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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_00/] [bench/] [verilog/] [system.v] - Blame information for rev 154

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 26 mihad
        # 1;
706 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
707 26 mihad
        # 1;
708 15 mihad
    end
709
    // fill WB slave behavioral MEMORY
710
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
711
    begin
712
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
713
        # 1;
714
    end
715
end
716
endtask // fill_memory
717
 
718
reg [2:0] tb_init_waits ;
719
reg [2:0] tb_subseq_waits ;
720
reg [2:0] tb_target_decode_speed ;
721
 
722
task run_tests ;
723
begin
724
    // first - reset logic
725
    do_reset ;
726
    next_test_name[79:0] <= "Initing...";
727
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
728
 
729
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
730
    begin
731
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
732
        begin
733
 
734
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
735
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
736
 
737
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
738
            begin
739
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
740
 
741
                `ifdef HOST
742
                    configure_bridge_target ;
743
                    find_pci_devices ;
744
                `endif
745
 
746
                @(posedge pci_clock) ;
747
                configure_target(1) ;
748
                @(posedge pci_clock) ;
749
                configure_target(2) ;
750
 
751
                `ifdef GUEST
752
                    configure_bridge_target ;
753
                `endif
754
 
755
               next_test_name[79:0] <= "WB_SLAVE..";
756
 
757
                $display("Testing WISHBONE slave images' features!") ;
758
                test_wb_image(1) ;
759
 
760
                `ifdef WB_IMAGE2
761
                    test_wb_image(2) ;
762
                `else
763
                    $display(" WB IMAGE 2 not implemented! ") ;
764
                `endif
765
 
766
                `ifdef WB_IMAGE3
767
                    test_wb_image(3) ;
768
                `else
769
                    $display(" WB IMAGE 3 not implemented! ") ;
770
                `endif
771
 
772
                `ifdef WB_IMAGE4
773
                    test_wb_image(4) ;
774
                `else
775
                    $display(" WB IMAGE 4 not implemented! ") ;
776
                `endif
777
 
778
                `ifdef WB_IMAGE5
779
                    test_wb_image(5) ;
780
                `else
781
                    $display(" WB IMAGE 5 not implemented! ") ;
782
                `endif
783
 
784
                wb_slave_errors ;
785
                wb_to_pci_error_handling ;
786
 
787
                parity_checking ;
788
 
789
                wb_to_pci_transactions ;
790
 
791
                `ifdef HOST
792
                iack_cycle ;
793
                `endif
794
 
795
            end
796
            $display(" ") ;
797
            $display("WB slave images' tests finished!") ;
798
 
799
            $display("########################################################################") ;
800
            $display("########################################################################") ;
801
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
802
            $display("########################################################################") ;
803
            $display("########################################################################") ;
804
 
805
            $display("Testing PCI target images' features!") ;
806
            configure_bridge_target_base_addresses ;
807
 
808
            `ifdef HOST
809
             `ifdef NO_CNF_IMAGE
810
              `ifdef PCI_IMAGE0
811
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
812
            test_pci_image(0) ;
813
              `else
814
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
815
              `endif
816
             `else
817
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
818
             `endif
819
            `endif
820
 
821
            $display("PCI image 1 is ALWAYS implemented!") ;
822
            test_pci_image(1) ;
823
 
824
            `ifdef PCI_IMAGE2
825
            $display("PCI image 2 is implemented!") ;
826
            test_pci_image(2) ;
827
            `else
828
            $display("PCI image 2 is NOT implemented!") ;
829
            `endif
830
 
831
            `ifdef PCI_IMAGE3
832
            $display("PCI image 3 is implemented!") ;
833
            test_pci_image(3) ;
834
            `else
835
            $display("PCI image 3 is NOT implemented!") ;
836
            `endif
837
 
838
            `ifdef PCI_IMAGE4
839
            $display("PCI image 4 is implemented!") ;
840
            test_pci_image(4) ;
841
            `else
842
            $display("PCI image 4 is NOT implemented!") ;
843
            `endif
844
 
845
            `ifdef PCI_IMAGE5
846
            $display("PCI image 5 is implemented!") ;
847
            test_pci_image(5) ;
848
            `else
849
            $display("PCI image 5 is NOT implemented!") ;
850
            `endif
851
 
852
            test_wb_error_rd ;
853
 
854
            target_fast_back_to_back ;
855
            target_disconnects ;
856
 
857
            if ( target_io_image !== -1 )
858
                test_target_abort( target_io_image ) ;
859
            $display(" ") ;
860
            $display("PCI target images' tests finished!") ;
861
 
862
            transaction_ordering ;
863 33 mihad
 
864
            target_completion_expiration ;
865 15 mihad
            $display(" ") ;
866
            $display("PCI transaction ordering tests finished!") ;
867
        end
868
    end
869
 
870
    test_summary ;
871
 
872
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
873
    $stop ;
874
end
875
endtask // run_tests
876
 
877
task do_reset;
878
begin
879
    next_test_name[79:0] <= "Reset.....";
880
 
881
    reset = 1'b1 ;
882
    #100 ;
883
    `ifdef HOST
884
        @(posedge wb_clock) ;
885
    `else
886
    `ifdef GUEST
887
        @(posedge pci_clock) ;
888
    `endif
889
    `endif
890
 
891
    reset <= 1'b0 ;
892
 
893
end
894
endtask
895
 
896
/*############################################################################
897
WB SLAVE UNIT tasks
898
===================
899
############################################################################*/
900
 
901
task configure_target ;
902
    input [1:0]  device_num ;
903
    reg   [31:0] base_address1 ;
904
    reg   [31:0] base_address2 ;
905
    reg   [2:0]  Master_ID;
906
    reg   [31:0] Target_Config_Addr;
907
begin
908
    if (device_num === 1)
909
    begin
910
        base_address1       = `BEH_TAR1_MEM_START ;
911
        base_address2       = `BEH_TAR1_IO_START  ;
912
        Master_ID           = `Test_Master_2 ;
913
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
914
    end
915
    else
916
    if (device_num === 2)
917
    begin
918
        base_address1       = `BEH_TAR2_MEM_START ;
919
        base_address2       = `BEH_TAR2_IO_START  ;
920
        Master_ID           = `Test_Master_1 ;
921
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
922
    end
923
 
924
    // write target's base addresses
925
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
926
    // type 0 cycle, byte enables, base address
927
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
928
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
929
 
930
    // enable target's response and master
931
    // enable parity errors, disable system error
932
 
933
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
934
 
935
end
936
endtask //configure_target
937
 
938
task test_wb_image ;
939
    input [2:0]  image_num ;
940
    reg   [11:0] ctrl_offset ;
941
    reg   [11:0] ba_offset ;
942
    reg   [11:0] am_offset ;
943
    reg   [11:0] ta_offset ;
944
    reg   [11:0] err_cs_offset ;
945
    reg `WRITE_STIM_TYPE write_data ;
946
    reg `READ_STIM_TYPE  read_data ;
947
    reg `READ_RETURN_TYPE read_status ;
948
 
949
    reg `WRITE_RETURN_TYPE write_status ;
950
    reg `WB_TRANSFER_FLAGS write_flags ;
951
    reg [31:0] temp_val ;
952
    reg        ok   ;
953
    reg [11:0] pci_ctrl_offset ;
954
    reg [31:0] image_base ;
955
    reg [31:0] target_address ;
956
    reg [31:0] translation_address ;
957
    integer    i ;
958
    integer    j ;
959
begin:main
960
    pci_ctrl_offset = 12'h4 ;
961
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
962
    // image 0 can only be configuration image - start with 1
963
    if (image_num === 1)
964
    begin
965
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
966
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
967
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
968
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
969
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
970
    end
971
    else if (image_num === 2)
972
    begin
973
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
974
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
975
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
976
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
977
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
978
    end
979
    else if (image_num === 3)
980
    begin
981
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
982
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
983
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
984
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
985
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
986
    end
987
    else if (image_num === 4)
988
    begin
989
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
990
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
991
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
992
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
993
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
994
    end
995
    else if (image_num === 5)
996
    begin
997
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
998
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
999
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1000
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1001
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1002
    end
1003
    else
1004
    begin
1005
        test_name   = "WB IMAGES' FEATURES TEST" ;
1006
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1007
        disable main ;
1008
    end
1009
 
1010
    target_address  = `BEH_TAR1_MEM_START ;
1011
    image_base      = 0 ;
1012
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1013
 
1014
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1015
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1016
    write_flags                      = 0 ;
1017
    write_flags`INIT_WAITS           = tb_init_waits ;
1018
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1019
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1020
 
1021
    test_name = "WB IMAGE CONFIGURATION" ;
1022
    // enable master & target operation
1023
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1024
    if ( ok !== 1 )
1025
    begin
1026
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1027
        test_fail("write to PCI Device Control register didn't succeede");
1028
        disable main ;
1029
    end
1030
 
1031
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1032
    if ( ok !== 1 )
1033
    begin
1034
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1035
        test_fail("write to WB Error Control and Status register didn't succeede");
1036
        disable main ;
1037
    end
1038
 
1039
    // prepare image control register
1040
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1041
    if ( ok !== 1 )
1042
    begin
1043
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1044
        test_fail("write to WB Image Control register didn't succeede");
1045
        disable main ;
1046
    end
1047
 
1048
    // prepare base address register
1049
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1050
    if ( ok !== 1 )
1051
    begin
1052
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1053
        test_fail("write to WB Base Address register didn't succeede");
1054
        disable main ;
1055
    end
1056
 
1057
    // write address mask register
1058
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1059
    if ( ok !== 1 )
1060
    begin
1061
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1062
        test_fail("write to WB Address Mask register didn't succeede");
1063
        disable main ;
1064
    end
1065
 
1066
    fork
1067
    begin
1068
        write_data`WRITE_ADDRESS = target_address ;
1069
        write_data`WRITE_DATA    = wmem_data[0] ;
1070
        write_data`WRITE_SEL     = 4'hF ;
1071
 
1072
        // handle retries from now on
1073
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1074
 
1075
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1076
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1077
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1078
        begin
1079
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1080
            test_fail("WB Slave state machine failed to post single memory write");
1081
            disable main ;
1082
        end
1083
 
1084
        // read written data back
1085
        read_data`READ_ADDRESS  = target_address ;
1086
        read_data`READ_SEL      = 4'hF ;
1087
        read_data`READ_TAG_STIM = 0 ;
1088
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1089
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1090
        begin
1091
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1092
            test_fail("PCI bridge didn't process the read as expected");
1093
            disable main ;
1094
        end
1095
 
1096
        if (read_status`READ_DATA !== wmem_data[0])
1097
        begin
1098
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1099
            test_fail("PCI bridge returned unexpected Read Data");
1100
        end
1101
        else
1102
            test_ok ;
1103
    end
1104
    begin
1105
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1106
        if ( ok !== 1 )
1107
        begin
1108
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1109
        end
1110
        else
1111
            test_ok ;
1112
 
1113
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1114
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1115
        if ( ok !== 1 )
1116
        begin
1117
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1118
        end
1119
    end
1120
    join
1121
 
1122
    // if address translation is implemented - try it out
1123
    translation_address = image_base ;
1124
    `ifdef ADDR_TRAN_IMPL
1125
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1126
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1127
    if ( ok !== 1 )
1128
    begin
1129
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1130
        test_fail("write to WB Image Translation Address Register failed") ;
1131
        disable main ;
1132
    end
1133
 
1134
    target_address  = `BEH_TAR2_MEM_START ;
1135
    image_base      = 0 ;
1136
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1137
 
1138
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1139
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1140
 
1141
    write_flags                      = 0 ;
1142
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1143
 
1144
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1145
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1146
    if ( ok !== 1 )
1147
    begin
1148
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1149
        test_fail("write to WB Image Base Address Register failed") ;
1150
        disable main ;
1151
    end
1152
 
1153
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1154
    // enable address translation
1155
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1156
    if ( ok !== 1 )
1157
    begin
1158
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1159
        test_fail("write to WB Image Control Register failed") ;
1160
        disable main ;
1161
    end
1162
 
1163
    `endif
1164
 
1165
    fork
1166
    begin
1167
        write_data`WRITE_ADDRESS = target_address + 4 ;
1168
        write_data`WRITE_DATA    = wmem_data[1] ;
1169
        write_data`WRITE_SEL     = 4'hF ;
1170
 
1171
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1172
 
1173
        `ifdef ADDR_TRAN_IMPL
1174
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1175
        `else
1176
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1177
        `endif
1178
 
1179
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1180
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1181
        begin
1182
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1183
            test_fail("WB Slave state machine failed to post single memory write") ;
1184
            disable main ;
1185
        end
1186
 
1187
        // read written data back
1188
        read_data`READ_ADDRESS  = target_address + 4 ;
1189
        read_data`READ_SEL      = 4'hF ;
1190
        read_data`READ_TAG_STIM = 0 ;
1191
 
1192
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1193
 
1194
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1195
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1196
        begin
1197
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1198
            test_fail("PCI bridge failed to process single delayed memory read") ;
1199
            disable main ;
1200
        end
1201
 
1202
        if (read_status`READ_DATA !== wmem_data[1])
1203
        begin
1204
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1205
            test_fail("PCI bridge returned unexpected Read Data");
1206
        end
1207
        else
1208
            test_ok ;
1209
    end
1210
    begin
1211
        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 ) ;
1212
        if ( ok !== 1 )
1213
        begin
1214
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1215
        end
1216
        else
1217
            test_ok ;
1218
 
1219
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1220
        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 ) ;
1221
        if ( ok !== 1 )
1222
        begin
1223
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1224
        end
1225
    end
1226
    join
1227
 
1228
    // 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
1229
    // prepare write data
1230
    for ( i = 0 ; i < 6 ; i = i + 1 )
1231
    begin
1232
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1233
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1234
        write_data`WRITE_SEL     = 4'hF ;
1235
        wishbone_master.blk_write_data[i] = write_data ;
1236
    end
1237
 
1238
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1239
    write_flags`WB_TRANSFER_CAB    = 1 ;
1240
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1241
 
1242
    fork
1243
    begin
1244
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1245
        wishbone_master.wb_block_write(write_flags, write_status) ;
1246
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1247
        begin
1248
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1249
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1250
            disable main ;
1251
        end
1252
    end
1253
    begin
1254
        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 ) ;
1255
        if ( ok !== 1 )
1256
        begin
1257
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1258
        end
1259
        else
1260
            test_ok ;
1261
    end
1262
    join
1263
 
1264
    // set burst size and latency timer
1265
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1266
 
1267
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1268
    write_flags`WB_TRANSFER_CAB    = 1 ;
1269
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1270
 
1271
    // prepare read data
1272
    for ( i = 0 ; i < 4 ; i = i + 1 )
1273
    begin
1274
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1275
        read_data`READ_SEL     = 4'hF ;
1276
        wishbone_master.blk_read_data_in[i] = read_data ;
1277
    end
1278
 
1279
    fork
1280
    begin
1281
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1282
        wishbone_master.wb_block_read(write_flags, read_status) ;
1283
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1284
        begin
1285
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1286
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1287
            disable main ;
1288
        end
1289
 
1290
        // check data read from target
1291
        for ( i = 0 ; i < 4 ; i = i + 1 )
1292
        begin
1293
            read_status = wishbone_master.blk_read_data_out[i] ;
1294
            if (read_status`READ_DATA !== wmem_data[2 + i])
1295
            begin
1296
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1297
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1298
            end
1299
        end
1300
    end
1301
    begin
1302
        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 ) ;
1303
        if ( ok !== 1 )
1304
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1305
        else
1306
            test_ok ;
1307
 
1308
        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 ) ;
1309
        if ( ok !== 1 )
1310
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1311
        else
1312
            test_ok ;
1313
 
1314
        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 ) ;
1315
        if ( ok !== 1 )
1316
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1317
        else
1318
            test_ok ;
1319
 
1320
        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 ) ;
1321
        if ( ok !== 1 )
1322
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1323
        else
1324
            test_ok ;
1325
 
1326
    end
1327
    join
1328
 
1329
    // now repeat this same burst read with various image features enabled or disabled
1330
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1331
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1332
    if (ok !== 1)
1333
    begin
1334
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1335
        test_fail("write to WB Image control register failed") ;
1336
        disable main ;
1337
    end
1338
 
1339
    fork
1340
    begin
1341
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1342
        wishbone_master.wb_block_read(write_flags, read_status) ;
1343
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1344
        begin
1345
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1346
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1347
            disable main ;
1348
        end
1349
 
1350
        // check data read from target
1351
        for ( i = 0 ; i < 4 ; i = i + 1 )
1352
        begin
1353
            read_status = wishbone_master.blk_read_data_out[i] ;
1354
            if (read_status`READ_DATA !== wmem_data[2 + i])
1355
            begin
1356
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1357
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1358
            end
1359
            else
1360
                test_ok ;
1361
        end
1362
    end
1363
    begin
1364
        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 ) ;
1365
        if ( ok !== 1 )
1366
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1367
    end
1368
    join
1369
 
1370
    read_data`READ_ADDRESS  = target_address ;
1371
    read_data`READ_SEL      = 4'hF ;
1372
    read_data`READ_TAG_STIM = 0 ;
1373
 
1374
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1375
    fork
1376
    begin
1377
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1378
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1379
        begin
1380
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1381
            test_fail("delayed single memory read wasn't processed as expected") ;
1382
            disable main ;
1383
        end
1384
 
1385
        if (read_status`READ_DATA !== wmem_data[0])
1386
        begin
1387
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1388
            test_fail("delayed single memory read data value returned was not as expected") ;
1389
        end
1390
        else
1391
            test_ok ;
1392
    end
1393
    begin
1394
        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 ) ;
1395
        if ( ok !== 1 )
1396
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1397
    end
1398
    join
1399
 
1400
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1401
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1402
    if (ok !== 1)
1403
    begin
1404
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1405
        test_fail("write to WB Image control register failed") ;
1406
        disable main ;
1407
    end
1408
 
1409
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1410
    fork
1411
    begin
1412
        wishbone_master.wb_block_read(write_flags, read_status) ;
1413
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1414
        begin
1415
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1416
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1417
            disable main ;
1418
        end
1419
 
1420
        // check data read from target
1421
        for ( i = 0 ; i < 4 ; i = i + 1 )
1422
        begin
1423
            read_status = wishbone_master.blk_read_data_out[i] ;
1424
            if (read_status`READ_DATA !== wmem_data[2 + i])
1425
            begin
1426
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1427
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1428
            end
1429
            else
1430
                test_ok ;
1431
        end
1432
    end
1433
    begin
1434
        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 ) ;
1435
        if ( ok !== 1 )
1436
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1437
    end
1438
    join
1439
 
1440
    read_data`READ_ADDRESS  = target_address + 4 ;
1441
    read_data`READ_SEL      = 4'hF ;
1442
    read_data`READ_TAG_STIM = 0 ;
1443
 
1444
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1445
    fork
1446
    begin
1447
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1448
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1449
        begin
1450
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1451
            test_fail("delayed single memory read wasn't processed as expected") ;
1452
            disable main ;
1453
        end
1454
 
1455
        if (read_status`READ_DATA !== wmem_data[1])
1456
        begin
1457
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1458
            test_fail("delayed single memory read data value returned was not as expected") ;
1459
        end
1460
        else
1461
            test_ok ;
1462
    end
1463
    begin
1464
        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 ) ;
1465
        if ( ok !== 1 )
1466
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1467
    end
1468
    join
1469
 
1470
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1471
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1472
    if (ok !== 1)
1473
    begin
1474
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1475
        test_fail("write to WB Image control register failed") ;
1476
        disable main ;
1477
    end
1478
 
1479
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1480
    fork
1481
    begin
1482
        wishbone_master.wb_block_read(write_flags, read_status) ;
1483
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1484
        begin
1485
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1486
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1487
            disable main ;
1488
        end
1489
 
1490
        // check data read from target
1491
        for ( i = 0 ; i < 4 ; i = i + 1 )
1492
        begin
1493
            read_status = wishbone_master.blk_read_data_out[i] ;
1494
            if (read_status`READ_DATA !== wmem_data[2 + i])
1495
            begin
1496
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1497
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1498
            end
1499
            else
1500
                test_ok ;
1501
        end
1502
    end
1503
    begin
1504
        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 ) ;
1505
        if ( ok !== 1 )
1506
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1507
    end
1508
    join
1509
 
1510
    read_data`READ_ADDRESS  = target_address + 8 ;
1511
    read_data`READ_SEL      = 4'hF ;
1512
    read_data`READ_TAG_STIM = 0 ;
1513
 
1514
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1515
    fork
1516
    begin
1517
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1518
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1519
        begin
1520
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1521
            test_fail("delayed single memory read wasn't processed as expected") ;
1522
            disable main ;
1523
        end
1524
 
1525
        if (read_status`READ_DATA !== wmem_data[2])
1526
        begin
1527
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1528
            test_fail("delayed single memory read data value returned was not as expected") ;
1529
        end
1530
        else
1531
            test_ok ;
1532
    end
1533
    begin
1534
        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 ) ;
1535
        if ( ok !== 1 )
1536
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1537
    end
1538
    join
1539
 
1540
    // map image to IO space
1541
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1542
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1543
    if ( ok !== 1 )
1544
    begin
1545
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1546
        test_fail("write to WB Image Base Address register failed") ;
1547
        disable main ;
1548
    end
1549
 
1550
    write_data`WRITE_ADDRESS = target_address ;
1551
    write_data`WRITE_DATA    = wmem_data[11] ;
1552
    write_data`WRITE_SEL     = 4'hF ;
1553
 
1554
    // handle retries from now on
1555
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1556
 
1557
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1558
    fork
1559
    begin
1560
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1561
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1562
        begin
1563
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1564
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1565
            disable main ;
1566
        end
1567
    end
1568
    begin
1569
        // currently IO commands not supported in behavioral models - master abort
1570
        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 ) ;
1571
        if ( ok !== 1 )
1572
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1573
        else
1574
            test_ok ;
1575
    end
1576
    join
1577
 
1578
    read_data`READ_ADDRESS  = target_address ;
1579
    read_data`READ_SEL      = 4'hF ;
1580
    read_data`READ_TAG_STIM = 0 ;
1581
 
1582
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1583
 
1584
    // currently io commands are not supported by behavioral target - transfer should not be completed
1585
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1586
    fork
1587
    begin
1588
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1589
        if (read_status`CYC_ERR !== 1)
1590
        begin
1591
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1592
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1593
            disable main ;
1594
        end
1595
        else
1596
            test_ok ;
1597
    end
1598
    begin
1599
        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 ) ;
1600
        if ( ok !== 1 )
1601
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1602
    end
1603
    join
1604
 
1605
    // test byte addressing
1606
    read_data`READ_ADDRESS = target_address + 2 ;
1607
    read_data`READ_SEL     = 4'b1100 ;
1608
 
1609
    fork
1610
    begin
1611
        // currently io commands are not supported by behavioral target - transfer should not be completed
1612
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1613
        if (read_status`CYC_ERR !== 1)
1614
        begin
1615
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1616
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1617
            disable main ;
1618
        end
1619
        else test_ok ;
1620
    end
1621
    begin
1622
        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 ) ;
1623
        if ( ok !== 1 )
1624
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1625
    end
1626
    join
1627
 
1628
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1629
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1630
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1631
    if ( ok !== 1 )
1632
    begin
1633
        test_fail("WB Base address register could not be written") ;
1634
        disable main ;
1635
    end
1636
 
1637
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1638
    if ( ok !== 1 )
1639
    begin
1640
        test_fail("WB Address Mask register could not be written") ;
1641
        disable main ;
1642
    end
1643
 
1644
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1645
    if ( ok !== 1 )
1646
    begin
1647
        test_fail("WB Image Control register could not be written") ;
1648
        disable main ;
1649
    end
1650
 
1651
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1652
    write_data`WRITE_DATA    = wmem_data[11] ;
1653
    write_data`WRITE_SEL     = 4'b1000 ;
1654
 
1655
    // handle retries from now on
1656
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1657
 
1658
    fork
1659
    begin
1660
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1661
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1662
        begin
1663
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1664
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1665
            disable main ;
1666
        end
1667
    end
1668
    begin
1669
        // currently IO commands not supported in behavioral models - master abort
1670
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1671
        if ( ok !== 1 )
1672
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1673
        else
1674
            test_ok ;
1675
    end
1676
    join
1677
 
1678
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1679
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1680
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1681
 
1682
    fork
1683
    begin
1684
        // currently io commands are not supported by behavioral target - transfer should not be completed
1685
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1686
        if (read_status`CYC_ERR !== 1)
1687
        begin
1688
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1689
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1690
            disable main ;
1691
        end
1692
        else test_ok ;
1693
    end
1694
    begin
1695
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1696
        if ( ok !== 1 )
1697
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1698
    end
1699
    join
1700
 
1701
    test_name = "DISABLING WB IMAGE" ;
1702
 
1703
    // disable current image
1704
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1705
    if ( ok !== 1 )
1706
    begin
1707
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1708
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1709
        disable main ;
1710
    end
1711
 
1712
    // clear master abort status bit
1713
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1714
    if ( ok !== 1 )
1715
    begin
1716
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1717
        test_fail("write to PCI Device Status register not accepted as expected") ;
1718
        disable main ;
1719
    end
1720
 
1721
end //main
1722
endtask //test_wb_image
1723
 
1724
task wb_slave_errors ;
1725
    reg   [11:0] ctrl_offset ;
1726
    reg   [11:0] ba_offset ;
1727
    reg   [11:0] am_offset ;
1728
    reg   [11:0] ta_offset ;
1729
    reg `WRITE_STIM_TYPE write_data ;
1730
    reg `READ_STIM_TYPE  read_data ;
1731
    reg `READ_RETURN_TYPE read_status ;
1732
 
1733
    reg `WRITE_RETURN_TYPE write_status ;
1734
    reg `WB_TRANSFER_FLAGS write_flags ;
1735
    reg [31:0] temp_val1 ;
1736
    reg [31:0] temp_val2 ;
1737
    reg        ok   ;
1738
    reg [11:0] pci_ctrl_offset ;
1739
    reg [31:0] image_base ;
1740
    reg [31:0] target_address ;
1741
    integer    i ;
1742
    reg skip ;
1743
fork
1744
begin:main
1745
 
1746
    `ifdef GUEST
1747
        skip = 1 ;
1748
    `else
1749
        skip = 0 ;
1750
    `endif
1751
 
1752
    pci_ctrl_offset = 12'h4 ;
1753
 
1754
    // image 1 is used for error testing, since it is always implemented
1755
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1756
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1757
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1758
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1759
 
1760
    target_address  = `BEH_TAR1_MEM_START ;
1761
    image_base      = 0 ;
1762
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1763
 
1764
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1765
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1766
    write_flags                    = 0 ;
1767
    write_flags`INIT_WAITS         = tb_init_waits ;
1768
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1769
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1770
 
1771
    // enable master & target operation
1772
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1773
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1774
    if ( ok !== 1 )
1775
    begin
1776
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1777
        test_fail("PCI Device Control register couldn't be written") ;
1778
        disable no_transaction ;
1779
        disable main ;
1780
    end
1781
 
1782
    // prepare image control register
1783
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1784
    if ( ok !== 1 )
1785
    begin
1786
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1787
        test_fail("WB Image Control register couldn't be written") ;
1788
        disable no_transaction ;
1789
        disable main ;
1790
    end
1791
 
1792
    // prepare base address register
1793
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1794
    if ( ok !== 1 )
1795
    begin
1796
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1797
        test_fail("WB Base Address register couldn't be written") ;
1798
        disable no_transaction ;
1799
        disable main ;
1800
    end
1801
 
1802
    // write address mask register
1803
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1804
    if ( ok !== 1 )
1805
    begin
1806
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1807
        test_fail("WB Address Mask register couldn't be written") ;
1808
        disable no_transaction ;
1809
        disable main ;
1810
    end
1811
 
1812
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1813
 
1814
    skip = 0 ;
1815
 
1816
    // memory mapped image - access is erroneous when address is not alligned
1817
    write_data`WRITE_ADDRESS = target_address + 1 ;
1818
    write_data`WRITE_DATA    = wmem_data[0] ;
1819
    write_data`WRITE_SEL     = 4'hF ;
1820
 
1821
    // handle retries from now on
1822
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1823
 
1824
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1825
 
1826
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1827
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1828
    begin
1829
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1830
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1831
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1832
        disable no_transaction ;
1833
        disable main ;
1834
    end
1835
 
1836
    write_data`WRITE_ADDRESS = target_address + 2 ;
1837
 
1838
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1839
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1840
    begin
1841
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1842
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1843
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1844
        disable no_transaction ;
1845
        disable main ;
1846
 
1847
    end
1848
 
1849
    write_data`WRITE_ADDRESS = target_address + 3 ;
1850
 
1851
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1852
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1853
    begin
1854
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1855
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1856
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1857
        disable no_transaction ;
1858
        disable main ;
1859
    end
1860
 
1861
    test_ok ;
1862
 
1863
    // perform same tests for read accesses
1864
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1865
 
1866
    read_data`READ_ADDRESS  = target_address + 2 ;
1867
    read_data`READ_SEL      = 4'hF ;
1868
    read_data`READ_TAG_STIM = 0 ;
1869
 
1870
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1871
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1872
    begin
1873
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1874
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1875
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1876
        disable no_transaction ;
1877
        disable main ;
1878
    end
1879
 
1880
    test_ok ;
1881
 
1882
    // prepare write data
1883
    for ( i = 0 ; i < 6 ; i = i + 1 )
1884
    begin
1885
        write_data`WRITE_DATA    = wmem_data[i] ;
1886
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1887
        write_data`WRITE_SEL     = 4'hF ;
1888
        wishbone_master.blk_write_data[i] = write_data ;
1889
    end
1890
 
1891
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1892
    write_flags`WB_TRANSFER_CAB    = 1 ;
1893
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1894
 
1895
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1896
    wishbone_master.wb_block_write(write_flags, write_status) ;
1897
 
1898
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1899
    begin
1900
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1901
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1902
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1903
        disable no_transaction ;
1904
        disable main ;
1905
    end
1906
 
1907
    // prepare read data
1908
    for ( i = 0 ; i < 6 ; i = i + 1 )
1909
    begin
1910
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1911
        read_data`READ_SEL     = 4'hF ;
1912
        wishbone_master.blk_read_data_in[i] = read_data ;
1913
    end
1914
 
1915
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1916
    wishbone_master.wb_block_read(write_flags, read_status) ;
1917
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1918
    begin
1919
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1920
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1921
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
1922
        disable no_transaction ;
1923
        disable main ;
1924
    end
1925
 
1926
    test_ok ;
1927
 
1928
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1929
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
1930
 
1931
    // map image to IO space
1932
    `ifdef GUEST
1933
        skip = 1 ;
1934
    `endif
1935
 
1936
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
1937
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1938
    if ( ok !== 1 )
1939
    begin
1940
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1941
        test_fail("WB Image Base Address register couldn't be written") ;
1942
        disable no_transaction ;
1943
        disable main ;
1944
    end
1945
 
1946
    skip = 0 ;
1947
 
1948
    write_data`WRITE_ADDRESS = target_address ;
1949
    write_data`WRITE_DATA    = wmem_data[0] ;
1950
    write_data`WRITE_SEL     = 4'b1010 ;
1951
 
1952
    // don't handle retries
1953
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1954
 
1955
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
1956
 
1957
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1958
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1959
    begin
1960
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1961
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1962
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1963
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1964
        disable no_transaction ;
1965
        disable main ;
1966
    end
1967
 
1968
    write_data`WRITE_ADDRESS = target_address + 1 ;
1969
    write_data`WRITE_SEL     = 4'b0011 ;
1970
 
1971
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1972
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1973
    begin
1974
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1975
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1976
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1977
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1978
        disable no_transaction ;
1979
        disable main ;
1980
    end
1981
 
1982
    write_data`WRITE_SEL     = 4'b1100 ;
1983
 
1984
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1985
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1986
    begin
1987
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1988
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1989
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1990
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1991
        disable no_transaction ;
1992
        disable main ;
1993
    end
1994
 
1995
    write_data`WRITE_ADDRESS = target_address + 2 ;
1996
    write_data`WRITE_SEL     = 4'b0101 ;
1997
 
1998
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1999
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2000
    begin
2001
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2002
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2003
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2004
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2005
        disable no_transaction ;
2006
        disable main ;
2007
    end
2008
 
2009
    write_data`WRITE_SEL     = 4'b1000 ;
2010
 
2011
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2012
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2013
    begin
2014
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2015
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2016
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2017
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2018
        disable no_transaction ;
2019
        disable main ;
2020
    end
2021
 
2022
    write_data`WRITE_ADDRESS = target_address + 3 ;
2023
    write_data`WRITE_SEL     = 4'b1010 ;
2024
 
2025
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2026
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2027
    begin
2028
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2029
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2030
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2031
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2032
        disable no_transaction ;
2033
        disable main ;
2034
    end
2035
 
2036
    write_data`WRITE_SEL     = 4'b0110 ;
2037
 
2038
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2039
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2040
    begin
2041
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2042
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2043
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2044
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2045
        disable no_transaction ;
2046
        disable main ;
2047
    end
2048
 
2049
    test_ok ;
2050
 
2051
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2052
 
2053
    read_data`READ_ADDRESS  = target_address + 3 ;
2054
    read_data`READ_SEL      = 4'hF ;
2055
    read_data`READ_TAG_STIM = 0 ;
2056
 
2057
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2058
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2059
    begin
2060
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2061
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2062
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2063
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2064
        disable no_transaction ;
2065
        disable main ;
2066
    end
2067
 
2068
    test_ok ;
2069
 
2070
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2071
    // prepare write data
2072
    for ( i = 0 ; i < 6 ; i = i + 1 )
2073
    begin
2074
        write_data`WRITE_DATA    = wmem_data[i] ;
2075
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2076
        write_data`WRITE_SEL     = 4'hF ;
2077
        wishbone_master.blk_write_data[i] = write_data ;
2078
    end
2079
 
2080
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2081
    write_flags`WB_TRANSFER_CAB    = 1 ;
2082
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2083
 
2084
    wishbone_master.wb_block_write(write_flags, write_status) ;
2085
 
2086
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2087
    begin
2088
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2089
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2090
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2091
        disable no_transaction ;
2092
        disable main ;
2093
    end
2094
 
2095
    test_ok ;
2096
 
2097
    test_name = "CAB I/O READ TO WB SLAVE" ;
2098
    // prepare read data
2099
    for ( i = 0 ; i < 6 ; i = i + 1 )
2100
    begin
2101
        read_data`READ_ADDRESS = target_address + 4*i ;
2102
        read_data`READ_SEL     = 4'hF ;
2103
        wishbone_master.blk_read_data_in[i] = read_data ;
2104
    end
2105
 
2106
    wishbone_master.wb_block_read(write_flags, read_status) ;
2107
 
2108
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2109
    begin
2110
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2111
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2112
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2113
        disable no_transaction ;
2114
        disable main ;
2115
    end
2116
 
2117
    test_ok ;
2118
 
2119
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2120
 
2121
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2122
 
2123
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2124
    write_data`WRITE_ADDRESS = target_address + 1 ;
2125
    write_data`WRITE_DATA    = wmem_data[0] ;
2126
    write_data`WRITE_SEL     = 4'hF ;
2127
 
2128
    // don't handle retries
2129
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2130
 
2131
    `ifdef HOST
2132
        `define DO_W_CONF_TEST
2133
        `define DO_R_CONF_TEST
2134
    `else
2135
        `ifdef WB_CNF_IMAGE
2136
             `define DO_R_CONF_TEST
2137
        `endif
2138
    `endif
2139
 
2140
    `ifdef DO_W_CONF_TEST
2141
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2142
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2143
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2144
    begin
2145
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2146
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2147
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2148
        disable no_transaction ;
2149
        disable main ;
2150
    end
2151
 
2152
    write_data`WRITE_ADDRESS = target_address + 2 ;
2153
 
2154
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2155
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2156
    begin
2157
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2158
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2159
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2160
        disable no_transaction ;
2161
        disable main ;
2162
    end
2163
 
2164
    write_data`WRITE_ADDRESS = target_address + 3 ;
2165
 
2166
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2167
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2168
    begin
2169
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2170
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2171
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2172
        disable no_transaction ;
2173
        disable main ;
2174
    end
2175
 
2176
    test_ok ;
2177
    `endif
2178
 
2179
    `ifdef DO_R_CONF_TEST
2180
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2181
    read_data`READ_ADDRESS  = target_address + 3 ;
2182
    read_data`READ_SEL      = 4'hF ;
2183
    read_data`READ_TAG_STIM = 0 ;
2184
 
2185
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2186
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2187
    begin
2188
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2189
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2190
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2191
        disable no_transaction ;
2192
        disable main ;
2193
    end
2194
 
2195
    test_ok ;
2196
    `endif
2197
 
2198
    `ifdef DO_W_CONF_TEST
2199
    // prepare write data
2200
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2201
    for ( i = 0 ; i < 6 ; i = i + 1 )
2202
    begin
2203
        write_data`WRITE_DATA    = wmem_data[i] ;
2204
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2205
        write_data`WRITE_SEL     = 4'hF ;
2206
        wishbone_master.blk_write_data[i] = write_data ;
2207
    end
2208
 
2209
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2210
    write_flags`WB_TRANSFER_CAB    = 1 ;
2211
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2212
 
2213
    wishbone_master.wb_block_write(write_flags, write_status) ;
2214
 
2215
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2216
    begin
2217
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2218
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2219
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2220
        disable no_transaction ;
2221
        disable main ;
2222
    end
2223
    test_ok ;
2224
    `endif
2225
 
2226
    `ifdef DO_R_CONF_TEST
2227
    // prepare read data
2228
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2229
    for ( i = 0 ; i < 6 ; i = i + 1 )
2230
    begin
2231
        read_data`READ_ADDRESS = target_address + 4*i ;
2232
        read_data`READ_SEL     = 4'hF ;
2233
        wishbone_master.blk_read_data_in[i] = read_data ;
2234
    end
2235
 
2236
    wishbone_master.wb_block_read(write_flags, read_status) ;
2237
 
2238
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2239
    begin
2240
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2241
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2242
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2243
        disable no_transaction ;
2244
        disable main ;
2245
    end
2246
    test_ok ;
2247
    `endif
2248
 
2249
    `ifdef GUEST
2250
        skip = 1 ;
2251
    `endif
2252
 
2253
    // disable image
2254
    test_name = "DISABLE IMAGE" ;
2255
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2256
    if ( ok !== 1 )
2257
    begin
2258
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2259
        test_fail("WB Address Mask register couldn't be written") ;
2260
        disable no_transaction ;
2261
        disable main ;
2262
    end
2263
 
2264
    skip = 0 ;
2265
 
2266
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2267
 
2268
    disable no_transaction ;
2269
end
2270
begin:no_transaction
2271
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2272
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2273
    forever
2274
    begin
2275
        @(posedge pci_clock) ;
2276
        if ( skip !== 1 )
2277
        begin
2278
            if ( FRAME !== 1 )
2279
            begin
2280
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2281
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2282
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2283
            end
2284
        end
2285
    end
2286
end
2287
join
2288
endtask //wb_slave_errors
2289
 
2290
task wb_to_pci_error_handling ;
2291
    reg   [11:0] ctrl_offset ;
2292
    reg   [11:0] ba_offset ;
2293
    reg   [11:0] am_offset ;
2294
    reg   [11:0] ta_offset ;
2295
    reg   [11:0] err_cs_offset ;
2296
    reg `WRITE_STIM_TYPE write_data ;
2297
    reg `READ_STIM_TYPE  read_data ;
2298
    reg `READ_RETURN_TYPE read_status ;
2299
 
2300
    reg `WRITE_RETURN_TYPE write_status ;
2301
    reg `WB_TRANSFER_FLAGS write_flags ;
2302
    reg [31:0] temp_val1 ;
2303
    reg [31:0] temp_val2 ;
2304
    reg        ok   ;
2305
    reg [11:0] pci_ctrl_offset ;
2306
    reg [31:0] image_base ;
2307
    reg [31:0] target_address ;
2308
    integer    num_of_trans ;
2309
    integer    current ;
2310
    integer    i ;
2311
begin:main
2312
 
2313
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2314
 
2315
    pci_ctrl_offset = 12'h4 ;
2316
 
2317
    // disable error interrupts and disable error reporting
2318
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2319
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2320
    if ( ok !== 1 )
2321
    begin
2322
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2323
        test_fail("PCI Device Control register couldn't be written") ;
2324
        disable main ;
2325
    end
2326
 
2327
    // image 1 is used for error testing, since it is always implemented
2328
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2329
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2330
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2331
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2332
 
2333
    // set master abort testing address to address that goes out of target's range
2334
    target_address  = `BEH_TAR1_MEM_START ;
2335
    image_base      = 0 ;
2336
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2337
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2338
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2339
 
2340
    write_flags                    = 0 ;
2341
    write_flags`INIT_WAITS         = tb_init_waits ;
2342
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2343
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2344
 
2345
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2346
 
2347
    // enable master & target operation
2348
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2349
    if ( ok !== 1 )
2350
    begin
2351
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2352
        test_fail("PCI Device Control register couldn't be written") ;
2353
        disable main ;
2354
    end
2355
 
2356
    // prepare image control register
2357
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2358
    if ( ok !== 1 )
2359
    begin
2360
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2361
        test_fail("WB Image Control register couldn't be written") ;
2362
        disable main ;
2363
    end
2364
 
2365
    // prepare base address register
2366
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2367
    if ( ok !== 1 )
2368
    begin
2369
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2370
        test_fail("WB Image Base Address register couldn't be written") ;
2371
        disable main ;
2372
    end
2373
 
2374
    // write address mask register
2375
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2376
    if ( ok !== 1 )
2377
    begin
2378
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2379
        test_fail("WB Image Address Mask register couldn't be written") ;
2380
        disable main ;
2381
    end
2382
 
2383
    // disable error reporting
2384
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2385
    if ( ~ok )
2386
    begin
2387
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2388
        test_fail("WB Error Control and Status register couldn't be written") ;
2389
        disable main ;
2390
    end
2391
 
2392
    // perform two writes - one to error address and one to OK address
2393
    // prepare write buffer
2394
 
2395
    write_data`WRITE_ADDRESS = target_address ;
2396
    write_data`WRITE_DATA    = wmem_data[100] ;
2397
    write_data`WRITE_SEL     = 4'hF ;
2398
 
2399
    wishbone_master.blk_write_data[0] = write_data ;
2400
 
2401
    write_flags`WB_TRANSFER_SIZE = 2 ;
2402
 
2403
    // don't handle retries
2404
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2405
    write_flags`WB_TRANSFER_CAB    = 0 ;
2406
 
2407
    $display("Introducing master abort error on single WB to PCI write!") ;
2408
 
2409
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2410
    // first disable target 1
2411
 
2412
    configuration_cycle_write(0,             // bus number
2413
                              1,             // device number
2414
                              0,             // function number
2415
                              1,             // register number
2416
                              0,             // type of configuration cycle
2417
                              4'b0001,       // byte enables
2418
                              32'h0000_0000  // data
2419
                             ) ;
2420
 
2421
    fork
2422
    begin
2423
        // start no response monitor in parallel with writes
2424
        musnt_respond(ok) ;
2425
        if ( ok !== 1 )
2426
        begin
2427
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2428
            $display("Testbench is configured wrong!") ;
2429
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2430
        end
2431
        else
2432
            test_ok ;
2433
    end
2434
    begin
2435
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2436
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2437
       begin
2438
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2439
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2440
           test_fail("WB Slave state machine failed to post single memory write");
2441
           disable main ;
2442
       end
2443
    end
2444
    join
2445
 
2446
    /*// read data from second write
2447
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2448
    read_data`READ_ADDRESS = target_address ;
2449
    read_data`READ_SEL     = 4'hF ;
2450
    read_data`READ_TAG_STIM = 0 ;
2451
 
2452
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2453
 
2454
    if ( read_status`READ_DATA !== wmem_data[101] )
2455
    begin
2456
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2457
    end
2458
    */
2459
 
2460
    // read error status register - no errors should be reported since reporting was disabled
2461
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2462
 
2463
    @(posedge pci_clock) ;
2464
    // wait for two WB clocks for synchronization to be finished
2465
    repeat (2)
2466
        @(posedge wb_clock) ;
2467
 
2468
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2469
    if ( temp_val1[8] !== 0 )
2470
    begin
2471
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2472
        $display("Error reporting was disabled, but error was reported anyway!") ;
2473
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2474
        disable main ;
2475
    end
2476
    test_ok ;
2477
 
2478
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2479
    // check for interrupts - there should be no interrupt requests active
2480
    `ifdef HOST
2481
        repeat(4)
2482
            @(posedge wb_clock) ;
2483
 
2484
        if ( INT_O !== 0 )
2485
        begin
2486
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2487
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2488
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2489
        end
2490
        else
2491
            test_ok ;
2492
    `else
2493
    `ifdef GUEST
2494
        repeat( 4 )
2495
            @(posedge pci_clock) ;
2496
 
2497
        if ( INTA !== 1 )
2498
        begin
2499
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2500
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2501
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2502
        end
2503
        else
2504
            test_ok ;
2505
    `endif
2506
    `endif
2507
 
2508
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2509
    // check PCI status register
2510
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2511
    if ( temp_val1[29] !== 1 )
2512
    begin
2513
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2514
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2515
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2516
    end
2517
    else
2518
        test_ok ;
2519
 
2520
    // clear
2521
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2522
 
2523
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2524
 
2525
    $display("Introducing master abort error to CAB write!") ;
2526
    // now enable error reporting mechanism
2527
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2528
    // enable error interrupts
2529
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2530
 
2531
    // configure flags for CAB transfer
2532
    write_flags`WB_TRANSFER_CAB = 1 ;
2533
    write_flags`WB_TRANSFER_SIZE = 3 ;
2534
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2535
 
2536
    // prepare data for erroneous write
2537
    for ( i = 0 ; i < 3 ; i = i + 1 )
2538
    begin
2539
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2540
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2541
        write_data`WRITE_SEL     = 4'hF ;
2542
        wishbone_master.blk_write_data[i] = write_data ;
2543
    end
2544
 
2545
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2546
    fork
2547
    begin
2548
        wishbone_master.wb_block_write(write_flags, write_status) ;
2549
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2550
        begin
2551
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2552
            $display("Complete burst write through WB slave didn't succeed!") ;
2553
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2554
            disable main ;
2555
        end
2556
    end
2557
    begin
2558
        musnt_respond(ok) ;
2559
        if ( ok !== 1 )
2560
        begin
2561
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2562
            $display("Testbench is configured wrong!") ;
2563
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2564
        end
2565
        else
2566
            test_ok ;
2567
    end
2568
    join
2569
 
2570
    // check error status address, data, byte enables and bus command
2571
    // error status bit is signalled on PCI clock and synchronized to WB clock
2572
    // wait one PCI clock cycle
2573
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2574
    ok = 1 ;
2575
    @(posedge pci_clock) ;
2576
 
2577
    // wait for two WB clocks for synchronization to be finished
2578
    repeat (2)
2579
        @(posedge wb_clock) ;
2580
 
2581
    // read registers
2582
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2583
    if ( temp_val1[8] !== 1 )
2584
    begin
2585
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2586
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2587
        ok = 0 ;
2588
    end
2589
 
2590
    if ( temp_val1[9] !== 1 )
2591
    begin
2592
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2593
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2594
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2595
        ok = 0 ;
2596
    end
2597
 
2598
    if ( temp_val1[31:28] !== 0 )
2599
    begin
2600
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2601
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2602
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2603
        ok = 0 ;
2604
    end
2605
 
2606
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2607
    begin
2608
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2609
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2610
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2611
        ok = 0 ;
2612
    end
2613
 
2614
    // read error address register
2615
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2616
    if ( temp_val1 !== target_address )
2617
    begin
2618
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2619
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2620
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2621
        ok = 0 ;
2622
    end
2623
 
2624
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2625
    if ( temp_val1 !== wmem_data[110] )
2626
    begin
2627
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2628
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2629
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2630
        ok = 0 ;
2631
    end
2632
 
2633
    // check PCI status register
2634
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2635
    if ( temp_val1[29] !== 1 )
2636
    begin
2637
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2638
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2639
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2640
        ok = 0 ;
2641
    end
2642
 
2643
    if ( temp_val1[28] !== 0 )
2644
    begin
2645
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2646
        $display("Received Target Abort bit was set for no reason!") ;
2647
        test_fail("Received Target Abort bit was set for no reason") ;
2648
        ok = 0 ;
2649
    end
2650
 
2651
    if ( ok )
2652
        test_ok ;
2653
 
2654
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2655
 
2656
    // clear error status bit
2657
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2658
 
2659
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2660
 
2661
    ok = 1 ;
2662
 
2663
    `ifdef HOST
2664
        repeat(4)
2665
        @(posedge wb_clock) ;
2666
        if ( INT_O !== 1 )
2667
        begin
2668
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2669
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2670
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2671
            ok = 0 ;
2672
        end
2673
    `else
2674
    `ifdef GUEST
2675
        repeat(4)
2676
        @(posedge pci_clock) ;
2677
        if ( INTA !== 0 )
2678
        begin
2679
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2680
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2681
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2682
            ok = 0 ;
2683
        end
2684
    `endif
2685
    `endif
2686
 
2687
    // read interrupt status register
2688
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2689
    if ( temp_val1 !== 32'h0000_0002 )
2690
    begin
2691
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2692
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2693
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2694
        test_fail("Interrupt Status register returned wrong value") ;
2695
        ok = 0 ;
2696
    end
2697
 
2698
    if ( ok )
2699
        test_ok ;
2700
    // clear interrupt status bits
2701
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2702
 
2703
    ok = 1 ;
2704
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2705
    // wait for two clock cycles before checking interrupt request deassertion
2706
    `ifdef HOST
2707
        repeat (4)
2708
            @(posedge wb_clock) ;
2709
 
2710
        if ( INT_O !== 0 )
2711
        begin
2712
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2713
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2714
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2715
            ok = 0 ;
2716
        end
2717
    `else
2718
    `ifdef GUEST
2719
        repeat (4)
2720
            @(posedge pci_clock) ;
2721
 
2722
        if ( INTA !== 1 )
2723
        begin
2724
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2725
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2726
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2727
            ok = 0 ;
2728
        end
2729
    `endif
2730
    `endif
2731
 
2732
    if ( ok )
2733
        test_ok ;
2734
 
2735
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2736
    ok = 1 ;
2737
    // enable target
2738
    configuration_cycle_write(0,             // bus number
2739
                              1,             // device number
2740
                              0,             // function number
2741
                              1,             // register number
2742
                              0,             // type of configuration cycle
2743
                              4'b0001,       // byte enables
2744
                              32'h0000_0007  // data
2745
                             ) ;
2746
    // prepare data for ok write
2747
    for ( i = 0 ; i < 3 ; i = i + 1 )
2748
    begin
2749
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2750
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2751
        write_data`WRITE_SEL     = 4'hF ;
2752
        wishbone_master.blk_write_data[i] = write_data ;
2753
    end
2754
 
2755
    wishbone_master.wb_block_write(write_flags, write_status) ;
2756
 
2757
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2758
    begin
2759
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2760
        $display("Complete burst write through WB slave didn't succeed!") ;
2761
        test_fail("WB Slave state machine failed to post CAB write") ;
2762
        disable main ;
2763
    end
2764
 
2765
    // do a read
2766
    for ( i = 0 ; i < 3 ; i = i + 1 )
2767
    begin
2768
        read_data`READ_ADDRESS = target_address + 4*i ;
2769
        read_data`READ_SEL     = 4'hF ;
2770
        wishbone_master.blk_read_data_in[i] = read_data ;
2771
    end
2772
 
2773
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2774
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2775
    write_flags`WB_TRANSFER_CAB    = 1 ;
2776
 
2777
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2778
 
2779
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2780
    begin
2781
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2782
        $display("Complete burst read through WB slave didn't succeed!") ;
2783
        test_fail("Delayed CAB write was not processed as expected") ;
2784
        disable main ;
2785
    end
2786
 
2787
    for ( i = 0 ; i < 3 ; i = i + 1 )
2788
    begin
2789
        read_status = wishbone_master.blk_read_data_out[i] ;
2790
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2791
        begin
2792
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2793
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2794
        end
2795
    end
2796
 
2797
    $display("Introducing master abort error to single read!") ;
2798
    // disable target
2799
    configuration_cycle_write(0,             // bus number
2800
                              1,             // device number
2801
                              0,             // function number
2802
                              1,             // register number
2803
                              0,             // type of configuration cycle
2804
                              4'b0001,       // byte enables
2805
                              32'h0000_0000  // data
2806
                             ) ;
2807
    // set read data
2808
    read_data`READ_ADDRESS = target_address ;
2809
    read_data`READ_SEL     = 4'hF ;
2810
 
2811
    // enable automatic retry handling
2812
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2813
    write_flags`WB_TRANSFER_CAB    = 0 ;
2814
 
2815
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2816
    fork
2817
    begin
2818
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2819
    end
2820
    begin
2821
        musnt_respond(ok) ;
2822
        if ( ok !== 1 )
2823
        begin
2824
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2825
            $display("Testbench is configured wrong!") ;
2826
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2827
        end
2828
    end
2829
    join
2830
 
2831
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2832
    begin
2833
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2834
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2835
        $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) ;
2836
        test_fail("read didn't finish on WB bus as expected") ;
2837
        disable main ;
2838
    end
2839
 
2840
    test_ok ;
2841
 
2842
 
2843
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2844
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2845
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2846
    if ( temp_val1[8] !== 0 )
2847
    begin
2848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2849
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2850
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2851
    end
2852
    else
2853
        test_ok ;
2854
 
2855
    // now check normal read operation
2856
    configuration_cycle_write(0,             // bus number
2857
                              1,             // device number
2858
                              0,             // function number
2859
                              1,             // register number
2860
                              0,             // type of configuration cycle
2861
                              4'b0001,       // byte enables
2862
                              32'h0000_0007  // data
2863
                             ) ;
2864
 
2865
    test_name = "CHECK NORMAL READ AFTER ERROR TERMINATED READ" ;
2866
    read_data`READ_ADDRESS = target_address ;
2867
    read_data`READ_SEL     = 4'hF ;
2868
 
2869
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2870
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2871
    begin
2872
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2873
        $display("WB slave failed to process single read!") ;
2874
        $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) ;
2875
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2876
        disable main ;
2877
    end
2878
 
2879
    if ( read_status`READ_DATA !== wmem_data[113] )
2880
    begin
2881
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2882
        test_fail("when read finished on WB bus, wrong data was provided") ;
2883
    end
2884
    else
2885
        test_ok ;
2886
 
2887
    // check PCI status register
2888
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT ON DELAYED READ" ;
2889
    ok = 1 ;
2890
 
2891
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2892
    if ( temp_val1[29] !== 1 )
2893
    begin
2894
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2895
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2896
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2897
        ok = 0 ;
2898
    end
2899
 
2900
    if ( temp_val1[28] !== 0 )
2901
    begin
2902
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2903
        $display("Received Target Abort bit was set for no reason!") ;
2904
        test_fail("Received Target Abort bit was set for no reason") ;
2905
        ok = 0 ;
2906
    end
2907
    if ( ok )
2908
        test_ok ;
2909
 
2910
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2911
 
2912
    $display("Introducing master abort error to CAB read!") ;
2913
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2914
 
2915
    configuration_cycle_write(0,             // bus number
2916
                              1,             // device number
2917
                              0,             // function number
2918
                              1,             // register number
2919
                              0,             // type of configuration cycle
2920
                              4'b0001,       // byte enables
2921
                              32'h0000_0000  // data
2922
                             ) ;
2923
 
2924
    for ( i = 0 ; i < 3 ; i = i + 1 )
2925
    begin
2926
        read_data`READ_ADDRESS = target_address + 4*i ;
2927
        read_data`READ_SEL     = 4'hF ;
2928
        wishbone_master.blk_read_data_in[i] = read_data ;
2929
    end
2930
 
2931
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2932
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2933
    write_flags`WB_TRANSFER_CAB    = 1 ;
2934
 
2935
    fork
2936
    begin
2937
        wishbone_master.wb_block_read( write_flags, read_status ) ;
2938
    end
2939
    begin
2940
        musnt_respond(ok) ;
2941
        if ( ok !== 1 )
2942
        begin
2943
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2944
            $display("Testbench is configured wrong!") ;
2945
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2946
        end
2947
    end
2948
    join
2949
 
2950
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2951
    begin
2952
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2953
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2954
        $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) ;
2955
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
2956
        disable main ;
2957
    end
2958
    else
2959
        test_ok ;
2960
 
2961
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
2962
    ok = 1 ;
2963
    // check PCI status register
2964
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2965
    if ( temp_val1[29] !== 1 )
2966
    begin
2967
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2968
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2969
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2970
        ok = 0 ;
2971
    end
2972
 
2973
    if ( temp_val1[28] !== 0 )
2974
    begin
2975
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2976
        $display("Received Target Abort bit was set for no reason!") ;
2977
        test_fail("Received Target Abort bit was set for no reason") ;
2978
        ok = 0 ;
2979
    end
2980
 
2981
    if ( ok )
2982
        test_ok ;
2983
 
2984
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2985
 
2986
    $display("Introducing target abort termination to single write!") ;
2987
 
2988
    // disable error reporting and interrupts
2989
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
2990
 
2991
    configuration_cycle_write(0,             // bus number
2992
                              1,             // device number
2993
                              0,             // function number
2994
                              1,             // register number
2995
                              0,             // type of configuration cycle
2996
                              4'b0001,       // byte enables
2997
                              32'h0000_0007  // data
2998
                             ) ;
2999
 
3000
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3001
    if ( ok !== 1 )
3002
    begin
3003
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3004
        test_fail("WB Error Control and Status register couldn't be written to") ;
3005
        disable main ;
3006
    end
3007
 
3008
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3009
    if ( ok !== 1 )
3010
    begin
3011
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3012
        test_fail("Interrupt Control register couldn't be written to") ;
3013
        disable main ;
3014
    end
3015
 
3016
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3017
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3018
 
3019
    write_data`WRITE_ADDRESS = target_address ;
3020
    write_data`WRITE_DATA    = wmem_data[0] ;
3021
    write_data`WRITE_SEL     = 4'hF ;
3022
 
3023
    wishbone_master.blk_write_data[0] = write_data ;
3024
 
3025
    write_data`WRITE_ADDRESS = target_address + 4;
3026
    write_data`WRITE_DATA    = wmem_data[1] ;
3027
    write_data`WRITE_SEL     = 4'hF ;
3028
 
3029
    wishbone_master.blk_write_data[1] = write_data ;
3030
 
3031
    write_flags`WB_TRANSFER_SIZE = 2 ;
3032
 
3033
    // don't handle retries
3034
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3035
    write_flags`WB_TRANSFER_CAB    = 0 ;
3036
 
3037
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3038
    fork
3039
    begin
3040
        wishbone_master.wb_block_write(write_flags, write_status) ;
3041
 
3042
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3043
        begin
3044
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3045
            $display("Image writes were not accepted as expected!") ;
3046
            $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) ;
3047
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3048
            disable main ;
3049
        end
3050
 
3051
        // read data back to see, if it was written OK
3052
        read_data`READ_ADDRESS         = target_address + 4;
3053
        read_data`READ_SEL             = 4'hF ;
3054
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3055
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3056
    end
3057
    begin
3058
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3059
        if ( ok !== 1 )
3060
        begin
3061
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3062
        end
3063
        else
3064
            test_ok ;
3065
 
3066
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3067
 
3068
        // when first transaction finishes - enable normal target response!
3069
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3070
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3071
 
3072
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3073
        if ( ok !== 1 )
3074
        begin
3075
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3076
        end
3077
        else
3078
            test_ok ;
3079
 
3080
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3081
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3082
        if ( ok !== 1 )
3083
        begin
3084
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3085
        end
3086
    end
3087
    join
3088
 
3089
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3090
    begin
3091
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3092
        $display("Bridge failed to process single read after target abort terminated write!") ;
3093
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3094
        disable main ;
3095
    end
3096
 
3097
    if ( read_status`READ_DATA !== wmem_data[1] )
3098
    begin
3099
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3100
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3101
    end
3102
    else
3103
        test_ok ;
3104
 
3105
    // check interrupt and error statuses!
3106
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3107
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3108
    if ( temp_val1[8] !== 0 )
3109
    begin
3110
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3111
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3112
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3113
    end
3114
    else
3115
        test_ok ;
3116
 
3117
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3118
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3119
    if ( temp_val1[1] !== 0 )
3120
    begin
3121
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3122
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3123
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3124
    end
3125
    else
3126
        test_ok ;
3127
 
3128
    // check PCI status register
3129
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3130
    ok = 1 ;
3131
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3132
    if ( temp_val1[29] !== 0 )
3133
    begin
3134
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3135
        $display("Received Master Abort bit was set with no reason!") ;
3136
        test_fail("Received Master Abort bit was set with no reason") ;
3137
        ok = 0 ;
3138
    end
3139
 
3140
    if ( temp_val1[28] !== 1 )
3141
    begin
3142
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3143
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3144
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3145
        ok = 0 ;
3146
    end
3147
 
3148
    if ( ok )
3149
        test_ok ;
3150
 
3151
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3152
 
3153
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3154
 
3155
    $display("Introducing target abort termination to CAB write!") ;
3156
    // enable error reporting mechanism
3157
 
3158
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3159
    if ( ok !== 1 )
3160
    begin
3161
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3162
        test_fail("WB Error Control and Status register could not be written to") ;
3163
        disable main ;
3164
    end
3165
 
3166
    for ( i = 0 ; i < 3 ; i = i + 1 )
3167
    begin
3168
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3169
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3170
        write_data`WRITE_SEL     = 4'b1010 ;
3171
        wishbone_master.blk_write_data[i] = write_data ;
3172
    end
3173
 
3174
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3175
    write_flags`WB_TRANSFER_CAB    = 1 ;
3176
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3177
 
3178
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3179
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3180
 
3181
    fork
3182
    begin
3183
        wishbone_master.wb_block_write(write_flags, write_status) ;
3184
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3185
        begin
3186
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3187
            $display("Bridge failed to process complete CAB write!") ;
3188
            test_fail("bridge failed to post CAB Memory Write") ;
3189
            disable main ;
3190
        end
3191
    end
3192
    begin
3193
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3194
        if ( ok !== 1 )
3195
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3196
        else
3197
            test_ok ;
3198
    end
3199
    join
3200
 
3201
    // check statuses and data from error
3202
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3203
    ok = 1 ;
3204
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3205
    if ( temp_val1[8] !== 1 )
3206
    begin
3207
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3208
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3209
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3210
        ok = 0 ;
3211
    end
3212
 
3213
    if ( temp_val1[9] !== 0 )
3214
    begin
3215
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3216
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3217
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3218
        ok = 0 ;
3219
    end
3220
 
3221
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3222
    begin
3223
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3224
        $display("Value in W_ERR_CS register was wrong!") ;
3225
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3226
        test_fail("BE Field didn't provided expected value") ;
3227
        ok = 0 ;
3228
    end
3229
 
3230
    if ( ok )
3231
        test_ok ;
3232
 
3233
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3234
    ok = 1 ;
3235
    // check erroneous address and data
3236
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3237
    if ( temp_val1 !== (target_address + 8) )
3238
    begin
3239
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3240
        $display("Value in W_ERR_ADDR register was wrong!") ;
3241
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3242
        test_fail("Value in WB Erroneous Address register was wrong") ;
3243
        ok = 0 ;
3244
    end
3245
 
3246
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3247
    if ( temp_val1 !== wmem_data[120] )
3248
    begin
3249
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3250
        $display("Value in W_ERR_DATA register was wrong!") ;
3251
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3252
        test_fail("Value in WB Erroneous Data register was wrong") ;
3253
        ok = 0 ;
3254
    end
3255
 
3256
    if ( ok )
3257
        test_ok ;
3258
 
3259
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3260
    ok = 1 ;
3261
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3262
    if ( temp_val1[29] !== 0 )
3263
    begin
3264
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3265
        $display("Received Master Abort bit was set with no reason!") ;
3266
        test_fail("Received Master Abort bit was set for no reason") ;
3267
        ok = 0 ;
3268
    end
3269
 
3270
    if ( temp_val1[28] !== 1 )
3271
    begin
3272
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3273
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3274
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3275
        ok = 0 ;
3276
    end
3277
 
3278
    if ( ok )
3279
        test_ok ;
3280
 
3281
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3282
 
3283
    // clear error status bit and enable error interrupts
3284
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3285
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3286
 
3287
    // check if error bit was cleared
3288
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3289
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3290
    if ( temp_val1[8] !== 0 )
3291
    begin
3292
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3293
        $display("Error bit was not cleared even though one was written to its location!") ;
3294
        test_fail("Error bit was not cleared even though one was written to its location") ;
3295
    end
3296
 
3297
    // repeat same write with different target configuration
3298
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3299
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3300
 
3301
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3302
    fork
3303
    begin
3304
        write_flags`WB_TRANSFER_SIZE = 2 ;
3305
        wishbone_master.wb_block_write(write_flags, write_status) ;
3306
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3307
        begin
3308
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3309
            $display("Bridge failed to process complete CAB write!") ;
3310
            test_fail("bridge failed to post CAB Memory Write") ;
3311
            disable main ;
3312
        end
3313
 
3314
        write_flags`WB_TRANSFER_SIZE = 3 ;
3315
        wishbone_master.wb_block_write(write_flags, write_status) ;
3316
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3317
        begin
3318
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3319
            $display("Bridge failed to process complete CAB write!") ;
3320
            test_fail("bridge failed to post CAB Memory Write") ;
3321
            disable main ;
3322
        end
3323
    end
3324
    begin
3325
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3326
        if ( ok !== 1 )
3327
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3328
        else
3329
        begin
3330
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3331
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3332
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3333
            if ( ok !== 1 )
3334
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3335
            else
3336
                test_ok ;
3337
        end
3338
    end
3339
    join
3340
 
3341
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3342
    ok = 1 ;
3343
    // check statuses and data from error
3344
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3345
    if ( temp_val1[8] !== 1 )
3346
    begin
3347
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3348
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3349
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3350
        ok = 0 ;
3351
    end
3352
 
3353
    if ( temp_val1[9] !== 0 )
3354
    begin
3355
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3356
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3357
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3358
        ok = 0 ;
3359
    end
3360
 
3361
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3362
    begin
3363
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3364
        $display("Value in W_ERR_CS register was wrong!") ;
3365
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3366
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3367
        ok = 0 ;
3368
    end
3369
 
3370
    if ( ok )
3371
        test_ok ;
3372
 
3373
    // check erroneous address and data
3374
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3375
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3376
    ok = 1 ;
3377
    if ( temp_val1 !== (target_address + 8 + 4) )
3378
    begin
3379
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3380
        $display("Value in W_ERR_ADDR register was wrong!") ;
3381
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3382
        test_fail("Value in WB Erroneous Address register was wrong") ;
3383
        ok = 0 ;
3384
 
3385
    end
3386
 
3387
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3388
    if ( temp_val1 !== wmem_data[121] )
3389
    begin
3390
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3391
        $display("Value in W_ERR_DATA register was wrong!") ;
3392
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3393
        test_fail("Value in WB Erroneous Data register was wrong") ;
3394
        ok = 0 ;
3395
    end
3396
 
3397
    if ( ok )
3398
        test_ok ;
3399
 
3400
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3401
    `ifdef HOST
3402
        repeat(4)
3403
            @(posedge wb_clock) ;
3404
        if ( INT_O !== 1 )
3405
        begin
3406
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3407
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3408
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3409
        end
3410
        else
3411
            test_ok ;
3412
    `else
3413
    `ifdef GUEST
3414
        repeat(4)
3415
            @(posedge pci_clock) ;
3416
        if ( INTA !== 0 )
3417
        begin
3418
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3419
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3420
            test_fail("interrupt request was not presented on PCI bus") ;
3421
        end
3422
        else
3423
            test_ok ;
3424
    `endif
3425
    `endif
3426
 
3427
    // read interrupt status register
3428
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3429
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3430
    if ( temp_val1[1] !== 1 )
3431
    begin
3432
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3433
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3434
        test_fail("Expected Interrupt status bit wasn't set") ;
3435
    end
3436
 
3437
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3438
 
3439
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3440
    ok = 1 ;
3441
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3442
    if ( temp_val1[29] !== 0 )
3443
    begin
3444
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3445
        $display("Received Master Abort bit was set with no reason!") ;
3446
        test_fail("Received Master Abort bit was set with no reason") ;
3447
        ok = 0 ;
3448
    end
3449
 
3450
    if ( temp_val1[28] !== 1 )
3451
    begin
3452
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3453
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3454
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3455
        ok = 0 ;
3456
    end
3457
 
3458
    if ( ok )
3459
        test_ok ;
3460
 
3461
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3462
 
3463
    // clear interrupts and errors
3464
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3465
    repeat( 3 )
3466
        @(posedge pci_clock) ;
3467
 
3468
    repeat( 2 )
3469
        @(posedge wb_clock) ;
3470
 
3471
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3472
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3473
    if ( temp_val1[1] !== 0 )
3474
    begin
3475
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3476
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3477
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3478
    end
3479
    else
3480
        test_ok ;
3481
 
3482
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3483
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3484
    if ( temp_val1[8] !== 0 )
3485
    begin
3486
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3487
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3488
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3489
    end
3490
 
3491
 
3492
    $display("Introducing Target Abort error to single read!") ;
3493
    // set read data
3494
    read_data`READ_ADDRESS = target_address + 8 ;
3495
    read_data`READ_SEL     = 4'hF ;
3496
 
3497
    // enable automatic retry handling
3498
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3499
    write_flags`WB_TRANSFER_CAB    = 0 ;
3500
 
3501
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3502
 
3503
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3504
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3505
 
3506
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3507
 
3508
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3509
    begin
3510
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3511
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3512
        $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) ;
3513
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3514
        disable main ;
3515
    end
3516
    else
3517
        test_ok ;
3518
 
3519
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3520
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3521
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3522
    if ( temp_val1[8] !== 0 )
3523
    begin
3524
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3525
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3526
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3527
    end
3528
    else
3529
        test_ok ;
3530
 
3531
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3532
    ok = 1 ;
3533
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3534
    if ( temp_val1[29] !== 0 )
3535
    begin
3536
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3537
        $display("Received Master Abort bit was set with no reason!") ;
3538
        test_fail("Received Master Abort bit was set with no reason") ;
3539
        ok = 0 ;
3540
    end
3541
 
3542
    if ( temp_val1[28] !== 1 )
3543
    begin
3544
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3545
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3546
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3547
        ok = 0 ;
3548
    end
3549
 
3550
    if ( ok )
3551
        test_ok ;
3552
 
3553
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3554
 
3555
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3556
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3557
    if ( temp_val1[1] !== 0 )
3558
    begin
3559
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3560
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3561
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3562
    end
3563
    else
3564
        test_ok ;
3565
 
3566
    $display("Introducing Target Abort error to CAB read!") ;
3567
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3568
 
3569
    for ( i = 0 ; i < 4 ; i = i + 1 )
3570
    begin
3571
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3572
        read_data`READ_SEL     = 4'b1010 ;
3573
        wishbone_master.blk_read_data_in[i] = read_data ;
3574
    end
3575
 
3576
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3577
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3578
    write_flags`WB_TRANSFER_CAB    = 1 ;
3579
 
3580
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3581
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3582
 
3583
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3584
 
3585
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3586
    begin
3587
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3588
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3589
        $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) ;
3590
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3591
        disable main ;
3592
    end
3593
 
3594
    read_status = wishbone_master.blk_read_data_out[0] ;
3595
    temp_val1 = read_status`READ_DATA ;
3596
    temp_val2 = wmem_data[120] ;
3597
 
3598
    // last write to this address was with only two byte enables - check only those
3599
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3600
    begin
3601
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3602
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3603
    end
3604
    else
3605
        test_ok ;
3606
 
3607
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3608
    ok = 1 ;
3609
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3610
    if ( temp_val1[29] !== 0 )
3611
    begin
3612
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3613
        $display("Received Master Abort bit was set with no reason!") ;
3614
        test_fail("Received Master Abort bit was set with no reason") ;
3615
        ok = 0 ;
3616
    end
3617
 
3618
    if ( temp_val1[28] !== 1 )
3619
    begin
3620
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3621
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3622
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3623
        ok = 0 ;
3624
    end
3625
 
3626
    if ( ok )
3627
       test_ok ;
3628
 
3629
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3630
 
3631
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3632
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3633
 
3634
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3635
    for ( i = 0 ; i < 3 ; i = i + 1 )
3636
    begin
3637
        read_data`READ_ADDRESS = target_address + 4*i ;
3638
        read_data`READ_SEL     = 4'b1111 ;
3639
        wishbone_master.blk_read_data_in[i] = read_data ;
3640
    end
3641
 
3642
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3643
 
3644
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3645
 
3646
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3647
    begin
3648
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3649
        $display("Complete burst read through WB slave didn't succeed!") ;
3650
        test_fail("bridge didn't process Burst Read in an expected way") ;
3651
        disable main ;
3652
    end
3653
    else
3654
        test_ok ;
3655
 
3656
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3657
 
3658
    for ( i = 0 ; i < 3 ; i = i + 1 )
3659
    begin
3660
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3661
        read_data`READ_SEL     = 4'b1111 ;
3662
        wishbone_master.blk_read_data_in[i] = read_data ;
3663
    end
3664
 
3665
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3666
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3667
    write_flags`WB_TRANSFER_CAB    = 1 ;
3668
 
3669
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3670
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3671
 
3672
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3673
 
3674
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3675
    begin
3676
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3677
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3678
        $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) ;
3679
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3680
        disable main ;
3681
    end
3682
 
3683
    for ( i = 0 ; i < 3 ; i = i + 1 )
3684
    begin
3685
        ok = 1 ;
3686
        read_status = wishbone_master.blk_read_data_out[i] ;
3687
        temp_val1 = read_status`READ_DATA ;
3688
        temp_val2 = wmem_data[120 + i] ;
3689
 
3690
        // last write to this address was with only two byte enables - check only those
3691
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3692
        begin
3693
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3694
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3695
            ok = 0 ;
3696
        end
3697
    end
3698
 
3699
    if ( ok )
3700
        test_ok ;
3701
 
3702
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3703
    ok = 1 ;
3704
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3705
    if ( temp_val1[29] !== 0 )
3706
    begin
3707
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3708
        $display("Received Master Abort bit was set with no reason!") ;
3709
        test_fail("Received Master Abort bit was set with no reason") ;
3710
        ok = 0 ;
3711
    end
3712
 
3713
    if ( temp_val1[28] !== 1 )
3714
    begin
3715
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3716
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3717
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3718
        ok = 0 ;
3719
    end
3720
 
3721
    if ( ok )
3722
       test_ok ;
3723
 
3724
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3725
 
3726
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3727
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3728
 
3729
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3730
    for ( i = 0 ; i < 3 ; i = i + 1 )
3731
    begin
3732
        read_data`READ_ADDRESS = target_address + 4*i ;
3733
        read_data`READ_SEL     = 4'b1111 ;
3734
        wishbone_master.blk_read_data_in[i] = read_data ;
3735
    end
3736
 
3737
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3738
 
3739
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3740
 
3741
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3742
    begin
3743
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3744
        $display("Complete burst read through WB slave didn't succeed!") ;
3745
        test_fail("bridge didn't process Burst Read in an expected way") ;
3746
        disable main ;
3747
    end
3748
    else
3749
        test_ok ;
3750
 
3751
    // test error on IO write
3752
    // change base address
3753
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3754
    write_data`WRITE_SEL     = 4'b0101 ;
3755
    write_data`WRITE_ADDRESS = target_address ;
3756
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3757
 
3758
    write_flags`WB_TRANSFER_CAB    = 0 ;
3759
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3760
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3761
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3762
    fork
3763
    begin
3764
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3765
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3766
        begin
3767
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3768
            $display("WB slave failed to accept IO write!") ;
3769
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3770
            disable main ;
3771
        end
3772
    end
3773
    begin
3774
        musnt_respond(ok) ;
3775
        if ( ok !== 1 )
3776
        begin
3777
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3778
            $display("Testbench is configured wrong!") ;
3779
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3780
        end
3781
        else
3782
            test_ok ;
3783
    end
3784
    join
3785
 
3786
    // check statuses and everything else
3787
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3788
    ok = 1 ;
3789
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3790
    if ( temp_val1[8] !== 1 )
3791
    begin
3792
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3793
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3794
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3795
        ok = 0 ;
3796
    end
3797
 
3798
    if ( temp_val1[9] !== 1 )
3799
    begin
3800
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3801
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3802
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3803
        ok = 0 ;
3804
    end
3805
 
3806
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3807
    begin
3808
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3809
        $display("Value in W_ERR_CS register was wrong!") ;
3810
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3811
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3812
        ok = 0 ;
3813
    end
3814
 
3815
    if ( ok )
3816
        test_ok ;
3817
 
3818
    // check erroneous address and data
3819
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3820
    ok = 1 ;
3821
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3822
    if ( temp_val1 !== target_address )
3823
    begin
3824
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3825
        $display("Value in W_ERR_ADDR register was wrong!") ;
3826
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3827
        test_fail("WB Erroneous Address register didn't provide right value") ;
3828
        ok = 0 ;
3829
    end
3830
 
3831
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3832
    if ( temp_val1 !== 32'hAAAA_AAAA )
3833
    begin
3834
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3835
        $display("Value in W_ERR_DATA register was wrong!") ;
3836
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3837
        test_fail("WB Erroneous Data register didn't provide right value") ;
3838
        ok = 0 ;
3839
    end
3840
 
3841
    if ( ok )
3842
        test_ok ;
3843
 
3844
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3845
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3846
    if ( temp_val1[1] !== 1 )
3847
    begin
3848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3849
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3850
        test_fail("expected interrupt status bit was not set") ;
3851
    end
3852
    else
3853
        test_ok ;
3854
 
3855
    // clear interrupts and errors
3856
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3857
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3858
 
3859
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3860
    ok = 1 ;
3861
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3862
    if ( temp_val1[29] !== 1 )
3863
    begin
3864
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3865
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3866
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3867
        ok = 0 ;
3868
    end
3869
 
3870
    if ( temp_val1[28] !== 0 )
3871
    begin
3872
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3873
        $display("Received Target Abort bit was set for no reason!") ;
3874
        test_fail("Received Target Abort bit was set for no reason") ;
3875
        ok = 0 ;
3876
    end
3877
 
3878
    if ( ok )
3879
        test_ok ;
3880
 
3881
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3882
 
3883
    // disable image
3884
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3885
    if ( ok !== 1 )
3886
    begin
3887
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3888
        test_fail("WB Image Address Mask register couldn't be written") ;
3889
        disable main ;
3890
    end
3891
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3892
 
3893
end
3894
endtask
3895
 
3896
task parity_checking ;
3897
    reg   [11:0] ctrl_offset ;
3898
    reg   [11:0] ba_offset ;
3899
    reg   [11:0] am_offset ;
3900
    reg   [11:0] ta_offset ;
3901
    reg `WRITE_STIM_TYPE write_data ;
3902
    reg `READ_STIM_TYPE  read_data ;
3903
    reg `READ_RETURN_TYPE read_status ;
3904
 
3905
    reg `WRITE_RETURN_TYPE write_status ;
3906
    reg `WB_TRANSFER_FLAGS write_flags ;
3907
    reg [31:0] temp_val1 ;
3908
    reg [31:0] temp_val2 ;
3909
    reg        ok   ;
3910
    reg [11:0] pci_ctrl_offset ;
3911
    reg [31:0] image_base ;
3912
    reg [31:0] target_address ;
3913
    reg [11:0] icr_offset ;
3914
    reg [11:0] isr_offset ;
3915
    reg [11:0] p_ba_offset ;
3916
    reg [11:0] p_am_offset ;
3917
    reg [11:0] p_ctrl_offset ;
3918
    integer    i ;
3919
    reg        perr_asserted ;
3920
begin:main
3921
    $display("******************************* Testing Parity Checker functions ********************************") ;
3922
    $display("Testing Parity Errors during Master Transactions!") ;
3923
    $display("Introducing Parity Erros to Master Writes!") ;
3924
    $fdisplay(pci_mon_log_file_desc,
3925
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
3926
 
3927
    // image 1 is used for error testing, since it is always implemented
3928
    pci_ctrl_offset = 12'h004 ;
3929
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
3930
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
3931
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
3932
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
3933
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
3934
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
3935
 
3936
    // image 1 for PCI target
3937
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
3938
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
3939
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
3940
 
3941
    target_address  = `BEH_TAR1_MEM_START ;
3942
    image_base      = 0 ;
3943
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
3944
 
3945
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
3946
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
3947
    write_flags                    = 0 ;
3948
    write_flags`INIT_WAITS         = tb_init_waits ;
3949
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
3950
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3951
 
3952
    // enable master & target operation and disable parity functions
3953
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
3954
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
3955
    if ( ok !== 1 )
3956
    begin
3957
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
3958
        test_fail("PCI Device Control register could not be written to") ;
3959
        disable main ;
3960
    end
3961
 
3962
    // prepare image control register
3963
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
3964
    if ( ok !== 1 )
3965
    begin
3966
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
3967
        test_fail("WB Image Control register could not be written to") ;
3968
        disable main ;
3969
    end
3970
 
3971
    // prepare base address register
3972
    config_write( ba_offset, image_base, 4'hF, ok ) ;
3973
    if ( ok !== 1 )
3974
    begin
3975
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
3976
        test_fail("WB Image Base Address register could not be written to") ;
3977
        disable main ;
3978
    end
3979
 
3980
    // write address mask register
3981
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
3982
    if ( ok !== 1 )
3983
    begin
3984
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3985
        test_fail("WB Image Address Mask register could not be written to") ;
3986
        disable main ;
3987
    end
3988
 
3989
    // disable parity interrupts
3990
    config_write( icr_offset, 0, 4'hF, ok ) ;
3991
    if ( ok !== 1 )
3992
    begin
3993
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
3994
        test_fail("Interrupt Control register could not be written to") ;
3995
        disable main ;
3996
    end
3997
 
3998
    write_data`WRITE_ADDRESS = target_address ;
3999
    write_data`WRITE_DATA    = wmem_data[0] ;
4000
    write_data`WRITE_SEL     = 4'b1111 ;
4001
 
4002
    // enable target's 1 response to parity errors
4003
    configuration_cycle_write(0,             // bus number
4004
                              1,             // device number
4005
                              0,             // function number
4006
                              1,             // register number
4007
                              0,             // type of configuration cycle
4008
                              4'b0001,       // byte enables
4009
                              32'h0000_0047  // data
4010
                             ) ;
4011
 
4012
    // disable target's 2 response to parity errors
4013
    configuration_cycle_write(0,             // bus number
4014
                              2,             // device number
4015
                              0,             // function number
4016
                              1,             // register number
4017
                              0,             // type of configuration cycle
4018
                              4'b0001,       // byte enables
4019
                              32'h0000_0007  // data
4020
                             ) ;
4021
 
4022
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4023
 
4024
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4025
    fork
4026
    begin
4027
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4028
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4029
        begin
4030
            $display("Parity checker testing failed! Time %t ", $time) ;
4031
            $display("Bridge failed to process single memory write!") ;
4032
            test_fail("bridge failed to post single WB memory write") ;
4033
            disable main ;
4034
        end
4035
    end
4036
    begin:wait_perr1
4037
        perr_asserted = 0 ;
4038
        @(posedge pci_clock) ;
4039
 
4040 35 mihad
        while ( PERR !== 0 )
4041 15 mihad
            @(posedge pci_clock) ;
4042
 
4043 35 mihad
        perr_asserted = 1 ;
4044 15 mihad
 
4045
    end
4046
    begin
4047
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4048
 
4049
        if ( ok !== 1 )
4050
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4051
 
4052 35 mihad
        repeat(2)
4053 15 mihad
            @(posedge pci_clock) ;
4054
 
4055 35 mihad
        #1 ;
4056
        if ( !perr_asserted )
4057
            disable wait_perr1 ;
4058 15 mihad
    end
4059
    join
4060
 
4061
    if ( perr_asserted && ok )
4062
    begin
4063
        test_ok ;
4064
    end
4065
    else
4066
    if ( ~perr_asserted )
4067
    begin
4068
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4069
        disable main ;
4070
    end
4071
 
4072
    // check all the statuses - if HOST is defined, wait for them to be synced
4073
    `ifdef HOST
4074
    repeat(4)
4075
        @(posedge wb_clock) ;
4076
    `endif
4077
 
4078
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4079
    ok = 1 ;
4080
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4081
    if ( temp_val1[31] !== 1 )
4082
    begin
4083
        $display("Parity checker testing failed! Time %t ", $time) ;
4084
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4085
        test_fail("Detected Parity Error bit was not set after Write Master Data Parity Error") ;
4086
        ok = 0 ;
4087
    end
4088
 
4089
    if ( temp_val1[30] !== 0 )
4090
    begin
4091
        $display("Parity checker testing failed! Time %t ", $time) ;
4092
        $display("Signalled System Error bit was set for no reason!") ;
4093
        test_fail("Signalled System Error bit was set for no reason") ;
4094
        ok = 0 ;
4095
    end
4096
 
4097
    if ( temp_val1[24] !== 0 )
4098
    begin
4099
        $display("Parity checker testing failed! Time %t ", $time) ;
4100
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4101
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4102
        ok = 0 ;
4103
    end
4104
 
4105
    if ( ok )
4106
        test_ok ;
4107
 
4108
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4109
    // clear parity bits and enable parity response
4110
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4111
    if ( ok !== 1 )
4112
    begin
4113
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4114
        test_fail("write to PCI Status Register failed") ;
4115
        disable main ;
4116
    end
4117
 
4118
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4119
    fork
4120
    begin
4121
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4122
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4123
        begin
4124
            $display("Parity checker testing failed! Time %t ", $time) ;
4125
            $display("Bridge failed to process single memory write!") ;
4126
            test_fail("bridge failed to post single memory write") ;
4127
            disable main ;
4128
        end
4129
    end
4130
    begin:wait_perr2
4131
        perr_asserted = 0 ;
4132
        @(posedge pci_clock) ;
4133
 
4134 35 mihad
        while ( PERR !== 0 )
4135 15 mihad
            @(posedge pci_clock) ;
4136
 
4137 35 mihad
        perr_asserted = 1 ;
4138 15 mihad
 
4139
    end
4140
    begin
4141
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4142
 
4143
        if ( ok !== 1 )
4144
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4145
 
4146 35 mihad
        repeat(2)
4147 15 mihad
            @(posedge pci_clock) ;
4148
 
4149 35 mihad
        #1 ;
4150
        if (!perr_asserted)
4151
            disable wait_perr2 ;
4152 15 mihad
    end
4153
    join
4154
 
4155
    if ( perr_asserted && ok )
4156
    begin
4157
        test_ok ;
4158
    end
4159
    else
4160
    if ( ~perr_asserted )
4161
    begin
4162
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4163
        disable main ;
4164
    end
4165
 
4166
    // check all the statuses - if HOST is defined, wait for them to be synced
4167
    `ifdef HOST
4168
    repeat(4)
4169
        @(posedge wb_clock) ;
4170
    `endif
4171
 
4172
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4173
    ok = 1 ;
4174
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4175
    if ( temp_val1[31] !== 1 )
4176
    begin
4177
        $display("Parity checker testing failed! Time %t ", $time) ;
4178
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4179
        test_fail("Detected Parity Error bit was not set after parity error on PCI bus") ;
4180
        ok = 0 ;
4181
    end
4182
 
4183
    if ( temp_val1[30] !== 0 )
4184
    begin
4185
        $display("Parity checker testing failed! Time %t ", $time) ;
4186
        $display("Signalled System Error bit was set for no reason!") ;
4187
        test_fail("Signalled System Error bit was set for no reason") ;
4188
        ok = 0 ;
4189
    end
4190
 
4191
    if ( temp_val1[24] !== 1 )
4192
    begin
4193
        $display("Parity checker testing failed! Time %t ", $time) ;
4194
        $display("Master Data Parity Error bit wasn't set even though Parity Error Response bit was set!") ;
4195
        test_fail("Master Data Parity Error bit wasn't set after Parity Error on PCI bus, even though Parity Error Response bit was set") ;
4196
        ok = 0 ;
4197
    end
4198
 
4199
    if ( ok )
4200
        test_ok ;
4201
 
4202
    // clear status bits and disable parity error response
4203
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4204
 
4205
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4206
 
4207
    // disable perr generation and perform a write - no bits should be set
4208
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4209
    fork
4210
    begin
4211
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4212
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4213
        begin
4214
            $display("Parity checker testing failed! Time %t ", $time) ;
4215
            $display("Bridge failed to process single memory write!") ;
4216
            test_fail("bridge failed to post single memory write") ;
4217
            disable main ;
4218
        end
4219
    end
4220
    begin
4221
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4222
 
4223
        if ( ok !== 1 )
4224
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4225
        else
4226
            test_ok ;
4227
 
4228
        repeat(3)
4229
            @(posedge pci_clock) ;
4230
    end
4231
    join
4232
 
4233
    `ifdef HOST
4234
    repeat(4)
4235
        @(posedge wb_clock) ;
4236
    `endif
4237
 
4238
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4239
    ok = 1 ;
4240
 
4241
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4242
    if ( temp_val1[31] !== 0 )
4243
    begin
4244
        $display("Parity checker testing failed! Time %t ", $time) ;
4245
        $display("Detected Parity Error bit was set for no reason!") ;
4246
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4247
        ok = 0 ;
4248
    end
4249
 
4250
    if ( temp_val1[30] !== 0 )
4251
    begin
4252
        $display("Parity checker testing failed! Time %t ", $time) ;
4253
        $display("Signalled System Error bit was set for no reason!") ;
4254
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4255
        ok = 0 ;
4256
    end
4257
 
4258
    if ( temp_val1[24] !== 0 )
4259
    begin
4260
        $display("Parity checker testing failed! Time %t ", $time) ;
4261
        $display("Master Data Parity Error bit was set for no reason!") ;
4262
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4263
        ok = 0 ;
4264
    end
4265
 
4266
    if ( ok )
4267
        test_ok ;
4268
 
4269
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4270
 
4271
    read_data = 0 ;
4272
    read_data`READ_ADDRESS  = target_address ;
4273
    read_data`READ_SEL      = 4'hF ;
4274
    read_data`READ_TAG_STIM = 0 ;
4275
 
4276
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4277
 
4278
    // enable parity and system error interrupts
4279
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4280
 
4281
    // enable parity error response
4282
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4283
 
4284
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4285
 
4286
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4287
    fork
4288
    begin
4289
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4290
    end
4291
    begin:wait_perr4
4292
        perr_asserted = 0 ;
4293
        @(posedge pci_clock) ;
4294 35 mihad
        while ( PERR !== 0 )
4295 15 mihad
            @(posedge pci_clock) ;
4296
 
4297 35 mihad
        perr_asserted = 1 ;
4298 15 mihad
 
4299
    end
4300
    begin
4301
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4302
 
4303
        if ( ok !== 1 )
4304
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4305
 
4306
        repeat(2)
4307
            @(posedge pci_clock) ;
4308
 
4309 35 mihad
        #1 ;
4310
        if ( !perr_asserted )
4311
            disable wait_perr4 ;
4312 15 mihad
    end
4313
    join
4314
 
4315
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4316
    begin
4317
        $display("Parity checker testing failed! Time %t ", $time) ;
4318
        $display("Bridge failed to process single memory read!") ;
4319
        test_fail("bridge didn't process single memory read correctly") ;
4320
        ok = 0 ;
4321
    end
4322
 
4323
    if ( perr_asserted && ok )
4324
    begin
4325
        test_ok ;
4326
    end
4327
    else
4328
    if ( ~perr_asserted )
4329
    begin
4330
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4331
        disable main ;
4332
    end
4333
 
4334
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4335
    // interrupt should also be present
4336
    `ifdef HOST
4337
        repeat(4)
4338 26 mihad
            @(posedge pci_clock) ;
4339
        repeat(4)
4340 15 mihad
            @(posedge wb_clock) ;
4341
 
4342
        if ( INT_O !== 1 )
4343
        begin
4344
            $display("Parity checker testing failed! Time %t ", $time) ;
4345
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4346
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4347
        end
4348
        else
4349
            test_ok ;
4350
    `else
4351
    `ifdef GUEST
4352 26 mihad
        repeat(4)
4353
            @(posedge wb_clock) ;
4354
        repeat(4)
4355 15 mihad
            @(posedge pci_clock) ;
4356
 
4357
        if ( INTA !== 1 )
4358
        begin
4359
            $display("Parity checker testing failed! Time %t ", $time) ;
4360
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4361
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4362
        end
4363
        else
4364
            test_ok ;
4365
    `endif
4366
    `endif
4367
 
4368
    // check statuses!
4369
 
4370
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4371
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4372
    ok = 1 ;
4373
 
4374
    if ( temp_val1[31] !== 1 )
4375
    begin
4376
        $display("Parity checker testing failed! Time %t ", $time) ;
4377
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4378
        test_fail("Detected Parity Error bit was not set when parity error was presented on Read transaction") ;
4379
        ok = 0 ;
4380
    end
4381
 
4382
    if ( temp_val1[30] !== 0 )
4383
    begin
4384
        $display("Parity checker testing failed! Time %t ", $time) ;
4385
        $display("Signalled System Error bit was set for no reason!") ;
4386
        test_fail("Signalled System Error bit was set for no reason") ;
4387
        ok = 0 ;
4388
    end
4389
 
4390
    if ( temp_val1[24] !== 1 )
4391
    begin
4392
        $display("Parity checker testing failed! Time %t ", $time) ;
4393
        $display("Master Data Parity Error bit was not set when parity error was presented during read transaction!") ;
4394
        test_fail("Master Data Parity Error bit was not set when parity error was presented during read transaction and Parity Error Response was enabled") ;
4395
        ok = 0 ;
4396
    end
4397
 
4398
    if ( ok )
4399
        test_ok ;
4400
 
4401
    // clear statuses and disable parity error response
4402
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4403
 
4404
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4405
    ok = 1 ;
4406
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4407
 
4408
    if ( temp_val1[4] !== 0 )
4409
    begin
4410
        $display("Parity checker testing failed! Time %t ", $time) ;
4411
        $display("System error interrupt status bit set for no reason!") ;
4412
        test_fail("System error interrupt status bit set for no reason") ;
4413
        ok = 0 ;
4414
    end
4415
 
4416
    `ifdef HOST
4417
    if ( temp_val1[3] !== 1 )
4418
    begin
4419
        $display("Parity checker testing failed! Time %t ", $time) ;
4420
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4421
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4422
        ok = 0 ;
4423
    end
4424
    `else
4425
    if ( temp_val1[3] !== 0 )
4426
    begin
4427
        $display("Parity checker testing failed! Time %t ", $time) ;
4428
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4429
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4430
        ok = 0 ;
4431
    end
4432
    `endif
4433
 
4434
    if ( ok )
4435
        test_ok ;
4436
 
4437
    // clear int statuses
4438
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4439
 
4440
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4441
 
4442
    `ifdef HOST
4443
        repeat(4)
4444 26 mihad
            @(posedge pci_clock) ;
4445
        repeat(4)
4446 15 mihad
            @(posedge wb_clock) ;
4447
 
4448
        if ( INT_O !== 0 )
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
    `else
4457
    `ifdef GUEST
4458 26 mihad
        repeat(4)
4459
            @(posedge wb_clock) ;
4460
        repeat(4)
4461 15 mihad
            @(posedge pci_clock) ;
4462
 
4463
        if ( INTA !== 1 )
4464
        begin
4465
            $display("Parity checker testing failed! Time %t ", $time) ;
4466
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4467
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4468
        end
4469
        else
4470
            test_ok ;
4471
    `endif
4472
    `endif
4473
 
4474
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4475
 
4476
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4477
    fork
4478
    begin
4479
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4480
    end
4481
    begin:wait_perr5
4482
        perr_asserted = 0 ;
4483
        @(posedge pci_clock) ;
4484
        while ( PERR === 1 )
4485
            @(posedge pci_clock) ;
4486
 
4487
        perr_asserted = 1 ;
4488
        $display("Parity checker testing failed! Time %t ", $time) ;
4489
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4490
        test_fail("Bridge asserted PERR during read transaction when Parity Error response was disabled") ;
4491
    end
4492
    begin
4493
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4494
        if ( ok !== 1 )
4495
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4496
 
4497
        // perr can be asserted on idle or next PCI address phase
4498
        repeat(2)
4499
            @(posedge pci_clock) ;
4500
 
4501 35 mihad
        #1 ;
4502
        if ( !perr_asserted )
4503
            disable wait_perr5 ;
4504 15 mihad
    end
4505
    join
4506
 
4507
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4508
    begin
4509
        $display("Parity checker testing failed! Time %t ", $time) ;
4510
        $display("Bridge failed to process single memory read!") ;
4511
        test_fail("bridge failed to process single memory read correctly") ;
4512
        ok = 0 ;
4513
    end
4514
 
4515
    if ( ok && !perr_asserted)
4516
        test_ok ;
4517
 
4518
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4519
 
4520
    // interrupts should not be present
4521
    `ifdef HOST
4522
        repeat( 4 )
4523 26 mihad
            @(posedge pci_clock) ;
4524
        repeat( 4 )
4525 15 mihad
            @(posedge wb_clock) ;
4526
        if ( INT_O !== 0 )
4527
        begin
4528
            $display("Parity checker testing failed! Time %t ", $time) ;
4529
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4530
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4531
        end
4532
        else
4533
            test_ok ;
4534
    `else
4535
    `ifdef GUEST
4536
        repeat( 4 )
4537 26 mihad
            @(posedge wb_clock) ;
4538
        repeat( 4 )
4539 15 mihad
            @(posedge pci_clock) ;
4540
        if ( INTA !== 1 )
4541
        begin
4542
            $display("Parity checker testing failed! Time %t ", $time) ;
4543
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4544
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4545
        end
4546
        else
4547
            test_ok ;
4548
    `endif
4549
    `endif
4550
 
4551
    // check statuses!
4552
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4553
    ok = 1 ;
4554
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4555
    if ( temp_val1[31] !== 1 )
4556
    begin
4557
        $display("Parity checker testing failed! Time %t ", $time) ;
4558
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4559
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4560
        ok = 0 ;
4561
    end
4562
 
4563
    if ( temp_val1[30] !== 0 )
4564
    begin
4565
        $display("Parity checker testing failed! Time %t ", $time) ;
4566
        $display("Signalled System Error bit was set for no reason!") ;
4567
        test_fail("Signalled System Error bit was set for no reason") ;
4568
        ok = 0 ;
4569
    end
4570
 
4571
    if ( temp_val1[24] !== 0 )
4572
    begin
4573
        $display("Parity checker testing failed! Time %t ", $time) ;
4574
        $display("Master Data Parity Error bit was set when parity error was presented during read transaction, but Parity Response was disabled!") ;
4575
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4576
        ok = 0 ;
4577
    end
4578
 
4579
    if ( ok )
4580
        test_ok ;
4581
 
4582
    // clear statuses
4583
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4584
 
4585
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4586
    ok = 1 ;
4587
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4588
 
4589
    if ( temp_val1[4] !== 0 )
4590
    begin
4591
        $display("Parity checker testing failed! Time %t ", $time) ;
4592
        $display("System error interrupt status bit set for no reason!") ;
4593
        test_fail("System error interrupt status bit set for no reason") ;
4594
        ok = 0 ;
4595
    end
4596
 
4597
    if ( temp_val1[3] !== 0 )
4598
    begin
4599
        $display("Parity checker testing failed! Time %t ", $time) ;
4600
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4601
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4602
        ok = 0 ;
4603
    end
4604
 
4605
    if ( ok )
4606
        test_ok ;
4607
 
4608
    // enable all responses to parity errors!
4609
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4610
 
4611
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4612
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4613
 
4614
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4615
 
4616
    // repeat a read
4617
    fork
4618
    begin
4619
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4620
    end
4621
    begin:wait_perr6
4622
        perr_asserted = 0 ;
4623
        @(posedge pci_clock) ;
4624
        while ( PERR === 1 )
4625
            @(posedge pci_clock) ;
4626
 
4627
        perr_asserted = 1 ;
4628
        $display("Parity checker testing failed! Time %t ", $time) ;
4629
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4630
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4631
    end
4632
    begin
4633
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4634
        if ( ok !== 1 )
4635
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4636
 
4637
        repeat(2)
4638
            @(posedge pci_clock) ;
4639
 
4640 35 mihad
        #1 ;
4641
        if ( !perr_asserted )
4642
            disable wait_perr6 ;
4643 15 mihad
    end
4644
    join
4645
 
4646
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4647
    begin
4648
        $display("Parity checker testing failed! Time %t ", $time) ;
4649
        $display("Bridge failed to process single memory read!") ;
4650
        test_fail("bridge didn't process single memory read as expected") ;
4651
        ok = 0 ;
4652
    end
4653
 
4654
    if ( ok && !perr_asserted)
4655
        test_ok ;
4656
 
4657
    // check statuses!
4658
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4659
    ok = 1 ;
4660
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4661
    if ( temp_val1[31] !== 0 )
4662
    begin
4663
        $display("Parity checker testing failed! Time %t ", $time) ;
4664
        $display("Detected Parity Error bit was set for no reason!") ;
4665
        test_fail("Detected Parity Error bit was set for no reason") ;
4666
        ok = 0 ;
4667
    end
4668
 
4669
    if ( temp_val1[30] !== 0 )
4670
    begin
4671
        $display("Parity checker testing failed! Time %t ", $time) ;
4672
        $display("Signalled System Error bit was set for no reason!") ;
4673
        test_fail("Signalled System Error bit was set for no reason") ;
4674
        ok = 0 ;
4675
    end
4676
 
4677
    if ( temp_val1[24] !== 0 )
4678
    begin
4679
        $display("Parity checker testing failed! Time %t ", $time) ;
4680
        $display("Master Data Parity Error bit was set for no reason!") ;
4681
        test_fail("Master Data Parity Error bit was set for no reason") ;
4682
        ok = 0 ;
4683
    end
4684
 
4685
    if ( ok )
4686
        test_ok ;
4687
 
4688
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4689
    ok = 1 ;
4690
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4691
 
4692
    if ( temp_val1[4] !== 0 )
4693
    begin
4694
        $display("Parity checker testing failed! Time %t ", $time) ;
4695
        $display("System error interrupt status bit set for no reason!") ;
4696
        test_fail("System error interrupt status bit set for no reason") ;
4697
        ok = 0 ;
4698
    end
4699
 
4700
    if ( temp_val1[3] !== 0 )
4701
    begin
4702
        $display("Parity checker testing failed! Time %t ", $time) ;
4703
        $display("Parity error interrupt status bit set for no reason!") ;
4704
        test_fail("Parity error interrupt status bit set for no reason") ;
4705
        ok = 0 ;
4706
    end
4707
 
4708
    if ( ok )
4709
        test_ok ;
4710
 
4711
    $display("Presenting address parity error on PCI bus!") ;
4712
    // enable parity errors - this should not affect system errors
4713
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4714
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4715
 
4716
    // perform PCI write
4717
    // check transaction progress
4718
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4719
    fork
4720
    begin
4721
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4722
               target_address, 32'h1234_5678,
4723
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4724
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4725
        do_pause( 1 ) ;
4726
    end
4727
    begin:wait_serr7
4728
        perr_asserted = 0 ;
4729
        @(posedge pci_clock) ;
4730
        while( SERR === 1 )
4731
            @(posedge pci_clock) ;
4732
 
4733
        perr_asserted = 1 ;
4734
        $display("Parity checker testing failed! Time %t ", $time) ;
4735
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4736
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4737
    end
4738
    begin
4739
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4740
        if ( ok !== 1 )
4741
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4742
 
4743 35 mihad
        if ( !perr_asserted )
4744
            disable wait_serr7 ;
4745 15 mihad
    end
4746
    join
4747
 
4748
    if ( ok && !perr_asserted)
4749
        test_ok ;
4750
 
4751
    // check statuses!
4752
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4753
    ok = 1 ;
4754
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4755
    if ( temp_val1[31] !== 1 )
4756
    begin
4757
        $display("Parity checker testing failed! Time %t ", $time) ;
4758
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4759
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4760
        ok = 0 ;
4761
    end
4762
 
4763
    if ( temp_val1[30] !== 0 )
4764
    begin
4765
        $display("Parity checker testing failed! Time %t ", $time) ;
4766
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4767
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4768
        ok = 0 ;
4769
    end
4770
 
4771
    if ( temp_val1[24] !== 0 )
4772
    begin
4773
        $display("Parity checker testing failed! Time %t ", $time) ;
4774
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4775
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4776
        ok = 0 ;
4777
    end
4778
 
4779
    if ( ok )
4780
        test_ok ;
4781
 
4782
    // clear statuses
4783
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4784
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4785
    fork
4786
    begin
4787
        ipci_unsupported_commands_master.master_reference
4788
        (
4789
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4790
            32'h5555_5555,      // second part of address in dual address cycle
4791
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4792
            `BC_MEM_WRITE,      // normal command
4793
            4'h0,               // byte enables
4794
            32'h1234_5678,      // data
4795
            1'b1,               // make address parity error on first phase of dual address
4796
            1'b0,               // make address parity error on second phase of dual address
4797
            ok                  // result of operation
4798
        ) ;
4799 35 mihad
        if ( !perr_asserted )
4800
            disable wait_serr8 ;
4801 15 mihad
    end
4802
    begin:wait_serr8
4803
        perr_asserted = 0 ;
4804
        @(posedge pci_clock) ;
4805
        while( SERR === 1 )
4806
            @(posedge pci_clock) ;
4807
 
4808
        perr_asserted = 1 ;
4809
        $display("Parity checker testing failed! Time %t ", $time) ;
4810
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4811
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4812
    end
4813
    join
4814
 
4815
    if ( ok && !perr_asserted)
4816
        test_ok ;
4817
 
4818
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4819
    fork
4820
    begin
4821
        ipci_unsupported_commands_master.master_reference
4822
        (
4823
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4824
            32'h5555_5555,      // second part of address in dual address cycle
4825
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4826
            `BC_MEM_WRITE,      // normal command
4827
            4'h0,               // byte enables
4828
            32'h1234_5678,      // data
4829
            1'b0,               // make address parity error on first phase of dual address
4830
            1'b1,               // make address parity error on second phase of dual address
4831
            ok                  // result of operation
4832
        ) ;
4833 35 mihad
        if ( !perr_asserted )
4834
            disable wait_serr9 ;
4835 15 mihad
    end
4836
    begin:wait_serr9
4837
        perr_asserted = 0 ;
4838
        @(posedge pci_clock) ;
4839
        while( SERR === 1 )
4840
            @(posedge pci_clock) ;
4841
 
4842
        perr_asserted = 1 ;
4843
        $display("Parity checker testing failed! Time %t ", $time) ;
4844
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4845
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4846
    end
4847
    join
4848
 
4849
    if ( ok && !perr_asserted)
4850
        test_ok ;
4851
 
4852
    // check statuses!
4853
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4854
    ok = 1 ;
4855
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4856
    if ( temp_val1[31] !== 1 )
4857
    begin
4858
        $display("Parity checker testing failed! Time %t ", $time) ;
4859
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4860
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4861
        ok = 0 ;
4862
    end
4863
 
4864
    if ( temp_val1[30] !== 0 )
4865
    begin
4866
        $display("Parity checker testing failed! Time %t ", $time) ;
4867
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4868
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4869
        ok = 0 ;
4870
    end
4871
 
4872
    if ( temp_val1[24] !== 0 )
4873
    begin
4874
        $display("Parity checker testing failed! Time %t ", $time) ;
4875
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4876
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4877
        ok = 0 ;
4878
    end
4879
 
4880
    if ( ok )
4881
        test_ok ;
4882
 
4883
    // clear statuses
4884
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4885
 
4886
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4887
    fork
4888
    begin
4889
        ipci_unsupported_commands_master.master_reference
4890
        (
4891
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4892
            32'h5555_5555,      // second part of address in dual address cycle
4893
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4894
            `BC_MEM_WRITE,      // normal command
4895
            4'h0,               // byte enables
4896
            32'h1234_5678,      // data
4897
            1'b1,               // make address parity error on first phase of dual address
4898
            1'b1,               // make address parity error on second phase of dual address
4899
            ok                  // result of operation
4900
        ) ;
4901 35 mihad
        if ( !perr_asserted )
4902
            disable wait_serr10 ;
4903 15 mihad
    end
4904
    begin:wait_serr10
4905
        perr_asserted = 0 ;
4906
        @(posedge pci_clock) ;
4907
        while( SERR === 1 )
4908
            @(posedge pci_clock) ;
4909
 
4910
        perr_asserted = 1 ;
4911
        $display("Parity checker testing failed! Time %t ", $time) ;
4912
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4913
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4914
    end
4915
    join
4916
 
4917
    if ( ok && !perr_asserted)
4918
        test_ok ;
4919
 
4920
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
4921
 
4922
    `ifdef HOST
4923
        repeat(4)
4924 26 mihad
            @(posedge pci_clock) ;
4925
        repeat(4)
4926 15 mihad
            @(posedge wb_clock) ;
4927
        if ( INT_O !== 0 )
4928
        begin
4929
            $display("Parity checker testing failed! Time %t ", $time) ;
4930
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
4931
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
4932
        end
4933
        else
4934
            test_ok ;
4935
    `else
4936
    `ifdef GUEST
4937 26 mihad
        repeat(4)
4938
            @(posedge wb_clock) ;
4939
        repeat(4)
4940 15 mihad
            @(posedge pci_clock) ;
4941
 
4942
        if ( INTA !== 1 )
4943
        begin
4944
            $display("Parity checker testing failed! Time %t ", $time) ;
4945
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
4946
            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") ;
4947
        end
4948
        else
4949
            test_ok ;
4950
    `endif
4951
    `endif
4952
 
4953
    // check statuses!
4954
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4955
    ok = 1 ;
4956
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4957
    if ( temp_val1[31] !== 1 )
4958
    begin
4959
        $display("Parity checker testing failed! Time %t ", $time) ;
4960
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4961
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4962
        ok = 0 ;
4963
    end
4964
 
4965
    if ( temp_val1[30] !== 0 )
4966
    begin
4967
        $display("Parity checker testing failed! Time %t ", $time) ;
4968
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4969
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4970
        ok = 0 ;
4971
    end
4972
 
4973
    if ( temp_val1[24] !== 0 )
4974
    begin
4975
        $display("Parity checker testing failed! Time %t ", $time) ;
4976
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4977
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4978
        ok = 0 ;
4979
    end
4980
 
4981
    if ( ok )
4982
        test_ok ;
4983
 
4984
    // clear statuses
4985
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4986
 
4987
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4988
    ok = 1 ;
4989
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4990
 
4991
    if ( temp_val1[4] !== 0 )
4992
    begin
4993
        $display("Parity checker testing failed! Time %t ", $time) ;
4994
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
4995
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
4996
        ok = 0 ;
4997
    end
4998
 
4999
    if ( temp_val1[3] !== 0 )
5000
    begin
5001
        $display("Parity checker testing failed! Time %t ", $time) ;
5002
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5003
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5004
        ok = 0 ;
5005
    end
5006
 
5007
    if ( ok )
5008
        test_ok ;
5009
 
5010
    // now enable system error signaling and test response
5011
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5012
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5013
 
5014
    fork
5015
    begin
5016
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5017
               target_address, 32'h1234_5678,
5018
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5019
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5020
        do_pause( 1 ) ;
5021
    end
5022
    begin:wait_serr11
5023
        perr_asserted = 0 ;
5024
        @(posedge pci_clock) ;
5025 35 mihad
        while( SERR !== 0 )
5026 15 mihad
            @(posedge pci_clock) ;
5027
 
5028 35 mihad
        perr_asserted = 1 ;
5029 15 mihad
    end
5030
    begin
5031
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5032
        if ( ok !== 1 )
5033
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5034
 
5035
        @(posedge pci_clock) ;
5036 35 mihad
        #1 ;
5037
        if ( !perr_asserted )
5038
            disable wait_serr11 ;
5039 15 mihad
    end
5040
    join
5041
 
5042
    if ( ok && perr_asserted)
5043
        test_ok ;
5044
    else
5045
    if ( !perr_asserted )
5046
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5047
 
5048
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5049
 
5050
    `ifdef HOST
5051
        repeat(4)
5052 26 mihad
            @(posedge pci_clock) ;
5053
        repeat(4)
5054 15 mihad
            @(posedge wb_clock) ;
5055
        if ( INT_O !== 1 )
5056
        begin
5057
            $display("Parity checker testing failed! Time %t ", $time) ;
5058
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5059
            test_fail("Interrupt Request was not triggered as expected") ;
5060
        end
5061
        else
5062
            test_ok ;
5063
    `else
5064
    `ifdef GUEST
5065 26 mihad
        repeat(4)
5066
            @(posedge wb_clock) ;
5067
        repeat(4)
5068 15 mihad
            @(posedge pci_clock) ;
5069
 
5070
        if ( INTA !== 1 )
5071
        begin
5072
            $display("Parity checker testing failed! Time %t ", $time) ;
5073
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5074
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5075
        end
5076
        else
5077
            test_ok ;
5078
    `endif
5079
    `endif
5080
 
5081
    // check statuses!
5082
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5083
    ok = 1 ;
5084
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5085
    if ( temp_val1[31] !== 1 )
5086
    begin
5087
        $display("Parity checker testing failed! Time %t ", $time) ;
5088
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5089
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5090
        ok = 0 ;
5091
    end
5092
 
5093
    if ( temp_val1[30] !== 1 )
5094
    begin
5095
        $display("Parity checker testing failed! Time %t ", $time) ;
5096
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5097
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5098
        ok = 0 ;
5099
    end
5100
 
5101
    if ( temp_val1[24] !== 0 )
5102
    begin
5103
        $display("Parity checker testing failed! Time %t ", $time) ;
5104
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5105
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5106
        ok = 0 ;
5107
    end
5108
 
5109
    if ( ok )
5110
        test_ok ;
5111
 
5112
    // clear statuses
5113
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5114
 
5115
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5116
 
5117
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5118
    ok = 1 ;
5119
 
5120
    `ifdef HOST
5121
    if ( temp_val1[4] !== 1 )
5122
    begin
5123
        $display("Parity checker testing failed! Time %t ", $time) ;
5124
        $display("System error interrupt status bit not set when expected!") ;
5125
        test_fail("System error interrupt status bit not set when expected") ;
5126
        ok = 0 ;
5127
    end
5128
    `else
5129
    if ( temp_val1[4] !== 0 )
5130
    begin
5131
        $display("Parity checker testing failed! Time %t ", $time) ;
5132
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5133
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5134
        ok = 0 ;
5135
    end
5136
    `endif
5137
 
5138
    if ( temp_val1[3] !== 0 )
5139
    begin
5140
        $display("Parity checker testing failed! Time %t ", $time) ;
5141
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5142
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5143
        ok = 0 ;
5144
    end
5145
 
5146
    if ( ok )
5147
        test_ok ;
5148
 
5149
    // clear statuses
5150
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5151
 
5152
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5153
    fork
5154
    begin
5155
        ipci_unsupported_commands_master.master_reference
5156
        (
5157
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5158
            32'h5555_5555,      // second part of address in dual address cycle
5159
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5160
            `BC_MEM_WRITE,      // normal command
5161
            4'h0,               // byte enables
5162
            32'h1234_5678,      // data
5163
            1'b1,               // make address parity error on first phase of dual address
5164
            1'b0,               // make address parity error on second phase of dual address
5165
            ok                  // result of operation
5166
        ) ;
5167 35 mihad
        if ( !perr_asserted )
5168
            disable wait_serr14 ;
5169 15 mihad
    end
5170
    begin:wait_serr14
5171
        perr_asserted = 0 ;
5172
        @(posedge pci_clock) ;
5173 35 mihad
        while( SERR !== 0 )
5174 15 mihad
            @(posedge pci_clock) ;
5175
 
5176 35 mihad
        perr_asserted = 1 ;
5177 15 mihad
    end
5178
    join
5179
 
5180
    if ( ok && perr_asserted)
5181
        test_ok ;
5182
    else
5183
    if ( !perr_asserted )
5184
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5185
 
5186
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5187
 
5188
    `ifdef HOST
5189
        repeat(4)
5190 26 mihad
            @(posedge pci_clock) ;
5191
        repeat(4)
5192 15 mihad
            @(posedge wb_clock) ;
5193
        if ( INT_O !== 1 )
5194
        begin
5195
            $display("Parity checker testing failed! Time %t ", $time) ;
5196
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5197
            test_fail("Interrupt Request was not triggered as expected") ;
5198
        end
5199
        else
5200
            test_ok ;
5201
    `else
5202
    `ifdef GUEST
5203 26 mihad
        repeat(4)
5204
            @(posedge wb_clock) ;
5205
        repeat(4)
5206 15 mihad
            @(posedge pci_clock) ;
5207
 
5208
        if ( INTA !== 1 )
5209
        begin
5210
            $display("Parity checker testing failed! Time %t ", $time) ;
5211
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5212
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5213
        end
5214
        else
5215
            test_ok ;
5216
    `endif
5217
    `endif
5218
 
5219
    // check statuses!
5220
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5221
    ok = 1 ;
5222
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5223
    if ( temp_val1[31] !== 1 )
5224
    begin
5225
        $display("Parity checker testing failed! Time %t ", $time) ;
5226
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5227
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5228
        ok = 0 ;
5229
    end
5230
 
5231
    if ( temp_val1[30] !== 1 )
5232
    begin
5233
        $display("Parity checker testing failed! Time %t ", $time) ;
5234
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5235
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5236
        ok = 0 ;
5237
    end
5238
 
5239
    if ( temp_val1[24] !== 0 )
5240
    begin
5241
        $display("Parity checker testing failed! Time %t ", $time) ;
5242
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5243
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5244
        ok = 0 ;
5245
    end
5246
 
5247
    if ( ok )
5248
        test_ok ;
5249
 
5250
    // clear statuses
5251
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5252
 
5253
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5254
 
5255
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5256
    ok = 1 ;
5257
 
5258
    `ifdef HOST
5259
    if ( temp_val1[4] !== 1 )
5260
    begin
5261
        $display("Parity checker testing failed! Time %t ", $time) ;
5262
        $display("System error interrupt status bit not set when expected!") ;
5263
        test_fail("System error interrupt status bit not set when expected") ;
5264
        ok = 0 ;
5265
    end
5266
    `else
5267
    if ( temp_val1[4] !== 0 )
5268
    begin
5269
        $display("Parity checker testing failed! Time %t ", $time) ;
5270
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5271
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5272
        ok = 0 ;
5273
    end
5274
    `endif
5275
 
5276
    if ( temp_val1[3] !== 0 )
5277
    begin
5278
        $display("Parity checker testing failed! Time %t ", $time) ;
5279
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5280
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5281
        ok = 0 ;
5282
    end
5283
 
5284
    if ( ok )
5285
        test_ok ;
5286
 
5287
    // clear statuses
5288
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5289
 
5290
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5291
    fork
5292
    begin
5293
        ipci_unsupported_commands_master.master_reference
5294
        (
5295
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5296
            32'h5555_5555,      // second part of address in dual address cycle
5297
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5298
            `BC_MEM_WRITE,      // normal command
5299
            4'h0,               // byte enables
5300
            32'h1234_5678,      // data
5301
            1'b0,               // make address parity error on first phase of dual address
5302
            1'b1,               // make address parity error on second phase of dual address
5303
            ok                  // result of operation
5304
        ) ;
5305 35 mihad
        if ( !perr_asserted )
5306
            disable wait_serr15 ;
5307 15 mihad
    end
5308
    begin:wait_serr15
5309
        perr_asserted = 0 ;
5310
        @(posedge pci_clock) ;
5311 35 mihad
        while( SERR !== 0 )
5312 15 mihad
            @(posedge pci_clock) ;
5313
 
5314 35 mihad
        perr_asserted = 1 ;
5315 15 mihad
    end
5316
    join
5317
 
5318
    if ( ok && perr_asserted)
5319
        test_ok ;
5320
    else
5321
    if ( !perr_asserted )
5322
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5323
 
5324
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5325
 
5326
    `ifdef HOST
5327
        repeat(4)
5328 26 mihad
            @(posedge pci_clock) ;
5329
        repeat(4)
5330 15 mihad
            @(posedge wb_clock) ;
5331
        if ( INT_O !== 1 )
5332
        begin
5333
            $display("Parity checker testing failed! Time %t ", $time) ;
5334
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5335
            test_fail("Interrupt Request was not triggered as expected") ;
5336
        end
5337
        else
5338
            test_ok ;
5339
    `else
5340
    `ifdef GUEST
5341 26 mihad
        repeat(4)
5342
            @(posedge wb_clock) ;
5343
        repeat(4)
5344 15 mihad
            @(posedge pci_clock) ;
5345
 
5346
        if ( INTA !== 1 )
5347
        begin
5348
            $display("Parity checker testing failed! Time %t ", $time) ;
5349
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5350
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5351
        end
5352
        else
5353
            test_ok ;
5354
    `endif
5355
    `endif
5356
 
5357
    // check statuses!
5358
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5359
    ok = 1 ;
5360
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5361
    if ( temp_val1[31] !== 1 )
5362
    begin
5363
        $display("Parity checker testing failed! Time %t ", $time) ;
5364
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5365
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5366
        ok = 0 ;
5367
    end
5368
 
5369
    if ( temp_val1[30] !== 1 )
5370
    begin
5371
        $display("Parity checker testing failed! Time %t ", $time) ;
5372
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5373
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5374
        ok = 0 ;
5375
    end
5376
 
5377
    if ( temp_val1[24] !== 0 )
5378
    begin
5379
        $display("Parity checker testing failed! Time %t ", $time) ;
5380
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5381
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5382
        ok = 0 ;
5383
    end
5384
 
5385
    if ( ok )
5386
        test_ok ;
5387
 
5388
    // clear statuses
5389
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5390
 
5391
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5392
 
5393
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5394
    ok = 1 ;
5395
 
5396
    `ifdef HOST
5397
    if ( temp_val1[4] !== 1 )
5398
    begin
5399
        $display("Parity checker testing failed! Time %t ", $time) ;
5400
        $display("System error interrupt status bit not set when expected!") ;
5401
        test_fail("System error interrupt status bit not set when expected") ;
5402
        ok = 0 ;
5403
    end
5404
    `else
5405
    if ( temp_val1[4] !== 0 )
5406
    begin
5407
        $display("Parity checker testing failed! Time %t ", $time) ;
5408
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5409
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5410
        ok = 0 ;
5411
    end
5412
    `endif
5413
 
5414
    if ( temp_val1[3] !== 0 )
5415
    begin
5416
        $display("Parity checker testing failed! Time %t ", $time) ;
5417
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5418
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5419
        ok = 0 ;
5420
    end
5421
 
5422
    if ( ok )
5423
        test_ok ;
5424
 
5425
    // clear statuses
5426
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5427
 
5428
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5429
    fork
5430
    begin
5431
        ipci_unsupported_commands_master.master_reference
5432
        (
5433
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5434
            32'h5555_5555,      // second part of address in dual address cycle
5435
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5436
            `BC_MEM_WRITE,      // normal command
5437
            4'h0,               // byte enables
5438
            32'h1234_5678,      // data
5439
            1'b1,               // make address parity error on first phase of dual address
5440
            1'b1,               // make address parity error on second phase of dual address
5441
            ok                  // result of operation
5442
        ) ;
5443 35 mihad
        if ( !perr_asserted )
5444
            disable wait_serr16 ;
5445 15 mihad
    end
5446
    begin:wait_serr16
5447
        perr_asserted = 0 ;
5448
        @(posedge pci_clock) ;
5449 35 mihad
        while( SERR !== 0 )
5450 15 mihad
            @(posedge pci_clock) ;
5451
 
5452 35 mihad
        perr_asserted = 1 ;
5453 15 mihad
    end
5454
    join
5455
 
5456
    if ( ok && perr_asserted)
5457
        test_ok ;
5458
    else
5459
    if ( !perr_asserted )
5460
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5461
 
5462
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5463
 
5464
    `ifdef HOST
5465
        repeat(4)
5466 26 mihad
            @(posedge pci_clock) ;
5467
        repeat(4)
5468 15 mihad
            @(posedge wb_clock) ;
5469
        if ( INT_O !== 1 )
5470
        begin
5471
            $display("Parity checker testing failed! Time %t ", $time) ;
5472
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5473
            test_fail("Interrupt Request was not triggered as expected") ;
5474
        end
5475
        else
5476
            test_ok ;
5477
    `else
5478
    `ifdef GUEST
5479 26 mihad
        repeat(4)
5480
            @(posedge wb_clock) ;
5481
        repeat(4)
5482 15 mihad
            @(posedge pci_clock) ;
5483
 
5484
        if ( INTA !== 1 )
5485
        begin
5486
            $display("Parity checker testing failed! Time %t ", $time) ;
5487
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5488
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5489
        end
5490
        else
5491
            test_ok ;
5492
    `endif
5493
    `endif
5494
 
5495
    // check statuses!
5496
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5497
    ok = 1 ;
5498
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5499
    if ( temp_val1[31] !== 1 )
5500
    begin
5501
        $display("Parity checker testing failed! Time %t ", $time) ;
5502
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5503
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5504
        ok = 0 ;
5505
    end
5506
 
5507
    if ( temp_val1[30] !== 1 )
5508
    begin
5509
        $display("Parity checker testing failed! Time %t ", $time) ;
5510
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5511
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5512
        ok = 0 ;
5513
    end
5514
 
5515
    if ( temp_val1[24] !== 0 )
5516
    begin
5517
        $display("Parity checker testing failed! Time %t ", $time) ;
5518
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5519
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5520
        ok = 0 ;
5521
    end
5522
 
5523
    if ( ok )
5524
        test_ok ;
5525
 
5526
    // clear statuses
5527
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5528
 
5529
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5530
 
5531
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5532
    ok = 1 ;
5533
 
5534
    `ifdef HOST
5535
    if ( temp_val1[4] !== 1 )
5536
    begin
5537
        $display("Parity checker testing failed! Time %t ", $time) ;
5538
        $display("System error interrupt status bit not set when expected!") ;
5539
        test_fail("System error interrupt status bit not set when expected") ;
5540
        ok = 0 ;
5541
    end
5542
    `else
5543
    if ( temp_val1[4] !== 0 )
5544
    begin
5545
        $display("Parity checker testing failed! Time %t ", $time) ;
5546
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5547
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5548
        ok = 0 ;
5549
    end
5550
    `endif
5551
 
5552
    if ( temp_val1[3] !== 0 )
5553
    begin
5554
        $display("Parity checker testing failed! Time %t ", $time) ;
5555
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5556
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5557
        ok = 0 ;
5558
    end
5559
 
5560
    if ( ok )
5561
        test_ok ;
5562
 
5563
    // clear statuses
5564
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5565
 
5566
    // now just disable Parity Error response - on Address par errors nothing should happen
5567
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5568
 
5569
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5570
    fork
5571
    begin
5572
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5573
               target_address, 32'h1234_5678,
5574
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5575
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5576
        do_pause( 1 ) ;
5577
    end
5578
    begin:wait_serr12
5579
        perr_asserted = 0 ;
5580
        @(posedge pci_clock) ;
5581
        while( SERR === 1 )
5582
            @(posedge pci_clock) ;
5583
 
5584
        perr_asserted = 1 ;
5585
        $display("Parity checker testing failed! Time %t ", $time) ;
5586
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5587
        test_fail("SERR asserted when parity error response was disabled") ;
5588
    end
5589
    begin
5590
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5591
        if ( ok !== 1 )
5592
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5593
 
5594 35 mihad
        @(posedge pci_clock) ;
5595
        #1 ;
5596
        if ( !perr_asserted )
5597
            disable wait_serr12 ;
5598 15 mihad
    end
5599
    join
5600
 
5601
    if ( ok && !perr_asserted )
5602
        test_ok ;
5603
 
5604
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5605
    `ifdef HOST
5606 26 mihad
        repeat (4)
5607
            @(posedge pci_clock) ;
5608 15 mihad
        repeat(4)
5609
            @(posedge wb_clock) ;
5610
        if ( INT_O !== 0 )
5611
        begin
5612
            $display("Parity checker testing failed! Time %t ", $time) ;
5613
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5614
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5615
        end
5616
        else
5617
            test_ok ;
5618
    `else
5619
    `ifdef GUEST
5620 26 mihad
        repeat(4)
5621
            @(posedge wb_clock) ;
5622
        repeat (4)
5623 15 mihad
            @(posedge pci_clock) ;
5624
 
5625
        if ( INTA !== 1 )
5626
        begin
5627
            $display("Parity checker testing failed! Time %t ", $time) ;
5628
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5629
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5630
        end
5631
        else
5632
            test_ok ;
5633
    `endif
5634
    `endif
5635
 
5636
    // check statuses!
5637
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5638
    ok = 1 ;
5639
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5640
    if ( temp_val1[31] !== 1 )
5641
    begin
5642
        $display("Parity checker testing failed! Time %t ", $time) ;
5643
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5644
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5645
        ok = 0 ;
5646
    end
5647
 
5648
    if ( temp_val1[30] !== 0 )
5649
    begin
5650
        $display("Parity checker testing failed! Time %t ", $time) ;
5651
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5652
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5653
        ok = 0 ;
5654
    end
5655
 
5656
    if ( temp_val1[24] !== 0 )
5657
    begin
5658
        $display("Parity checker testing failed! Time %t ", $time) ;
5659
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5660
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5661
        ok = 0 ;
5662
    end
5663
 
5664
    if ( ok )
5665
        test_ok ;
5666
 
5667
    // clear statuses
5668
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5669
 
5670
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5671
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5672
    ok = 1 ;
5673
    if ( temp_val1[4] !== 0 )
5674
    begin
5675
        $display("Parity checker testing failed! Time %t ", $time) ;
5676
        $display("System error interrupt status bit set when not expected!") ;
5677
        test_fail("System error interrupt status bit set when not expected") ;
5678
        ok = 0 ;
5679
    end
5680
 
5681
    if ( temp_val1[3] !== 0 )
5682
    begin
5683
        $display("Parity checker testing failed! Time %t ", $time) ;
5684
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5685
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5686
        ok = 0 ;
5687
    end
5688
 
5689
    if ( ok )
5690
        test_ok ;
5691
 
5692
    // clear statuses
5693
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5694
 
5695
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5696
    fork
5697
    begin
5698
        ipci_unsupported_commands_master.master_reference
5699
        (
5700
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5701
            32'h5555_5555,      // second part of address in dual address cycle
5702
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5703
            `BC_MEM_WRITE,      // normal command
5704
            4'h0,               // byte enables
5705
            32'h1234_5678,      // data
5706
            1'b1,               // make address parity error on first phase of dual address
5707
            1'b0,               // make address parity error on second phase of dual address
5708
            ok                  // result of operation
5709
        ) ;
5710 35 mihad
        if ( !perr_asserted )
5711
            disable wait_serr17 ;
5712 15 mihad
    end
5713
    begin:wait_serr17
5714
        perr_asserted = 0 ;
5715
        @(posedge pci_clock) ;
5716
        while( SERR === 1 )
5717
            @(posedge pci_clock) ;
5718
 
5719
        perr_asserted = 1 ;
5720
        $display("Parity checker testing failed! Time %t ", $time) ;
5721
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5722
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5723
    end
5724
    join
5725
 
5726
    if ( ok && !perr_asserted)
5727
        test_ok ;
5728
 
5729
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5730
    fork
5731
    begin
5732
        ipci_unsupported_commands_master.master_reference
5733
        (
5734
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5735
            32'h5555_5555,      // second part of address in dual address cycle
5736
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5737
            `BC_MEM_WRITE,      // normal command
5738
            4'h0,               // byte enables
5739
            32'h1234_5678,      // data
5740
            1'b0,               // make address parity error on first phase of dual address
5741
            1'b1,               // make address parity error on second phase of dual address
5742
            ok                  // result of operation
5743
        ) ;
5744 35 mihad
        if ( !perr_asserted )
5745
            disable wait_serr18 ;
5746 15 mihad
    end
5747
    begin:wait_serr18
5748
        perr_asserted = 0 ;
5749
        @(posedge pci_clock) ;
5750
        while( SERR === 1 )
5751
            @(posedge pci_clock) ;
5752
 
5753
        perr_asserted = 1 ;
5754
        $display("Parity checker testing failed! Time %t ", $time) ;
5755
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5756
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5757
    end
5758
    join
5759
 
5760
    if ( ok && !perr_asserted)
5761
        test_ok ;
5762
 
5763
    // check statuses!
5764
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5765
    ok = 1 ;
5766
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5767
    if ( temp_val1[31] !== 1 )
5768
    begin
5769
        $display("Parity checker testing failed! Time %t ", $time) ;
5770
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5771
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5772
        ok = 0 ;
5773
    end
5774
 
5775
    if ( temp_val1[30] !== 0 )
5776
    begin
5777
        $display("Parity checker testing failed! Time %t ", $time) ;
5778
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5779
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5780
        ok = 0 ;
5781
    end
5782
 
5783
    if ( temp_val1[24] !== 0 )
5784
    begin
5785
        $display("Parity checker testing failed! Time %t ", $time) ;
5786
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5787
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5788
        ok = 0 ;
5789
    end
5790
 
5791
    if ( ok )
5792
        test_ok ;
5793
 
5794
    // clear statuses
5795
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5796
 
5797
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5798
    fork
5799
    begin
5800
        ipci_unsupported_commands_master.master_reference
5801
        (
5802
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5803
            32'h5555_5555,      // second part of address in dual address cycle
5804
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5805
            `BC_MEM_WRITE,      // normal command
5806
            4'h0,               // byte enables
5807
            32'h1234_5678,      // data
5808
            1'b1,               // make address parity error on first phase of dual address
5809
            1'b1,               // make address parity error on second phase of dual address
5810
            ok                  // result of operation
5811
        ) ;
5812 35 mihad
        if ( !perr_asserted )
5813
            disable wait_serr19 ;
5814 15 mihad
    end
5815
    begin:wait_serr19
5816
        perr_asserted = 0 ;
5817
        @(posedge pci_clock) ;
5818
        while( SERR === 1 )
5819
            @(posedge pci_clock) ;
5820
 
5821
        perr_asserted = 1 ;
5822
        $display("Parity checker testing failed! Time %t ", $time) ;
5823
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5824
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5825
    end
5826
    join
5827
 
5828
    if ( ok && !perr_asserted)
5829
        test_ok ;
5830
 
5831
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5832
 
5833
    `ifdef HOST
5834
        repeat(4)
5835 26 mihad
            @(posedge pci_clock) ;
5836
        repeat(4)
5837 15 mihad
            @(posedge wb_clock) ;
5838
        if ( INT_O !== 0 )
5839
        begin
5840
            $display("Parity checker testing failed! Time %t ", $time) ;
5841
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5842
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5843
        end
5844
        else
5845
            test_ok ;
5846
    `else
5847
    `ifdef GUEST
5848 26 mihad
        repeat(4)
5849
            @(posedge wb_clock) ;
5850
        repeat(4)
5851 15 mihad
            @(posedge pci_clock) ;
5852
 
5853
        if ( INTA !== 1 )
5854
        begin
5855
            $display("Parity checker testing failed! Time %t ", $time) ;
5856
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5857
            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") ;
5858
        end
5859
        else
5860
            test_ok ;
5861
    `endif
5862
    `endif
5863
 
5864
    // check statuses!
5865
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5866
    ok = 1 ;
5867
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5868
    if ( temp_val1[31] !== 1 )
5869
    begin
5870
        $display("Parity checker testing failed! Time %t ", $time) ;
5871
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5872
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5873
        ok = 0 ;
5874
    end
5875
 
5876
    if ( temp_val1[30] !== 0 )
5877
    begin
5878
        $display("Parity checker testing failed! Time %t ", $time) ;
5879
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5880
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5881
        ok = 0 ;
5882
    end
5883
 
5884
    if ( temp_val1[24] !== 0 )
5885
    begin
5886
        $display("Parity checker testing failed! Time %t ", $time) ;
5887
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5888
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5889
        ok = 0 ;
5890
    end
5891
 
5892
    if ( ok )
5893
        test_ok ;
5894
 
5895
    // clear statuses
5896
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5897
 
5898
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5899
 
5900
    // do normal write
5901
    fork
5902
    begin
5903
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5904
               target_address, 32'h1234_5678, `Test_All_Bytes,
5905
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5906
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5907
        do_pause( 1 ) ;
5908
    end
5909
    begin:wait_serr13
5910
        perr_asserted = 0 ;
5911
        @(posedge pci_clock) ;
5912
        while( SERR === 1 )
5913
            @(posedge pci_clock) ;
5914
 
5915
        perr_asserted = 1 ;
5916
        $display("Parity checker testing failed! Time %t ", $time) ;
5917
        $display("SERR asserted for no reason!") ;
5918
        test_fail("SERR was asserted for no reason") ;
5919
    end
5920
    begin
5921
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5922
        if ( ok !== 1 )
5923
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5924
 
5925 35 mihad
        @(posedge pci_clock) ;
5926
        #1 ;
5927
        if ( !perr_asserted )
5928
            disable wait_serr13 ;
5929 15 mihad
    end
5930
    join
5931
 
5932
    if ( ok && !perr_asserted )
5933
        test_ok ;
5934
 
5935
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
5936
    `ifdef HOST
5937 26 mihad
        repeat( 4 )
5938
            @(posedge pci_clock) ;
5939 15 mihad
        repeat(4)
5940
            @(posedge wb_clock) ;
5941
        if ( INT_O !== 0 )
5942
        begin
5943
            $display("Parity checker testing failed! Time %t ", $time) ;
5944
            $display("Interrupt request asserted for no reason!") ;
5945
            test_fail("Interrupt request was asserted for no reason") ;
5946
        end
5947
        else
5948
            test_ok ;
5949
    `else
5950
    `ifdef GUEST
5951 26 mihad
        repeat(4)
5952
            @(posedge wb_clock) ;
5953
        repeat(4)
5954 15 mihad
            @(posedge pci_clock) ;
5955
 
5956
        if ( INTA !== 1 )
5957
        begin
5958
            $display("Parity checker testing failed! Time %t ", $time) ;
5959
            $display("Interrupt request asserted for no reason!") ;
5960
            test_fail("Interrupt request was asserted for no reason") ;
5961
        end
5962
        else
5963
            test_ok ;
5964
    `endif
5965
    `endif
5966
 
5967
    // check statuses!
5968
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5969
    ok = 1 ;
5970
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5971
    if ( temp_val1[31] !== 0 )
5972
    begin
5973
        $display("Parity checker testing failed! Time %t ", $time) ;
5974
        $display("Detected Parity Error bit was set for no reason!") ;
5975
        test_fail("Detected Parity Error bit was set for no reason") ;
5976
        ok = 0 ;
5977
    end
5978
 
5979
    if ( temp_val1[30] !== 0 )
5980
    begin
5981
        $display("Parity checker testing failed! Time %t ", $time) ;
5982
        $display("Signalled System Error bit was set for no reason!") ;
5983
        test_fail("Signalled System Error bit was set for no reason") ;
5984
        ok = 0 ;
5985
    end
5986
 
5987
    if ( temp_val1[24] !== 0 )
5988
    begin
5989
        $display("Parity checker testing failed! Time %t ", $time) ;
5990
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5991
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5992
        ok = 0 ;
5993
    end
5994
 
5995
    if ( ok )
5996
        test_ok ;
5997
 
5998
    // clear statuses
5999
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6000
 
6001
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6002
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6003
    ok = 1 ;
6004
 
6005
    if ( temp_val1[4] !== 0 )
6006
    begin
6007
        $display("Parity checker testing failed! Time %t ", $time) ;
6008
        $display("System error interrupt status bit set when not expected!") ;
6009
        test_fail("System error interrupt status bit set when not expected") ;
6010
        ok = 0 ;
6011
    end
6012
 
6013
    if ( temp_val1[3] !== 0 )
6014
    begin
6015
        $display("Parity checker testing failed! Time %t ", $time) ;
6016
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6017
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6018
        ok = 0 ;
6019
    end
6020
 
6021
    if ( ok )
6022
        test_ok ;
6023
 
6024
    // clear statuses
6025
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6026
 
6027
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6028
 
6029
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6030
 
6031
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6032
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6033
 
6034
    // setup target's image!
6035
    target_address  = Target_Base_Addr_R[1] ;
6036
 
6037
    // base address
6038
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6039
 
6040
    // address mask
6041
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6042
 
6043
    // image control
6044
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6045
 
6046
    // enable everything possible for parity checking
6047
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6048
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6049
 
6050
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6051
 
6052
    fork
6053
    begin
6054
        if ( target_mem_image === 1 )
6055
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6056
                   target_address, 32'h1234_5678,
6057
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6058
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6059
        else
6060
            PCIU_IO_WRITE_MAKE_PERR (
6061
                                    `Test_Master_1,
6062
                                    target_address,
6063
                                    32'h1234_5678,
6064
                                    4'h0,
6065
                                    1,
6066
                                    `Test_Target_Normal_Completion
6067
                                    );
6068
 
6069
        do_pause( 1 ) ;
6070
    end
6071
    begin:wait_perr11
6072
        perr_asserted = 0 ;
6073
        @(posedge pci_clock) ;
6074 35 mihad
        while ( PERR !== 0 )
6075 15 mihad
            @(posedge pci_clock) ;
6076
 
6077 35 mihad
        perr_asserted = 1 ;
6078 15 mihad
 
6079
    end
6080
    begin
6081
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6082
 
6083
        if ( ok !== 1 )
6084
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6085
 
6086
        repeat(2)
6087
            @(posedge pci_clock) ;
6088
 
6089 35 mihad
        #1 ;
6090
        if ( !perr_asserted )
6091
            disable wait_perr11 ;
6092 15 mihad
    end
6093
    join
6094
 
6095
    if ( ok && perr_asserted )
6096
        test_ok ;
6097
    else
6098
    if ( !perr_asserted )
6099
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6100
 
6101
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6102
    `ifdef HOST
6103 26 mihad
        repeat (4)
6104
            @(posedge pci_clock) ;
6105 15 mihad
        repeat(4)
6106
            @(posedge wb_clock) ;
6107
        if ( INT_O !== 0 )
6108
        begin
6109
            $display("Parity checker testing failed! Time %t ", $time) ;
6110
            $display("Interrupt request asserted for no reason!") ;
6111
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6112
        end
6113
        else
6114
            test_ok ;
6115
    `else
6116
    `ifdef GUEST
6117 26 mihad
        repeat(4)
6118
            @(posedge wb_clock) ;
6119
        repeat (4)
6120 15 mihad
            @(posedge pci_clock) ;
6121
 
6122
        if ( INTA !== 1 )
6123
        begin
6124
            $display("Parity checker testing failed! Time %t ", $time) ;
6125
            $display("Interrupt request asserted for no reason!") ;
6126
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6127
        end
6128
        else
6129
            test_ok ;
6130
 
6131
    `endif
6132
    `endif
6133
 
6134
    // check statuses!
6135
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6136
    ok = 1 ;
6137
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6138
    if ( temp_val1[31] !== 1 )
6139
    begin
6140
        $display("Parity checker testing failed! Time %t ", $time) ;
6141
        $display("Detected Parity Error bit was not set after Target detected parity error!") ;
6142
        test_fail("Detected Parity Error bit was not set after Target detected parity error") ;
6143
        ok = 0 ;
6144
    end
6145
 
6146
    if ( temp_val1[30] !== 0 )
6147
    begin
6148
        $display("Parity checker testing failed! Time %t ", $time) ;
6149
        $display("Signalled System Error bit was set for no reason!") ;
6150
        test_fail("Signalled System Error bit was set for no reason") ;
6151
        ok = 0 ;
6152
    end
6153
 
6154
    if ( temp_val1[24] !== 0 )
6155
    begin
6156
        $display("Parity checker testing failed! Time %t ", $time) ;
6157
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6158
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6159
        ok = 0 ;
6160
    end
6161
 
6162
    if ( ok )
6163
        test_ok ;
6164
 
6165
    // clear statuses
6166
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6167
 
6168
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6169
 
6170
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6171
    ok = 1 ;
6172
    if ( temp_val1[4] !== 0 )
6173
    begin
6174
        $display("Parity checker testing failed! Time %t ", $time) ;
6175
        $display("System error interrupt status bit set when not expected!") ;
6176
        test_fail("System error interrupt status bit set when not expected") ;
6177
        ok = 0 ;
6178
    end
6179
 
6180
    if ( temp_val1[3] !== 0 )
6181
    begin
6182
        $display("Parity checker testing failed! Time %t ", $time) ;
6183
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6184
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6185
        ok = 0 ;
6186
    end
6187
 
6188
    if ( ok )
6189
        test_ok ;
6190
 
6191
    // clear statuses
6192
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6193
 
6194
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6195
 
6196
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6197
    fork
6198
    begin
6199
        if ( target_mem_image === 1 )
6200
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6201
                          target_address, 32'h1234_5678,
6202
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6203
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6204
        else
6205
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6206
 
6207
        do_pause( 1 ) ;
6208
    end
6209
    begin:wait_perr12
6210
        perr_asserted = 0 ;
6211
        @(posedge pci_clock) ;
6212 35 mihad
        while ( PERR !== 0 )
6213 15 mihad
            @(posedge pci_clock) ;
6214
 
6215 35 mihad
        perr_asserted = 1 ;
6216 15 mihad
    end
6217
    begin
6218
 
6219
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6220
        if ( ok !== 1 )
6221
        begin
6222
            test_fail("Bridge failed to process Target Memory read correctly") ;
6223
            disable main ;
6224
        end
6225
 
6226
        repeat(3)
6227
            @(posedge pci_clock) ;
6228
 
6229
        if ( target_mem_image === 1 )
6230
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6231
                    target_address, 32'h1234_5678,
6232
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6233
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6234
        else
6235
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6236
 
6237
        do_pause( 1 ) ;
6238
 
6239
    end
6240
    begin
6241
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6242
        if ( ok !== 1 )
6243
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6244
        else
6245
        begin
6246
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6247
            if ( ok !== 1 )
6248
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6249
        end
6250
 
6251 35 mihad
        repeat(2)
6252 15 mihad
            @(posedge pci_clock) ;
6253
 
6254 35 mihad
        #1 ;
6255
        if ( !perr_asserted )
6256
            disable wait_perr12 ;
6257 15 mihad
    end
6258
    join
6259
 
6260
    if ( ok && perr_asserted )
6261
        test_ok ;
6262
    else
6263
    if ( !perr_asserted )
6264
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6265
 
6266
 
6267
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6268
    `ifdef HOST
6269
        repeat(4)
6270 26 mihad
            @(posedge pci_clock) ;
6271
        repeat(4)
6272 15 mihad
            @(posedge wb_clock) ;
6273
        if ( INT_O !== 0 )
6274
        begin
6275
            $display("Parity checker testing failed! Time %t ", $time) ;
6276
            $display("Interrupt request asserted for no reason!") ;
6277
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6278
        end
6279
        else
6280
            test_ok ;
6281
    `else
6282
    `ifdef GUEST
6283 26 mihad
        repeat(4)
6284
            @(posedge wb_clock) ;
6285
        repeat(4)
6286 15 mihad
            @(posedge pci_clock) ;
6287
 
6288
        if ( INTA !== 1 )
6289
        begin
6290
            $display("Parity checker testing failed! Time %t ", $time) ;
6291
            $display("Interrupt request asserted for no reason!") ;
6292
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6293
        end
6294
        else
6295
            test_ok ;
6296
    `endif
6297
    `endif
6298
 
6299
    // check statuses!
6300
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6301
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6302
    ok = 1 ;
6303
    if ( temp_val1[31] !== 1 )
6304
    begin
6305
        $display("Parity checker testing failed! Time %t ", $time) ;
6306
        $display("Detected Parity Error bit was not set after Target receive PERR asserted!") ;
6307
        test_fail("Detected Parity Error bit was not set after Target received PERR asserted on read reference") ;
6308
        ok = 0 ;
6309
    end
6310
 
6311
    if ( temp_val1[30] !== 0 )
6312
    begin
6313
        $display("Parity checker testing failed! Time %t ", $time) ;
6314
        $display("Signalled System Error bit was set for no reason!") ;
6315
        test_fail("Signalled System Error bit was set for no reason") ;
6316
        ok = 0 ;
6317
    end
6318
 
6319
    if ( temp_val1[24] !== 0 )
6320
    begin
6321
        $display("Parity checker testing failed! Time %t ", $time) ;
6322
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6323
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6324
        ok = 0 ;
6325
    end
6326
 
6327
    if ( ok )
6328
        test_ok ;
6329
 
6330
    // clear statuses
6331
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6332
 
6333
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6334
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6335
    ok = 1 ;
6336
    if ( temp_val1[4] !== 0 )
6337
    begin
6338
        $display("Parity checker testing failed! Time %t ", $time) ;
6339
        $display("System error interrupt status bit set when not expected!") ;
6340
        test_fail("System error interrupt status bit set when not expected") ;
6341
        ok = 0 ;
6342
    end
6343
 
6344
    if ( temp_val1[3] !== 0 )
6345
    begin
6346
        $display("Parity checker testing failed! Time %t ", $time) ;
6347
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6348
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6349
        ok = 0 ;
6350
    end
6351
 
6352
    if ( ok )
6353
        test_ok ;
6354
    // clear statuses
6355
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6356
 
6357
    $fdisplay(pci_mon_log_file_desc,
6358
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6359
    test_name = "DISABLE USED IMAGES" ;
6360
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6361
    if ( ok !== 1 )
6362
    begin
6363
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6364
        test_fail("WB Image Address Mask register could not be written to") ;
6365
        disable main ;
6366
    end
6367
 
6368
    config_write( p_am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6369
    if ( ok !== 1 )
6370
    begin
6371
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6372
        test_fail("PCI Image Address Mask register could not be written to") ;
6373
        disable main ;
6374
    end
6375
 
6376
    // disable target's 1 response to parity errors
6377
    configuration_cycle_write(0,             // bus number
6378
                              1,             // device number
6379
                              0,             // function number
6380
                              1,             // register number
6381
                              0,             // type of configuration cycle
6382
                              4'b0001,       // byte enables
6383
                              32'h0000_0007  // data
6384
                             ) ;
6385
 
6386
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6387
end
6388
endtask // parity_checking
6389
 
6390
task wb_to_pci_transactions ;
6391
    reg   [11:0] ctrl_offset ;
6392
    reg   [11:0] ba_offset ;
6393
    reg   [11:0] am_offset ;
6394
    reg   [11:0] pci_ctrl_offset ;
6395
    reg   [11:0] err_cs_offset ;
6396
    reg   [11:0] icr_offset ;
6397
    reg   [11:0] isr_offset ;
6398
    reg   [11:0] lat_tim_cls_offset ;
6399
 
6400
    reg `WRITE_STIM_TYPE  write_data ;
6401
    reg `READ_STIM_TYPE   read_data ;
6402
    reg `READ_RETURN_TYPE read_status ;
6403
 
6404
    reg `WRITE_RETURN_TYPE write_status ;
6405
    reg `WB_TRANSFER_FLAGS write_flags ;
6406
    reg [31:0] temp_val1 ;
6407
    reg [31:0] temp_val2 ;
6408
    reg        ok   ;
6409
 
6410
    reg [31:0] image_base ;
6411
    reg [31:0] target_address ;
6412
    integer i ;
6413
    integer required_reads ;
6414
    integer writes_left ;
6415
 
6416
begin:main
6417
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6418
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6419
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6420
    pci_ctrl_offset    = 12'h4 ;
6421
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6422
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6423
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6424
    lat_tim_cls_offset = 12'hC ;
6425
 
6426
    $display("Checking WB to PCI transaction lengths!") ;
6427
    target_address  = `BEH_TAR1_MEM_START ;
6428
    image_base      = 0 ;
6429
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6430
 
6431
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6432
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6433
    write_flags                    = 0 ;
6434
    write_flags`INIT_WAITS         = tb_init_waits ;
6435
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6436
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6437
 
6438
    // enable master & target operation
6439
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6440
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6441
    if ( ok !== 1 )
6442
    begin
6443
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6444
        test_fail("write to PCI Device Control register failed") ;
6445
        disable main ;
6446
    end
6447
 
6448
    // prepare image control register
6449
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6450
    if ( ok !== 1 )
6451
    begin
6452
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6453
        test_fail("write to WB Image Control register failed") ;
6454
        disable main ;
6455
    end
6456
 
6457
    // prepare base address register
6458
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6459
    if ( ok !== 1 )
6460
    begin
6461
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6462
        test_fail("write to WB Base Address register failed") ;
6463
        disable main ;
6464
    end
6465
 
6466
    // write address mask register
6467
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6468
    if ( ok !== 1 )
6469
    begin
6470
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6471
        test_fail("write to WB Address Mask register failed") ;
6472
        disable main ;
6473
    end
6474
 
6475
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6476
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6477
    if ( ok !== 1 )
6478
    begin
6479
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6480
        test_fail("write to WB Error Control and Status register failed") ;
6481
        disable main ;
6482
    end
6483
 
6484
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6485
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6486
    if ( ok !== 1 )
6487
    begin
6488
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6489
        test_fail("write to Interrupt Control register failed") ;
6490
        disable main ;
6491
    end
6492
 
6493
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6494
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6495
    if ( ok !== 1 )
6496
    begin
6497
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6498
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6499
        disable main ;
6500
    end
6501
 
6502
    $display("Testing single write transaction progress from WB to PCI!") ;
6503
    write_data`WRITE_ADDRESS = target_address ;
6504
    write_data`WRITE_DATA    = wmem_data[0] ;
6505
    write_data`WRITE_SEL     = 4'hF ;
6506
 
6507
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6508
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6509
 
6510
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6511
    fork
6512
    begin
6513
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6514
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6515
        begin
6516
            $display("Transaction progress testing failed! Time %t ", $time) ;
6517
            $display("Bridge failed to process single memory write!") ;
6518
            test_fail("bridge failed to post single memory write") ;
6519
            disable main ;
6520
        end
6521
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6522
    end
6523
    begin
6524
        // wait two retries, then enable target response
6525
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6526
        if ( ok !== 1 )
6527
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6528
        else
6529
            test_ok ;
6530
 
6531
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6532
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6533
        if ( ok !== 1 )
6534
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6535
        else
6536
            test_ok ;
6537
 
6538
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6539
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6540
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6541
 
6542
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6543
        if ( ok !== 1 )
6544
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6545
        else
6546
            test_ok ;
6547
    end
6548
    join
6549
 
6550
    $display("Testing burst write transaction progress from WB to PCI!") ;
6551
    write_data`WRITE_ADDRESS = target_address ;
6552
    write_data`WRITE_DATA    = wmem_data[0] ;
6553
    write_data`WRITE_SEL     = 4'hF ;
6554
 
6555
    wishbone_master.blk_write_data[0] = write_data ;
6556
 
6557
    write_data`WRITE_ADDRESS = target_address + 4 ;
6558
    write_data`WRITE_DATA    = wmem_data[1] ;
6559
    write_data`WRITE_SEL     = 4'hF ;
6560
 
6561
    wishbone_master.blk_write_data[1] = write_data ;
6562
 
6563
    write_flags`WB_TRANSFER_SIZE = 2 ;
6564
    write_flags`WB_TRANSFER_CAB  = 1 ;
6565
 
6566
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6567
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6568
 
6569
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6570
 
6571
    fork
6572
    begin
6573
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6574
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6575
        begin
6576
            $display("Transaction progress testing failed! Time %t ", $time) ;
6577
            $display("Bridge failed to process whole CAB memory write!") ;
6578
            test_fail("bridge failed to post whole CAB memory write") ;
6579
            disable main ;
6580
        end
6581
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6582
    end
6583
    begin
6584
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6585
        if ( ok !== 1 )
6586
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6587
        else
6588
            test_ok ;
6589
 
6590
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6591
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6592
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6593
 
6594
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6595
        if ( ok !== 1 )
6596
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6597
        else
6598
            test_ok ;
6599
 
6600
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6601
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6602
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6603
 
6604
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6605
        if ( ok !== 1 )
6606
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6607
        else
6608
            test_ok ;
6609
    end
6610
    join
6611
 
6612
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6613
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6614
 
6615
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6616
    // try same write with other terminations
6617
    fork
6618
    begin
6619
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6620
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6621
        begin
6622
            $display("Transaction progress testing failed! Time %t ", $time) ;
6623
            $display("Bridge failed to process whole CAB memory write!") ;
6624
            test_fail("bridge failed to post whole CAB memory write") ;
6625
            disable main ;
6626
        end
6627
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6628
    end
6629
    begin
6630
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6631
        if ( ok !== 1 )
6632
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6633
        else
6634
            test_ok ;
6635
 
6636
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6637
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6638
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6639
 
6640
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6641
        if ( ok !== 1 )
6642
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6643
        else
6644
            test_ok ;
6645
    end
6646
    join
6647
 
6648
    // repeat the write with normal completion
6649
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6650
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6651
 
6652
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6653
    fork
6654
    begin
6655
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6656
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6657
        begin
6658
            $display("Transaction progress testing failed! Time %t ", $time) ;
6659
            $display("Bridge failed to process whole CAB memory write!") ;
6660
            test_fail("bridge failed to post whole CAB memory write") ;
6661
            disable main ;
6662
        end
6663
    end
6664
    begin
6665
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6666
        if ( ok !== 1 )
6667
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6668
        else
6669
            test_ok ;
6670
    end
6671
    join
6672
 
6673
    // do the same thing with burst length of 3
6674
    write_data`WRITE_ADDRESS = target_address + 8 ;
6675
    write_data`WRITE_DATA    = wmem_data[2] ;
6676
    write_data`WRITE_SEL     = 4'hF ;
6677
 
6678
    wishbone_master.blk_write_data[2] = write_data ;
6679
 
6680
    write_flags`WB_TRANSFER_SIZE = 3 ;
6681
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6682
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6683
 
6684
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6685
 
6686
    fork
6687
    begin
6688
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6689
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6690
        begin
6691
            $display("Transaction progress testing failed! Time %t ", $time) ;
6692
            $display("Bridge failed to process whole CAB memory write!") ;
6693
            test_fail("bridge failed to post whole CAB memory write") ;
6694
            disable main ;
6695
        end
6696
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6697
    end
6698
    begin
6699
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6700
        if ( ok !== 1 )
6701
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6702
        else
6703
            test_ok ;
6704
 
6705
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6706
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6707
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6708
 
6709
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6710
        if ( ok !== 1 )
6711
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6712
        else
6713
            test_ok ;
6714
    end
6715
    join
6716
 
6717
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6718
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6719
 
6720
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6721
    fork
6722
    begin
6723
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6724
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6725
        begin
6726
            $display("Transaction progress testing failed! Time %t ", $time) ;
6727
            $display("Bridge failed to process whole CAB memory write!") ;
6728
            test_fail("bridge failed to post whole CAB memory write") ;
6729
            disable main ;
6730
        end
6731
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6732
    end
6733
    begin
6734
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6735
        if ( ok !== 1 )
6736
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6737
        else
6738
            test_ok ;
6739
 
6740
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6741
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6742
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6743
 
6744
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6745
        if ( ok !== 1 )
6746
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6747
        else
6748
            test_ok ;
6749
 
6750
    end
6751
    join
6752
 
6753
    // repeat with normal completion
6754
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6755
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6756
 
6757
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6758
    fork
6759
    begin
6760
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6761
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6762
        begin
6763
            $display("Transaction progress testing failed! Time %t ", $time) ;
6764
            $display("Bridge failed to process whole CAB memory write!") ;
6765
            test_fail("bridge failed to post whole CAB memory write") ;
6766
            disable main ;
6767
        end
6768
    end
6769
    begin
6770
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6771
        if ( ok !== 1 )
6772
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6773
        else
6774
            test_ok ;
6775
 
6776
    end
6777
    join
6778
 
6779
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6780
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6781
    begin
6782
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6783
        write_data`WRITE_DATA    = wmem_data[i] ;
6784
        write_data`WRITE_SEL     = 4'hF ;
6785
 
6786
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6787
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6788
 
6789
        wishbone_master.blk_write_data[i]   = write_data ;
6790
        wishbone_master.blk_read_data_in[i] = read_data ;
6791
    end
6792
 
6793
    write_flags`WB_TRANSFER_CAB      = 1 ;
6794
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6795
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6796
 
6797
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6798
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6799
 
6800
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6801
    fork
6802
    begin
6803
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6804
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6805
        begin
6806
            $display("Transaction progress testing failed! Time %t ", $time) ;
6807
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6808
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6809
            test_fail("bridge failed to post whole CAB memory write") ;
6810
            disable main ;
6811
        end
6812
 
6813
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6814
 
6815
        // read here just checks if data was transfered OK
6816
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6817
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6818
 
6819
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6820
 
6821
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6822
        begin
6823
            $display("Transaction progress testing failed! Time %t ", $time) ;
6824
            $display("Bridge processed CAB read wrong!") ;
6825
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6826
        end
6827
 
6828
    end
6829
    begin
6830
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6831
        if ( ok !== 1 )
6832
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6833
        else
6834
            test_ok ;
6835
 
6836
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6837
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6838
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6839
 
6840
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6841
        if ( ok !== 1 )
6842
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6843
        else
6844
            test_ok ;
6845
 
6846
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6847
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6848
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6849
 
6850
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6851
        if ( ok !== 1 )
6852
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6853
        else
6854
            test_ok ;
6855
 
6856
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6857
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6858
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6859
 
6860
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6861
        if ( ok !== 1 )
6862
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6863
        else
6864
            test_ok ;
6865
 
6866
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6867
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6868
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6869
 
6870
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6871
        if ( ok !== 1 )
6872
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6873
        else
6874
            test_ok ;
6875
 
6876
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6877
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6878
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6879
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6880
        begin
6881
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6882
            if ( ok !== 1 )
6883
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6884
        end
6885
    end
6886
    join
6887
 
6888
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6889
    begin
6890
        read_status = wishbone_master.blk_read_data_out[i] ;
6891
        if (read_status`READ_DATA !== wmem_data[i])
6892
        begin
6893
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6894
            test_fail("data read from target wasn't the same as data written to it") ;
6895
            ok = 0 ;
6896
        end
6897
    end
6898
 
6899
    if ( ok )
6900
        test_ok ;
6901
 
6902
    $display("Testing single read transaction progress from WB to PCI!") ;
6903
    read_data`READ_ADDRESS = target_address + 8 ;
6904
    read_data`READ_SEL     = 4'hF ;
6905
 
6906
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6907
 
6908
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6909
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6910
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6911
 
6912
    fork
6913
    begin
6914
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6915
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6916
        begin
6917
            $display("Transaction progress testing failed! Time %t ", $time) ;
6918
            $display("Bridge processed single read wrong!") ;
6919
            test_fail("bridge processed single read wrong") ;
6920
            disable main ;
6921
        end
6922
 
6923
        if (read_status`READ_DATA !== wmem_data[2])
6924
        begin
6925
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6926
            test_fail("data returned from single read was not as expected") ;
6927
        end
6928
        else
6929
        if ( ok )
6930
            test_ok ;
6931
    end
6932
    begin
6933
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
6934
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6935
 
6936
        if ( ok !== 1 )
6937
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6938
 
6939
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
6940
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6941
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6942
 
6943
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6944
        if ( ok !== 1 )
6945
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6946
    end
6947
    join
6948
 
6949
    $display("Testing CAB read transaction progress from WB to PCI!") ;
6950
 
6951
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6952
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6953
 
6954
    test_name = "FILL TARGET MEMORY WITH DATA" ;
6955
    // first fill target's memory with enough data to fill WBR_FIFO
6956
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
6957
    begin
6958
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6959
        write_data`WRITE_DATA    = wmem_data[i] ;
6960
        write_data`WRITE_SEL     = 4'hF ;
6961
 
6962
        wishbone_master.blk_write_data[i] = write_data ;
6963
    end
6964
 
6965
    write_flags`WB_TRANSFER_CAB = 1 ;
6966
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6967
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
6968
 
6969
    wishbone_master.wb_block_write( write_flags, write_status ) ;
6970
 
6971
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
6972
    begin
6973
        $display("Transaction progress testing failed! Time %t ", $time) ;
6974
        $display("Bridge processed CAB write wrong!") ;
6975
        test_fail("bridge didn't process all the writes as it was supposed too") ;
6976
        disable main ;
6977
    end
6978
 
6979
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
6980
    // perform single read to force write data to pci
6981
    read_data`READ_ADDRESS = target_address + 8;
6982
    read_data`READ_SEL     = 4'hF ;
6983
 
6984
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6985
 
6986
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6987
    begin
6988
        $display("Transaction progress testing failed! Time %t ", $time) ;
6989
        $display("Bridge processed single read wrong!") ;
6990
        test_fail("bridge didn't process single memory read as expected") ;
6991
        disable main ;
6992
    end
6993
 
6994
    wishbone_master.blk_read_data_in[0] = read_data ;
6995
 
6996
    read_data`READ_ADDRESS = target_address + 12 ;
6997
    read_data`READ_SEL     = 4'hF ;
6998
 
6999
    wishbone_master.blk_read_data_in[1] = read_data ;
7000
 
7001
    read_data`READ_ADDRESS = target_address + 16 ;
7002
    read_data`READ_SEL     = 4'hF ;
7003
 
7004
    wishbone_master.blk_read_data_in[2] = read_data ;
7005
 
7006
    write_flags`WB_TRANSFER_CAB  = 1 ;
7007
    write_flags`WB_TRANSFER_SIZE = 2 ;
7008
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7009
    read_status = 0 ;
7010
 
7011
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7012
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7013
 
7014
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7015
 
7016
    ok = 1 ;
7017
    fork
7018
    begin
7019
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7020
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7021
 
7022
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7023
        begin
7024
            $display("Transaction progress testing failed! Time %t ", $time) ;
7025
            $display("Bridge processed CAB read wrong!") ;
7026
            test_fail("bridge didn't process disconnected burst read as expected") ;
7027
        end
7028
        else
7029
        begin
7030
 
7031
            read_status = wishbone_master.blk_read_data_out[0] ;
7032
 
7033
            if (read_status`READ_DATA !== wmem_data[2])
7034
            begin
7035
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7036
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7037
            end
7038
            else
7039
                test_ok ;
7040
        end
7041
 
7042
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7043
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7044
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7045
 
7046
        read_status = 0 ;
7047
 
7048
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7049
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7050
 
7051
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7052
        begin
7053
            $display("Transaction progress testing failed! Time %t ", $time) ;
7054
            $display("Bridge processed CAB read wrong!") ;
7055
            test_fail("bridge didn't process disconnected burst read as expected") ;
7056
        end
7057
        else
7058
        begin
7059
 
7060
            read_status = wishbone_master.blk_read_data_out[0] ;
7061
 
7062
            if (read_status`READ_DATA !== wmem_data[3])
7063
            begin
7064
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7065
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7066
            end
7067
            else
7068
                test_ok ;
7069
        end
7070
 
7071
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7072
        // complete delayed read which was requested
7073
        read_data = wishbone_master.blk_read_data_in[2] ;
7074
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7075
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7076
 
7077
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7078
        begin
7079
            $display("Transaction progress testing failed! Time %t ", $time) ;
7080
            $display("Bridge processed single out of burst read wrong!") ;
7081
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7082
        end
7083
        else
7084
        begin
7085
 
7086
            if (read_status`READ_DATA !== wmem_data[4])
7087
            begin
7088
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7089
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7090
            end
7091
            else
7092
                test_ok ;
7093
        end
7094
 
7095
    end
7096
    begin
7097
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7098
 
7099
        if ( ok !== 1 )
7100
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7101
 
7102
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7103
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7104
 
7105
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7106
        if ( ok !== 1 )
7107
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7108
 
7109
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7110
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7111
 
7112
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7113
        if ( ok !== 1 )
7114
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7115
    end
7116
    join
7117
 
7118
    // now try burst read with normal termination
7119
    read_data`READ_ADDRESS = target_address + 12 ;
7120
    read_data`READ_SEL     = 4'hF ;
7121
 
7122
    wishbone_master.blk_read_data_in[0] = read_data ;
7123
 
7124
    read_data`READ_ADDRESS = target_address + 16 ;
7125
    read_data`READ_SEL     = 4'hF ;
7126
 
7127
    wishbone_master.blk_read_data_in[1] = read_data ;
7128
 
7129
    write_flags`WB_TRANSFER_SIZE = 2 ;
7130
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7131
    write_flags`WB_TRANSFER_CAB = 1 ;
7132
 
7133
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7134
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7135
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7136
 
7137
    fork
7138
    begin
7139
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7140
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7141
        begin
7142
            $display("Transaction progress testing failed! Time %t ", $time) ;
7143
            $display("Bridge processed CAB read wrong!") ;
7144
            test_fail("bridge didn't process burst read as expected") ;
7145
            ok = 0 ;
7146
        end
7147
    end
7148
    begin
7149
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7150
        if ( ok !== 1 )
7151
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7152
    end
7153
    join
7154
 
7155
    if ( ok )
7156
    begin
7157
        read_status = wishbone_master.blk_read_data_out[0] ;
7158
        if ( read_status`READ_DATA !== wmem_data[3] )
7159
        begin
7160
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7161
            test_fail("data provided from normaly terminated read was wrong") ;
7162
            ok = 0 ;
7163
        end
7164
 
7165
        read_status = wishbone_master.blk_read_data_out[1] ;
7166
        if ( read_status`READ_DATA !== wmem_data[4] )
7167
        begin
7168
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7169
            test_fail("data provided from normaly terminated read was wrong") ;
7170
            ok = 0 ;
7171
        end
7172
    end
7173
 
7174
    if ( ok )
7175
        test_ok ;
7176
 
7177
    // disable memory read line command and enable prefetch
7178
    // prepare image control register
7179
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7180
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7181
    if ( ok !== 1 )
7182
    begin
7183
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7184
        test_fail("WB Image Control register couldn't be written to") ;
7185
        disable main ;
7186
    end
7187
 
7188
    write_flags`WB_TRANSFER_SIZE = 4 ;
7189
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7190
    write_flags`WB_TRANSFER_CAB = 1 ;
7191
 
7192
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7193
 
7194
    for ( i = 0 ; i < 4 ; i = i + 1 )
7195
    begin
7196
        read_data`READ_ADDRESS = target_address + i*4 ;
7197
        read_data`READ_SEL     = 4'b1010 ;
7198
 
7199
        wishbone_master.blk_read_data_in[i] = read_data ;
7200
    end
7201
 
7202
    fork
7203
    begin
7204
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7205
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7206
        begin
7207
            $display("Transaction progress testing failed! Time %t ", $time) ;
7208
            $display("Bridge processed CAB read wrong!") ;
7209
            test_fail("bridge didn't process prefetched burst read as expected") ;
7210
            ok = 0 ;
7211
        end
7212
    end
7213
    begin
7214
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7215
        if ( ok !== 1 )
7216
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7217
    end
7218
    join
7219
 
7220
    if ( ok )
7221
    begin
7222
        for ( i = 0 ; i < 4 ; i = i + 1 )
7223
        begin
7224
            read_status = wishbone_master.blk_read_data_out[i] ;
7225
            if ( read_status`READ_DATA !== wmem_data[i] )
7226
            begin
7227
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7228
                test_fail("burst read returned unexpected data") ;
7229
                ok = 0 ;
7230
            end
7231
        end
7232
    end
7233
 
7234
    if ( ok )
7235
        test_ok ;
7236
 
7237
    // do one single read with different byte enables
7238
    read_data`READ_ADDRESS = target_address + 4 ;
7239
    read_data`READ_SEL     = 4'b1010 ;
7240
 
7241
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7242
    fork
7243
    begin
7244
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7245
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7246
        begin
7247
            $display("Transaction progress testing failed! Time %t ", $time) ;
7248
            $display("Bridge processed single read wrong!") ;
7249
            test_fail("bridge didn't process single memory read as expected") ;
7250
            ok = 0 ;
7251
        end
7252
    end
7253
    begin
7254
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7255
        if ( ok !== 1 )
7256
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7257
    end
7258
    join
7259
 
7260
    // check read data
7261
    if ( ok )
7262
    begin
7263
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7264
        begin
7265
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7266
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7267
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7268
            ok = 0 ;
7269
            test_fail("unexpected data received from single read") ;
7270
        end
7271
    end
7272
 
7273
    if ( ok )
7274
         test_ok ;
7275
 
7276
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7277
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7278
 
7279
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7280
    if ( ok !== 1 )
7281
    begin
7282
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7283
        test_fail("WB Image Control register could not be written") ;
7284
        disable main ;
7285
    end
7286
 
7287
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7288
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7289
    begin
7290
        read_data`READ_ADDRESS = target_address + i*4 ;
7291
        read_data`READ_SEL     = 4'b1111 ;
7292
 
7293
        wishbone_master.blk_read_data_in[i] = read_data ;
7294
    end
7295
 
7296
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7297
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7298
    write_flags`WB_TRANSFER_CAB = 1 ;
7299
 
7300
    fork
7301
    begin
7302
        read_status         = 0 ;
7303
        read_status`CYC_RTY = 1 ;
7304
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7305
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7306
 
7307
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7308
        begin
7309
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7310
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7311
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7312
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7313
            ok = 0 ;
7314
        end
7315
    end
7316
    begin
7317
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7318
        if ( ok !== 1 )
7319
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7320
    end
7321
    join
7322
 
7323
    // now repeat single read to flush redundant read initiated
7324
    write_flags`WB_TRANSFER_SIZE = 1 ;
7325
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7326
    write_flags`WB_TRANSFER_CAB = 1 ;
7327
 
7328
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7329
    read_data`READ_SEL     = 4'hF ;
7330
 
7331
    wishbone_master.blk_read_data_in[0] = read_data ;
7332
 
7333
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7334
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7335
 
7336
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7337
    begin
7338
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7339
        $display(" PCI bridge failed to process single CAB read!") ;
7340
        test_fail("single CAB write was not processed as expected") ;
7341
    end
7342
 
7343
    // because last read could be very long on PCI - delete target abort status
7344
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7345
 
7346
    // write unsupported value to cache line size register
7347
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7348
 
7349
    read_data`READ_ADDRESS = target_address ;
7350
    read_data`READ_SEL     = 4'hF ;
7351
    wishbone_master.blk_read_data_in[0] = read_data ;
7352
 
7353
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7354
    // perform a read
7355
    fork
7356
    begin
7357
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7358
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7359
        begin
7360
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7361
            $display(" PCI bridge failed to process single CAB read!") ;
7362
            test_fail("burst read was not processed as expected") ;
7363
            ok = 0 ;
7364
        end
7365
    end
7366
    begin
7367
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7368
        if ( ok !== 1 )
7369
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7370
    end
7371
    join
7372
 
7373
    if ( ok )
7374
        test_ok ;
7375
 
7376
    // write 2 to cache line size register
7377
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7378
 
7379
    // perform a read
7380
    fork
7381
    begin
7382
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7383
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7384
        begin
7385
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7386
            $display(" PCI bridge failed to process single CAB read!") ;
7387
            test_fail("burst read was not processed as expected") ;
7388
            ok = 0 ;
7389
        end
7390
    end
7391
    begin
7392
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7393
        if ( ok !== 1 )
7394
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7395
    end
7396
    join
7397
 
7398
    if ( ok )
7399
        test_ok ;
7400
 
7401
    // write 0 to cache line size
7402
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7403
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7404
 
7405
    // perform a read
7406
    fork
7407
    begin
7408
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7409
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7410
        begin
7411
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7412
            $display(" PCI bridge failed to process single CAB read!") ;
7413
            test_fail("burst read was not processed as expected") ;
7414
            ok = 0 ;
7415
        end
7416
    end
7417
    begin
7418
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7419
        if ( ok !== 1 )
7420
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7421
    end
7422
    join
7423
 
7424
    if ( ok )
7425
        test_ok ;
7426
 
7427
    // write normal value to cls register
7428
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7429
 
7430
    $display("Testing Master's latency timer operation!") ;
7431
    $display("Testing Latency timer during Master Writes!") ;
7432
 
7433
    for ( i = 0 ; i < 6 ; i = i + 1 )
7434
    begin
7435
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7436
        write_data`WRITE_SEL     = 4'b1111 ;
7437
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7438
 
7439
        wishbone_master.blk_write_data[i] = write_data ;
7440
    end
7441
 
7442
    write_flags`WB_TRANSFER_SIZE = 6 ;
7443
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7444
    write_flags`WB_TRANSFER_CAB = 1 ;
7445
 
7446
    // start wb write, pci write and monitor in parallel
7447
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7448
    fork
7449
    begin
7450
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7451
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7452
        begin
7453
            $display("Transaction progress testing failed! Time %t ", $time) ;
7454
            $display("Bridge failed to process CAB write!") ;
7455
            test_fail("bridge didn't post whole burst memory write") ;
7456
            disable main ;
7457
        end
7458
    end
7459
    begin
7460
        // wait for bridge's master to start transaction
7461
        @(posedge pci_clock) ;
7462
        while ( FRAME === 1 )
7463
            @(posedge pci_clock) ;
7464
 
7465
        // start behavioral master request
7466
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7467
               target_address, wmem_data[1023], `Test_All_Bytes,
7468
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7469
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7470
 
7471
        do_pause ( 1 ) ;
7472
    end
7473
    begin
7474
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7475
        if ( ok !== 1 )
7476
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7477
        else
7478
            test_ok ;
7479
    end
7480
    join
7481
 
7482
    // perform a read to check data
7483
    for ( i = 0 ; i < 6 ; i = i + 1 )
7484
    begin
7485
        read_data`READ_ADDRESS = target_address + i*4 ;
7486
        read_data`READ_SEL     = 4'b1111 ;
7487
 
7488
        wishbone_master.blk_read_data_in[i] = read_data ;
7489
    end
7490
 
7491
    write_flags`WB_TRANSFER_SIZE = 6 ;
7492
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7493
    write_flags`WB_TRANSFER_CAB = 1 ;
7494
 
7495
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7496
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7497
 
7498
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7499
    begin
7500
        $display("Transaction progress testing failed! Time %t ", $time) ;
7501
        $display("Bridge failed to process CAB read!") ;
7502
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7503
        disable main ;
7504
    end
7505
 
7506
    ok = 1 ;
7507
    for ( i = 0 ; i < 6 ; i = i + 1 )
7508
    begin
7509
        read_status = wishbone_master.blk_read_data_out[i] ;
7510
 
7511
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7512
        begin
7513
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7514
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7515
            test_fail("unexpected data read back from PCI") ;
7516
            ok = 0 ;
7517
        end
7518
    end
7519
 
7520
    if ( ok )
7521
        test_ok ;
7522
 
7523
    $display("Testing Latency timer during Master Reads!") ;
7524
 
7525
    // at least 2 words are transfered during Master Reads terminated with timeout
7526
    write_flags`WB_TRANSFER_SIZE = 2 ;
7527
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7528
    fork
7529
    begin
7530
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7531
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7532
        begin
7533
            $display("Transaction progress testing failed! Time %t ", $time) ;
7534
            $display("Bridge failed to process CAB read!") ;
7535
            test_fail("bridge didn't process burst read as expected") ;
7536
            ok = 0 ;
7537
        end
7538
    end
7539
    begin
7540
        // wait for bridge's master to start transaction
7541
        @(posedge pci_clock) ;
7542
        while ( FRAME === 1 )
7543
            @(posedge pci_clock) ;
7544
 
7545
        // start behavioral master request
7546
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7547
               target_address, wmem_data[0], `Test_All_Bytes,
7548
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7549
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7550
 
7551
        do_pause ( 1 ) ;
7552
    end
7553
    begin
7554
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7555
        if ( ok !== 1 )
7556
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7557
    end
7558
    join
7559
 
7560
    // check data provided by target
7561
    if ( ok )
7562
    begin
7563
        for ( i = 0 ; i < 2 ; i = i + 1 )
7564
        begin
7565
            read_status = wishbone_master.blk_read_data_out[i] ;
7566
 
7567
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7568
            begin
7569
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7570
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7571
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7572
                ok = 0 ;
7573
            end
7574
        end
7575
    end
7576
    if ( ok )
7577
        test_ok ;
7578
 
7579
    test_name = "DISABLE_IMAGE" ;
7580
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7581
    if ( ok !== 1 )
7582
    begin
7583
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7584
        test_fail("write to WB Address Mask register failed") ;
7585
        disable main ;
7586
    end
7587
 
7588
end
7589
endtask //wb_to_pci_transactions
7590
 
7591
task iack_cycle ;
7592
    reg `READ_STIM_TYPE   read_data ;
7593
    reg `READ_RETURN_TYPE read_status ;
7594
    reg `WB_TRANSFER_FLAGS flags ;
7595
 
7596
    reg [31:0] temp_var ;
7597
    reg ok ;
7598
begin
7599
 
7600
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7601
 
7602
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7603
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7604
 
7605
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7606
    read_data`READ_SEL     = 4'hF ;
7607
 
7608
    flags = 0 ;
7609
 
7610
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7611
 
7612
    irq_respond = 0 ;
7613
    irq_vector  = 32'hAAAA_AAAA ;
7614
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7615
 
7616
    fork
7617
    begin
7618
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7619
    end
7620
    begin
7621
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok) ;
7622
        if ( ok !== 1 )
7623
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7624
    end
7625
    join
7626
 
7627
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7628
    begin
7629
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7630
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7631
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7632
    end
7633
    else
7634
    if ( ok )
7635
        test_ok ;
7636
        // clearing the status bits
7637
        config_write(12'h4, 32'hFFFF_0000, 4'hC, ok);
7638
 
7639
    irq_respond = 1 ;
7640
    irq_vector  = 32'h5555_5555 ;
7641
 
7642
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7643
    fork
7644
    begin
7645
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7646
    end
7647
    begin
7648
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7649
        if ( ok !== 1 )
7650
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7651
    end
7652
    join
7653
 
7654
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7655
    begin
7656
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7657
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7658
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7659
        ok = 0 ;
7660
    end
7661
 
7662
    if ( read_status`READ_DATA !== irq_vector )
7663
    begin
7664
        $display(" Time %t ", $time ) ;
7665
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7666
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7667
        ok = 0 ;
7668
    end
7669
 
7670
    if ( ok )
7671
        test_ok ;
7672
 
7673
    read_data`READ_SEL = 4'b0101 ;
7674
    irq_vector  = 32'hAAAA_AAAA ;
7675
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7676
    fork
7677
    begin
7678
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7679
    end
7680
    begin
7681
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7682
        if ( ok !== 1 )
7683
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7684
    end
7685
    join
7686
 
7687
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7688
    begin
7689
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7690
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7691
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7692
        ok = 0 ;
7693
    end
7694
 
7695
    if ( read_status`READ_DATA !== 32'h00AA_00AA )
7696
    begin
7697
        $display(" Time %t ", $time ) ;
7698
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h00AA_00AA, read_status`READ_DATA ) ;
7699
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7700
        ok = 0 ;
7701
    end
7702
 
7703
    if ( ok )
7704
        test_ok ;
7705
 
7706
 
7707
end
7708
endtask //iack_cycle
7709
 
7710
task transaction_ordering ;
7711
    reg   [11:0] wb_ctrl_offset ;
7712
    reg   [11:0] wb_ba_offset ;
7713
    reg   [11:0] wb_am_offset ;
7714
    reg   [11:0] pci_ctrl_offset ;
7715
    reg   [11:0] pci_ba_offset ;
7716
    reg   [11:0] pci_am_offset ;
7717
    reg   [11:0] pci_device_ctrl_offset ;
7718
    reg   [11:0] wb_err_cs_offset ;
7719
    reg   [11:0] pci_err_cs_offset ;
7720
    reg   [11:0] icr_offset ;
7721
    reg   [11:0] isr_offset ;
7722
    reg   [11:0] lat_tim_cls_offset ;
7723
 
7724
    reg `WRITE_STIM_TYPE  write_data ;
7725
    reg `READ_STIM_TYPE   read_data ;
7726
    reg `READ_RETURN_TYPE read_status ;
7727
 
7728
    reg `WRITE_RETURN_TYPE write_status ;
7729
    reg `WB_TRANSFER_FLAGS write_flags ;
7730
    reg [31:0] temp_val1 ;
7731
    reg [31:0] temp_val2 ;
7732
    reg        ok   ;
7733
 
7734
    reg [31:0] wb_image_base ;
7735
    reg [31:0] wb_target_address ;
7736
    reg [31:0] pci_image_base ;
7737
    integer i ;
7738
 
7739
    reg     error_monitor_done ;
7740
begin:main
7741
    write_flags`INIT_WAITS = tb_init_waits ;
7742
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7743
 
7744
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7745
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7746
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7747
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7748
 
7749
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7750
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7751
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7752
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7753
 
7754
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7755
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7756
    lat_tim_cls_offset = 12'hC ;
7757
    pci_device_ctrl_offset    = 12'h4 ;
7758
 
7759
    wb_target_address  = `BEH_TAR1_MEM_START ;
7760
    wb_image_base      = 0 ;
7761
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7762
 
7763
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7764
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7765
    write_flags                    = 0 ;
7766
    write_flags`INIT_WAITS         = 0 ;
7767
    write_flags`SUBSEQ_WAITS       = 0 ;
7768
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7769
 
7770
    pci_image_base = Target_Base_Addr_R[1] ;
7771
 
7772
    // enable master & target operation
7773
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7774
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7775
    if ( ok !== 1 )
7776
    begin
7777
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7778
        test_fail("write to PCI Device Control register failed") ;
7779
        disable main ;
7780
    end
7781
 
7782
    // prepare image control register
7783
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7784
    if ( ok !== 1 )
7785
    begin
7786
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7787
        test_fail("write to WB Image Control register failed") ;
7788
        disable main ;
7789
    end
7790
 
7791
    // prepare base address register
7792
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7793
    if ( ok !== 1 )
7794
    begin
7795
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7796
        test_fail("write to WB Base Address register failed") ;
7797
        disable main ;
7798
    end
7799
 
7800
    // write address mask register
7801
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7802
    if ( ok !== 1 )
7803
    begin
7804
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7805
        test_fail("write to WB Address Mask register failed") ;
7806
        disable main ;
7807
    end
7808
 
7809
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7810
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7811
    if ( ok !== 1 )
7812
    begin
7813
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
7814
        test_fail("write to WB Error Control and Status register failed") ;
7815
        disable main ;
7816
    end
7817
 
7818
    // prepare image control register
7819
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7820
    if ( ok !== 1 )
7821
    begin
7822
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
7823
        test_fail("write to PCI Image Control register failed") ;
7824
        disable main ;
7825
    end
7826
 
7827
    // prepare base address register
7828
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
7829
    if ( ok !== 1 )
7830
    begin
7831
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
7832
        test_fail("write to PCI Base Address register failed") ;
7833
        disable main ;
7834
    end
7835
 
7836
    // write address mask register
7837
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7838
    if ( ok !== 1 )
7839
    begin
7840
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
7841
        test_fail("write to PCI Address Mask register failed") ;
7842
        disable main ;
7843
    end
7844
 
7845
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7846
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7847
    if ( ok !== 1 )
7848
    begin
7849
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
7850
        test_fail("write to PCI Error Control and Status register failed") ;
7851
        disable main ;
7852
    end
7853
 
7854
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
7855
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7856
    if ( ok !== 1 )
7857
    begin
7858
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
7859
        test_fail("write to Interrupt Control register failed") ;
7860
        disable main ;
7861
    end
7862
 
7863
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
7864
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
7865
    if ( ok !== 1 )
7866
    begin
7867
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
7868
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
7869
        disable main ;
7870
    end
7871
 
7872
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
7873
 
7874
    // prepare wb_master write and read data
7875
    for ( i = 0 ; i < 4 ; i = i + 1 )
7876
    begin
7877
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
7878
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
7879
        write_data`WRITE_SEL     = 4'hF ;
7880
 
7881
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
7882
        read_data`READ_SEL       = write_data`WRITE_SEL ;
7883
 
7884
        wishbone_master.blk_write_data[i]   = write_data ;
7885
        wishbone_master.blk_read_data_in[i] = read_data ;
7886
    end
7887
 
7888
    // put wishbone slave in acknowledge and pci target in retry mode
7889
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
7890
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7891
 
7892
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7893
 
7894
    fork
7895
    begin
7896
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7897
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7898
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7899
        begin
7900
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7901
            test_fail("Bridge didn't post single memory write as expected") ;
7902
        end
7903
 
7904
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7905
        if ( ok !== 1 )
7906
        begin
7907
            $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) ;
7908
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7909
            ok = 0 ;
7910
        end
7911
 
7912
        // now post single write to target - normal progress
7913
        if ( target_mem_image == 1 )
7914
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7915
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7916
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7917
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7918
        else
7919
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7920
 
7921
        do_pause( 1 ) ;
7922
 
7923
    end
7924
    begin:error_monitor_1
7925 35 mihad
        error_monitor_done = 0 ;
7926 15 mihad
        @(error_event_int) ;
7927
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7928
        ok = 0 ;
7929 35 mihad
        error_monitor_done = 1 ;
7930 15 mihad
    end
7931
    begin
7932
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7933
        if ( ok !== 1 )
7934
        begin
7935
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7936
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7937
        end
7938
        else
7939
        begin
7940 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7941
//            while ( FRAME === 0 || IRDY === 0 )
7942
//                @(posedge pci_clock) ;
7943 15 mihad
 
7944
            // enable response in PCI target
7945
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
7946
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7947
 
7948
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7949
            if ( ok !== 1 )
7950
            begin
7951
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
7952
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
7953
            end
7954
        end
7955
 
7956 35 mihad
        #1 ;
7957
        if ( !error_monitor_done )
7958
            disable error_monitor_1 ;
7959 15 mihad
    end
7960
    join
7961
 
7962
    if ( ok )
7963
        test_ok ;
7964
 
7965
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
7966
 
7967
    // put WISHBONE slave in retry mode
7968
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
7969
 
7970
    fork
7971
    begin
7972
        // now post single write to target - normal progress
7973
        if ( target_mem_image == 1 )
7974
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7975
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7976
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7977
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7978
        else
7979
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7980
 
7981
        do_pause( 1 ) ;
7982
 
7983
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
7984
        if ( ok !== 1 )
7985
        begin
7986
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
7987
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
7988
        end
7989
 
7990
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7991
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7992
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7993
        begin
7994
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7995
            test_fail("Bridge didn't post single memory write as expected") ;
7996
        end
7997
 
7998
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7999
        if ( ok !== 1 )
8000
        begin
8001
            $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) ;
8002
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8003
            ok = 0 ;
8004
        end
8005
 
8006
        wait ( CYC_O === 0 ) ;
8007
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8008
 
8009
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8010
        if ( ok !== 1 )
8011
        begin
8012
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8013
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8014
        end
8015
 
8016 35 mihad
        #1 ;
8017
        if ( !error_monitor_done )
8018
            disable error_monitor_2 ;
8019 15 mihad
    end
8020
    begin:error_monitor_2
8021 35 mihad
        error_monitor_done = 0 ;
8022 15 mihad
        @(error_event_int) ;
8023
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8024
        ok = 0 ;
8025 35 mihad
        error_monitor_done = 1 ;
8026 15 mihad
    end
8027
    join
8028
 
8029
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8030
 
8031
    // put wishbone slave in acknowledge and pci target in retry mode
8032
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8033
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8034
 
8035
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8036
 
8037
    fork
8038
    begin
8039
        write_flags`WB_TRANSFER_SIZE = 3 ;
8040
        write_flags`WB_TRANSFER_CAB  = 1 ;
8041
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8042
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8043
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8044
        begin
8045
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8046
            test_fail("Bridge didn't post burst memory write as expected") ;
8047
        end
8048
 
8049
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8050
        if ( ok !== 1 )
8051
        begin
8052
            $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) ;
8053
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8054
            ok = 0 ;
8055
        end
8056
 
8057
        // now post single write to target - normal progress
8058
        if ( target_mem_image == 1 )
8059
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8060
                        pci_image_base, 32'h5555_5555, 4'h0,
8061
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8062
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8063
        else
8064
        begin
8065
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8066
            do_pause( 1 ) ;
8067
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8068
        end
8069
 
8070
        do_pause( 1 ) ;
8071
 
8072
    end
8073
    begin:error_monitor_3
8074 35 mihad
        error_monitor_done = 0 ;
8075 15 mihad
        @(error_event_int) ;
8076
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8077
        ok = 0 ;
8078 35 mihad
        error_monitor_done = 1 ;
8079 15 mihad
    end
8080
    begin
8081
        if ( target_mem_image == 1 )
8082
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8083
        else
8084
        begin
8085
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8086
            if ( ok )
8087
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8088
        end
8089
 
8090
        if ( ok !== 1 )
8091
        begin
8092
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8093
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8094
        end
8095
        else
8096
        begin
8097 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8098
//            while ( FRAME === 0 || IRDY === 0 )
8099
//                @(posedge pci_clock) ;
8100 15 mihad
 
8101
            // enable response in PCI target
8102
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8103
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8104
 
8105
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8106
            if ( ok !== 1 )
8107
            begin
8108
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8109
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8110
            end
8111
        end
8112
 
8113 35 mihad
        #1 ;
8114
        if ( !error_monitor_done )
8115
            disable error_monitor_3 ;
8116 15 mihad
    end
8117
    join
8118
 
8119
    if ( ok )
8120
        test_ok ;
8121
 
8122
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8123
 
8124
    // put WISHBONE slave in retry mode
8125
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8126
 
8127
    fork
8128
    begin
8129
        // now post single write to target - normal progress
8130
        if ( target_mem_image == 1 )
8131
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8132
                        pci_image_base, 32'h5555_5555, 4'h0,
8133
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8134
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8135
        else
8136
        begin
8137
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8138
            do_pause( 1 ) ;
8139
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8140
        end
8141
 
8142
        do_pause( 1 ) ;
8143
 
8144
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8145
 
8146
        if ( ok !== 1 )
8147
        begin
8148
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8149
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8150
        end
8151
 
8152
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8153
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8154
        write_flags`WB_TRANSFER_CAB      = 1 ;
8155
 
8156
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8157
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8158
        begin
8159
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8160
            test_fail("Bridge didn't post burst memory write as expected") ;
8161
        end
8162
 
8163
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8164
        if ( ok !== 1 )
8165
        begin
8166
            $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) ;
8167
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8168
            ok = 0 ;
8169
        end
8170
 
8171
        @(posedge wb_clock) ;
8172
        while ( CYC_O === 1 )
8173
            @(posedge wb_clock) ;
8174
 
8175
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8176
 
8177
        if ( target_mem_image == 1 )
8178
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8179
        else
8180
        begin
8181
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8182
            if ( ok )
8183
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8184
        end
8185
 
8186 35 mihad
        #1 ;
8187
        if ( !error_monitor_done )
8188
            disable error_monitor_4 ;
8189 15 mihad
    end
8190
    begin:error_monitor_4
8191 35 mihad
        error_monitor_done = 0 ;
8192 15 mihad
        @(error_event_int) ;
8193
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8194
        ok = 0 ;
8195 35 mihad
        error_monitor_done = 1 ;
8196 15 mihad
    end
8197
    join
8198
 
8199
    if ( ok )
8200
        test_ok ;
8201
 
8202
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8203
 
8204
    // put wishbone slave in acknowledge and pci target in retry mode
8205
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8206
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8207
 
8208
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8209
 
8210
    master1_check_received_data = 1 ;
8211
 
8212
    error_monitor_done = 0 ;
8213
    fork
8214
    begin:error_monitor_5
8215
        @(error_event_int or error_monitor_done) ;
8216
        if ( !error_monitor_done )
8217
        begin
8218
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8219
            ok = 0 ;
8220
        end
8221
    end
8222
    begin
8223
 
8224
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8225
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8226
        begin
8227
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8228
            test_fail("Bridge didn't post single memory write as expected") ;
8229
        end
8230
 
8231
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8232
        if ( ok !== 1 )
8233
        begin
8234
            $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) ;
8235
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8236
            ok = 0 ;
8237
        end
8238
 
8239
        // start Read Through pci target
8240
        if ( target_mem_image == 1 )
8241
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8242
                          pci_image_base, 32'h5555_5555,
8243
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8244
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8245
        else
8246
            PCIU_IO_READ
8247
             (
8248
                `Test_Master_1,
8249
                pci_image_base,
8250
                32'h5555_5555,
8251
                4'h0,
8252
                1,
8253
                `Test_Target_Retry_On
8254
             );
8255
 
8256
         do_pause( 1 ) ;
8257
 
8258
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8259
         if ( ok !== 1 )
8260
         begin
8261
            $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) ;
8262
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8263
         end
8264
 
8265
         // repeat the read 4 times - it should be retried all the time by pci target
8266
        for ( i = 0 ; i < 4 ; i = i + 1 )
8267
        begin
8268
            if ( target_mem_image == 1 )
8269
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8270
                            pci_image_base, 32'h5555_5555,
8271
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8272
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8273
            else
8274
                PCIU_IO_READ
8275
                (
8276
                    `Test_Master_1,
8277
                    pci_image_base,
8278
                    32'h5555_5555,
8279
                    4'h0,
8280
                    1,
8281
                    `Test_Target_Retry_On
8282
                );
8283
 
8284
            do_pause( 1 ) ;
8285
        end
8286
 
8287
        // now do posted write through target - it must go through OK
8288
        if ( target_mem_image == 1 )
8289
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8290
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8291
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8292
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8293
        else
8294
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8295
 
8296
        do_pause( 1 ) ;
8297
 
8298
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8299
        if ( ok !== 1 )
8300
        begin
8301
           $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) ;
8302
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8303
        end
8304
 
8305
        // start a read through wb_slave
8306
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8307
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8308
        begin
8309
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8310
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8311
            ok = 0 ;
8312
        end
8313
 
8314 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8315
//        while ( FRAME === 0 || IRDY === 0 )
8316
//            @(posedge pci_clock) ;
8317 15 mihad
 
8318
        // set the target to normal completion
8319
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8320
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8321
 
8322
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8323
        if ( ok !== 1 )
8324
        begin
8325
            $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) ;
8326
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8327
            ok = 0 ;
8328
        end
8329
 
8330
        // now wait for delayed read to finish
8331
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8332
        if ( ok !== 1 )
8333
        begin
8334
            $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) ;
8335
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8336
            ok = 0 ;
8337
        end
8338
 
8339
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8340
        fork
8341
        begin
8342
                if ( target_mem_image == 1 )
8343
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8344
                                pci_image_base, 32'h5555_5555, 4'h0,
8345
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8346
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8347
                else
8348
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8349
 
8350
                do_pause( 1 ) ;
8351
                end
8352
                begin
8353
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8354
                end
8355
                join
8356
 
8357
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8358
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8359
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8360
        begin
8361
            $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) ;
8362
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8363
            ok = 0 ;
8364
        end
8365
 
8366
        fork
8367
        begin
8368
        // now complete a read from PCI Target
8369
            if ( target_mem_image == 1 )
8370
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8371
                            pci_image_base, 32'h5555_5555,
8372
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8373
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8374
            else
8375
                PCIU_IO_READ
8376
                (
8377
                    `Test_Master_1,
8378
                    pci_image_base,
8379
                    32'h5555_5555,
8380
                    4'h0,
8381
                    1,
8382
                    `Test_Target_Normal_Completion
8383
                );
8384
 
8385
            do_pause( 1 ) ;
8386
        end
8387
        begin
8388
            if ( target_mem_image == 1 )
8389
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8390
            else
8391
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8392
        end
8393
        join
8394
 
8395
        @(posedge pci_clock) ;
8396
        repeat( 4 )
8397
            @(posedge wb_clock) ;
8398
 
8399
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8400
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8401
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8402
        begin
8403
            $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) ;
8404
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8405
            ok = 0 ;
8406
        end
8407
 
8408
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8409
        if ( ok !== 1 )
8410
        begin
8411
            $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) ;
8412
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8413
            ok = 0 ;
8414
        end
8415
 
8416
        // finish a read on WISHBONE also
8417
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8418
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8419
        begin
8420
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8421
            test_fail("WB Slave didn't process single delayed read as expected") ;
8422
        end
8423
 
8424
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8425
        begin
8426
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8427
            ok = 0 ;
8428
        end
8429
 
8430
 
8431
        error_monitor_done = 1 ;
8432
    end
8433
    join
8434
 
8435
    if ( ok )
8436
        test_ok ;
8437
 
8438
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8439
 
8440
    // put wishbone slave in retry and pci target in completion mode
8441
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8442
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8443
 
8444
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8445
 
8446
    master1_check_received_data = 1 ;
8447
 
8448
    error_monitor_done = 0 ;
8449
    fork
8450
    begin:error_monitor_6
8451
        @(error_event_int or error_monitor_done) ;
8452
        if ( !error_monitor_done )
8453
        begin
8454
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8455
            ok = 0 ;
8456
        end
8457
    end
8458
    begin
8459
 
8460
        // do a write through Target
8461
        fork
8462
        begin
8463
            if ( target_mem_image == 1 )
8464
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8465
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8466
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8467
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8468
            else
8469
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8470
 
8471
            do_pause( 1 ) ;
8472
        end
8473
        begin
8474
            if ( target_mem_image == 1 )
8475
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8476
            else
8477
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8478
        end
8479
        join
8480
 
8481
        // start a read through WB slave
8482
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8483
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8484
        begin
8485
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8486
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8487
            ok = 0 ;
8488
        end
8489
 
8490
        // now wait for this read to finish on pci
8491
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8492
        if ( ok !== 1 )
8493
        begin
8494
            $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) ;
8495
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8496
            ok = 0 ;
8497
        end
8498
 
8499
        // repeat the read four times - it should be retried
8500
        for ( i = 0 ; i < 4 ; i = i + 1 )
8501
        begin
8502
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8503
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8504
            begin
8505
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8506
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8507
                ok = 0 ;
8508
            end
8509
        end
8510
 
8511
        // posted write through WB Slave - must go through
8512
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8513
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8514
        begin
8515
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8516
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8517
            ok = 0 ;
8518
        end
8519
 
8520
        // write must come through
8521
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8522
        if ( ok !== 1 )
8523
        begin
8524
            $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) ;
8525
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8526
            ok = 0 ;
8527
        end
8528
 
8529
        // do a read through pci target
8530
        if ( target_mem_image == 1 )
8531
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8532
                          pci_image_base + 12, 32'hDEAD_BEAF,
8533
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8534
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8535
        else
8536
            PCIU_IO_READ
8537
             (
8538
                `Test_Master_1,
8539
                pci_image_base + 12,
8540
                32'hDEAD_BEAF,
8541
                4'h0,
8542
                1,
8543
                `Test_Target_Retry_On
8544
             );
8545
 
8546
         do_pause( 1 ) ;
8547
 
8548
        // wait for current cycle to finish on WB
8549 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8550
//        @(posedge wb_clock) ;
8551
//        while( CYC_O === 1 )
8552
//            @(posedge wb_clock) ;
8553 15 mihad
 
8554
        // set slave response to acknowledge
8555
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8556
 
8557
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8558
        if ( ok !== 1 )
8559
        begin
8560
            $display("Transaction ordering test failed! WB Master started invalid transaction or none at all on WB bus after single write was posted! Time %t ", $time) ;
8561
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8562
        end
8563
 
8564
        // check the read to finish on wb
8565
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8566
        if ( ok !== 1 )
8567
        begin
8568
            $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) ;
8569
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8570
        end
8571
 
8572
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8573
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8574
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8575
        begin
8576
            $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) ;
8577
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8578
            ok = 0 ;
8579
        end
8580
 
8581
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8582
        fork
8583
        begin
8584
            if ( target_mem_image == 1 )
8585
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8586
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8587
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8588
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8589
            else
8590
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8591
        end
8592
        begin
8593
            if ( target_mem_image == 1 )
8594
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8595
            else
8596
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8597
        end
8598
        join
8599
 
8600
        do_pause( 1 ) ;
8601
 
8602
        // complete a read in WB Slave Unit
8603
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8604
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8605
        begin
8606
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8607
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8608
            ok = 0 ;
8609
        end
8610
 
8611
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8612
        begin
8613
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8614
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8615
            ok = 0 ;
8616
        end
8617
 
8618
        // wait for statuses to be propagated from one side of bridge to another
8619
        repeat( 4 )
8620
            @(posedge pci_clock) ;
8621
 
8622
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8623
        fork
8624
        begin
8625
            if ( target_mem_image == 1 )
8626
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8627
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8628
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8629
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8630
            else
8631
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8632
 
8633
            do_pause( 1 ) ;
8634
        end
8635
        begin
8636
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8637
            if ( ok !== 1 )
8638
            begin
8639
                $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) ;
8640
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8641
            end
8642
        end
8643
        join
8644
 
8645
        // finish the last read in PCI Target Unit
8646
        if ( target_mem_image == 1 )
8647
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8648
                          pci_image_base + 12, 32'hDEAD_BEAF,
8649
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8650
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8651
        else
8652
            PCIU_IO_READ
8653
             (
8654
                `Test_Master_1,
8655
                pci_image_base + 12,
8656
                32'hDEAD_BEAF,
8657
                4'h0,
8658
                1,
8659
                `Test_Target_Normal_Completion
8660
             );
8661
 
8662
         do_pause( 1 ) ;
8663
 
8664
         error_monitor_done = 1 ;
8665
    end
8666
    join
8667
 
8668
    if ( ok )
8669
        test_ok ;
8670
 
8671
end
8672
endtask // transaction_ordering
8673
 
8674
task pci_transaction_progress_monitor ;
8675
    input [31:0] address ;
8676
    input [3:0]  bus_command ;
8677
    input [31:0] num_of_transfers ;
8678
    input [31:0] num_of_cycles ;
8679
    input check_transfers ;
8680
    input check_cycles ;
8681
    input doing_fast_back_to_back ;
8682
    output ok ;
8683
    reg in_use ;
8684
    integer deadlock_counter ;
8685
    integer transfer_counter ;
8686
    integer cycle_counter ;
8687
    integer deadlock_max_val ;
8688
begin:main
8689
 
8690
    if ( in_use === 1 )
8691
    begin
8692
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8693
        ok = 0 ;
8694
        disable main ;
8695
    end
8696
 
8697
    // approximate number of cycles on WB bus for maximum transaction length
8698
    deadlock_max_val = tb_init_waits + 100 +
8699
                       `WBW_DEPTH *
8700
                       (tb_subseq_waits + 1 +
8701
                       `ifdef REGISTER_WBS_OUTPUTS
8702
                       1) ;
8703
                       `else
8704
                       0) ;
8705
                       `endif
8706
 
8707
    // time used for maximum transaction length on WB
8708
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8709
 
8710
    // maximum pci clock cycles
8711
    `ifdef PCI33
8712
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8713
    `else
8714
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8715
    `endif
8716
 
8717
    in_use = 1 ;
8718
    ok     = 1 ;
8719
 
8720
    fork
8721
    begin:wait_start
8722
 
8723
        deadlock_counter = 0 ;
8724
 
8725
        @(posedge pci_clock) ;
8726
 
8727
        if ( doing_fast_back_to_back !== 1 )
8728
        begin
8729
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8730
            begin
8731 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8732
                    deadlock_counter = 0 ;
8733
                else
8734
                    deadlock_counter = deadlock_counter + 1 ;
8735 15 mihad
                @(posedge pci_clock) ;
8736
            end
8737
            if ( FRAME !== 1 )
8738
            begin
8739
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8740
                in_use = 0 ;
8741
                ok     = 0 ;
8742
                disable main ;
8743
            end
8744
        end
8745
 
8746
        deadlock_counter = 0 ;
8747
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8748
        begin
8749
            deadlock_counter = deadlock_counter + 1 ;
8750
            @(posedge pci_clock) ;
8751
        end
8752
 
8753
        if ( FRAME !== 0 )
8754
        begin
8755
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8756
            in_use = 0 ;
8757
            ok     = 0 ;
8758
            disable main ;
8759
        end
8760
    end //wait_start
8761
 
8762
    begin:addr_bc_monitor
8763
 
8764
        @(posedge pci_clock) ;
8765
 
8766
        if ( doing_fast_back_to_back !== 1 )
8767
        begin
8768
            while ( FRAME !== 1 )
8769
                @(posedge pci_clock) ;
8770
        end
8771
 
8772
        while( FRAME !== 0 )
8773
            @(posedge pci_clock) ;
8774
 
8775
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8776
        if ( bus_command !== `BC_IACK )
8777
        begin
8778
            if ( AD !== address )
8779
            begin
8780
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8781
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8782
                ok = 0 ;
8783
            end
8784
        end
8785
 
8786
        if ( CBE !== bus_command )
8787
        begin
8788
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8789
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8790
            ok = 0 ;
8791
        end
8792
    end //addr_bc_monitor
8793
 
8794
    begin:transfer_checker
8795
        transfer_counter = 0 ;
8796
 
8797
        @(posedge pci_clock) ;
8798
 
8799
        if ( doing_fast_back_to_back !== 1 )
8800
        begin
8801
            while ( FRAME !== 1 )
8802
                @(posedge pci_clock) ;
8803
        end
8804
 
8805
        while( FRAME !== 0 )
8806
            @(posedge pci_clock) ;
8807
 
8808
        while( FRAME === 0 )
8809
        begin
8810
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
8811
                transfer_counter = transfer_counter + 1 ;
8812
            @(posedge pci_clock) ;
8813
        end
8814
 
8815
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
8816
        begin
8817
            @(posedge pci_clock) ;
8818
        end
8819
 
8820
        if ( (TRDY === 0) && (DEVSEL === 0) )
8821
                transfer_counter = transfer_counter + 1 ;
8822
 
8823
        if ( check_transfers === 1 )
8824
        begin
8825
            if ( transfer_counter !== num_of_transfers )
8826
            begin
8827
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8828
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8829
                ok = 0 ;
8830
            end
8831
        end
8832
    end //transfer_checker
8833
    begin:cycle_checker
8834
        if ( check_cycles )
8835
        begin
8836
            cycle_counter = 0 ;
8837
            @(posedge pci_clock) ;
8838
 
8839
            if ( doing_fast_back_to_back !== 1)
8840
            begin
8841
                while ( FRAME !== 1 )
8842
                    @(posedge pci_clock) ;
8843
            end
8844
 
8845
            while( FRAME !== 0 )
8846
                @(posedge pci_clock) ;
8847
 
8848
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
8849
            begin
8850
                cycle_counter = cycle_counter + 1 ;
8851
                @(posedge pci_clock) ;
8852
            end
8853
 
8854
            if ( FRAME !== 1 )
8855
            begin
8856
                while ((FRAME === 0) && (MAS0_GNT === 0))
8857
                    @(posedge pci_clock) ;
8858
 
8859
                if ( FRAME !== 1 )
8860
                begin
8861
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
8862
                        @(posedge pci_clock) ;
8863
 
8864
                    @(posedge pci_clock) ;
8865
 
8866
                    if ( FRAME !== 1 )
8867
                    begin
8868
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
8869
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
8870
                        ok = 0 ;
8871
                    end
8872
                end
8873
            end
8874
        end
8875
    end // cycle_checker
8876
    join
8877
 
8878
    in_use = 0 ;
8879
end
8880
endtask //pci_transaction_progress_monitor
8881
 
8882
reg CYC_O_previous ;
8883
always@(posedge wb_clock or posedge reset)
8884
begin
8885
    if ( reset )
8886
        CYC_O_previous <= #1 1'b0 ;
8887
    else
8888
        CYC_O_previous <= #1 CYC_O ;
8889
end
8890
 
8891
task wb_transaction_progress_monitor ;
8892
    input [31:0] address ;
8893
    input        write ;
8894
    input [31:0] num_of_transfers ;
8895
    input check_transfers ;
8896
    output ok ;
8897
    reg in_use ;
8898
    integer deadlock_counter ;
8899
    integer transfer_counter ;
8900
    integer deadlock_max_val ;
8901
begin:main
8902
    if ( in_use === 1 )
8903
    begin
8904
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8905
        ok = 0 ;
8906
        disable main ;
8907
    end
8908
 
8909
    // number of cycles on WB bus for maximum transaction length
8910
    deadlock_max_val = 4 - tb_init_waits + 100 +
8911
                       `PCIW_DEPTH *
8912
                       (4 - tb_subseq_waits + 1) ;
8913
 
8914
    // time used for maximum transaction length on PCI
8915
    `ifdef PCI33
8916
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
8917
    `else
8918
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
8919
    `endif
8920
 
8921
    // maximum wb clock cycles
8922
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
8923
 
8924
    in_use = 1 ;
8925
    ok     = 1 ;
8926
 
8927
    fork
8928
    begin:wait_start
8929
        deadlock_counter = 0 ;
8930
        @(posedge wb_clock) ;
8931
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
8932
        begin
8933 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
8934
                deadlock_counter = deadlock_counter + 1 ;
8935
            else
8936
                deadlock_counter = 0;
8937 15 mihad
            @(posedge wb_clock) ;
8938
        end
8939
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
8940
        begin
8941
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8942
            in_use = 0 ;
8943
            ok     = 0 ;
8944
            disable main ;
8945
        end
8946
 
8947
        deadlock_counter = 0 ;
8948
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
8949
        begin
8950
            deadlock_counter = deadlock_counter + 1 ;
8951
            @(posedge wb_clock) ;
8952
        end
8953
 
8954
        if ( CYC_O !== 1 )
8955
        begin
8956
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8957
            in_use = 0 ;
8958
            ok     = 0 ;
8959
            disable main ;
8960
        end
8961
    end //wait_start
8962
    begin:addr_monitor
8963
        @(posedge wb_clock) ;
8964
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8965
            @(posedge wb_clock) ;
8966
 
8967
        while( CYC_O !== 1 )
8968
            @(posedge wb_clock) ;
8969
 
8970
        while (STB_O !== 1 )
8971
            @(posedge wb_clock) ;
8972
 
8973
        if ( WE_O !== write )
8974
        begin
8975
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
8976
            if ( write !== 1 )
8977
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
8978
            else
8979
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
8980
        end
8981
 
8982
        if ( ADR_O !== address )
8983
        begin
8984
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
8985
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
8986
            ok = 0 ;
8987
        end
8988
    end
8989
    begin:transfer_checker
8990
        transfer_counter = 0 ;
8991
        @(posedge wb_clock) ;
8992
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8993
            @(posedge wb_clock) ;
8994
 
8995
        while( CYC_O !== 1 )
8996
            @(posedge wb_clock) ;
8997
 
8998
        while( CYC_O === 1 )
8999
        begin
9000
            if ( (STB_O === 1) && (ACK_I === 1) )
9001
                transfer_counter = transfer_counter + 1 ;
9002
            @(posedge wb_clock) ;
9003
        end
9004
 
9005
        if ( check_transfers === 1 )
9006
        begin
9007
            if ( transfer_counter !== num_of_transfers )
9008
            begin
9009
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9010
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9011
                ok = 0 ;
9012
            end
9013
        end
9014
    end //transfer_checker
9015
    join
9016
 
9017
    in_use = 0 ;
9018
end
9019
endtask // wb_transaction_progress_monitor
9020
 
9021
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9022
// so they are not re-entered
9023
task wb_transaction_progress_monitor_backup ;
9024
    input [31:0] address ;
9025
    input        write ;
9026
    input [31:0] num_of_transfers ;
9027
    input check_transfers ;
9028
    output ok ;
9029
    reg in_use ;
9030
    integer deadlock_counter ;
9031
    integer transfer_counter ;
9032
    integer deadlock_max_val ;
9033
begin:main
9034
    if ( in_use === 1 )
9035
    begin
9036
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9037
        ok = 0 ;
9038
        disable main ;
9039
    end
9040
 
9041
    // number of cycles on WB bus for maximum transaction length
9042
    deadlock_max_val = 4 - tb_init_waits + 100 +
9043
                       `PCIW_DEPTH *
9044
                       (4 - tb_subseq_waits + 1) ;
9045
 
9046
    // time used for maximum transaction length on PCI
9047
    `ifdef PCI33
9048
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9049
    `else
9050
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9051
    `endif
9052
 
9053
    // maximum wb clock cycles
9054
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9055
 
9056
    in_use = 1 ;
9057
    ok     = 1 ;
9058
 
9059
    fork
9060
    begin:wait_start
9061
        deadlock_counter = 0 ;
9062
        @(posedge wb_clock) ;
9063
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9064
        begin
9065 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9066
                deadlock_counter = deadlock_counter + 1 ;
9067
            else
9068
                deadlock_counter = 0;
9069 15 mihad
            @(posedge wb_clock) ;
9070
        end
9071
        if ( CYC_O !== 0 )
9072
        begin
9073
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9074
            in_use = 0 ;
9075
            ok     = 0 ;
9076
            disable main ;
9077
        end
9078
 
9079
        deadlock_counter = 0 ;
9080
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9081
        begin
9082
            deadlock_counter = deadlock_counter + 1 ;
9083
            @(posedge wb_clock) ;
9084
        end
9085
 
9086
        if ( CYC_O !== 1 )
9087
        begin
9088
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9089
            in_use = 0 ;
9090
            ok     = 0 ;
9091
            disable main ;
9092
        end
9093
    end //wait_start
9094
    begin:addr_monitor
9095
        @(posedge wb_clock) ;
9096
        while ( CYC_O !== 0 )
9097
            @(posedge wb_clock) ;
9098
 
9099
        while( CYC_O !== 1 )
9100
            @(posedge wb_clock) ;
9101
 
9102
        while (STB_O !== 1 )
9103
            @(posedge wb_clock) ;
9104
 
9105
        if ( WE_O !== write )
9106
        begin
9107
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9108
            if ( write !== 1 )
9109
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9110
            else
9111
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9112
        end
9113
 
9114
        if ( ADR_O !== address )
9115
        begin
9116
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9117
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9118
            ok = 0 ;
9119
        end
9120
    end
9121
    begin:transfer_checker
9122
        transfer_counter = 0 ;
9123
        @(posedge wb_clock) ;
9124
        while ( CYC_O !== 0 )
9125
            @(posedge wb_clock) ;
9126
 
9127
        while( CYC_O !== 1 )
9128
            @(posedge wb_clock) ;
9129
 
9130
        while( CYC_O === 1 )
9131
        begin
9132
            if ( (STB_O === 1) && (ACK_I === 1) )
9133
                transfer_counter = transfer_counter + 1 ;
9134
            @(posedge wb_clock) ;
9135
        end
9136
 
9137
        if ( check_transfers === 1 )
9138
        begin
9139
            if ( transfer_counter !== num_of_transfers )
9140
            begin
9141
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9142
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9143
                ok = 0 ;
9144
            end
9145
        end
9146
    end //transfer_checker
9147
    join
9148
 
9149
    in_use = 0 ;
9150
end
9151
endtask // wb_transaction_progress_monitor_backup
9152
 
9153
task wb_transaction_stop ;
9154
    input [31:0] num_of_transfers ;
9155
    integer transfer_counter ;
9156
begin:main
9157
    begin:transfer_checker
9158
        transfer_counter = 0 ;
9159
        @(posedge wb_clock) ;
9160
        while ( CYC_O !== 0 )
9161
            @(posedge wb_clock) ;
9162
 
9163
        while( CYC_O !== 1 )
9164
            @(posedge wb_clock) ;
9165
 
9166
        if ( (STB_O === 1) && (ACK_I === 1) )
9167
            transfer_counter = transfer_counter + 1 ;
9168
 
9169
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9170
        begin
9171
            @(posedge wb_clock) ;
9172
            if ( (STB_O === 1) && (ACK_I === 1) )
9173
                transfer_counter = transfer_counter + 1 ;
9174
        end
9175
    end //transfer_checker
9176
end
9177
endtask // wb_transaction_stop
9178
 
9179
task musnt_respond ;
9180
    output ok ;
9181
    reg in_use ;
9182
    integer i ;
9183
begin:main
9184
    if ( in_use === 1 )
9185
    begin
9186
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9187
        #20 $stop ;
9188
        ok = 0 ;
9189
        disable main ;
9190
    end
9191
 
9192
    in_use = 1 ;
9193
    ok = 1 ;
9194
 
9195
    fork
9196
    begin:wait_start
9197
        @(negedge FRAME) ;
9198
        disable count ;
9199
    end
9200
    begin:count
9201
        i = 0 ;
9202
        while ( i < 1000 )
9203
        begin
9204
            @(posedge pci_clock) ;
9205
            i = i + 1 ;
9206
        end
9207
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9208
        ok = 0 ;
9209
        disable wait_start ;
9210
    end
9211
    join
9212
 
9213
    @(posedge pci_clock) ;
9214
    while ( FRAME === 0 && ok )
9215
    begin
9216
        if ( DEVSEL !== 1 )
9217
        begin
9218
            ok = 0 ;
9219
        end
9220
        @(posedge pci_clock) ;
9221
    end
9222
 
9223
    while ( IRDY === 0 && ok )
9224
    begin
9225
        if ( DEVSEL !== 1 )
9226
        begin
9227
            ok = 0 ;
9228
        end
9229
        @(posedge pci_clock) ;
9230
    end
9231
    in_use = 0 ;
9232
end
9233
endtask
9234
 
9235
function [31:0] wb_to_pci_addr_convert ;
9236
    input [31:0] wb_address ;
9237
    input [31:0] translation_address ;
9238
    input [31:0] translate ;
9239
 
9240
    reg   [31:0] temp_address ;
9241
begin
9242
    if ( translate !== 1 )
9243
    begin
9244
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9245
    end
9246
    else
9247
    begin
9248
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9249
    end
9250
 
9251
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9252
    wb_to_pci_addr_convert = temp_address ;
9253
end
9254
endfunction //wb_to_pci_addr_convert
9255
 
9256
task find_pci_devices ;
9257
    integer device_num ;
9258
    reg     found ;
9259
    reg [11:0] pci_ctrl_offset ;
9260
    reg ok ;
9261
    reg [31:0] data ;
9262
begin:main
9263
    pci_ctrl_offset = 12'h004 ;
9264
 
9265
    // enable master & target operation
9266
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9267
 
9268
    if ( ok !== 1 )
9269
    begin
9270
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9271
        $stop ;
9272
        disable main ;
9273
    end
9274
    // find all possible devices on pci bus by performing configuration cycles
9275
    for ( device_num = 0 ; device_num <= 20 ; device_num = device_num + 1 )
9276
    begin
9277
        find_device ( device_num, found ) ;
9278
 
9279
        // check pci status register - if device is not present, Received Master Abort bit must be set
9280
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9281
 
9282
        if ( (data[29] !== 0) && (found !== 0) )
9283
    begin
9284
            $display( "Time %t ", $time ) ;
9285
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9286
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9287
            #20 $stop ;
9288
        end
9289
 
9290
        if ( (data[29] !== 1) && (found !== 1) )
9291
        begin
9292
            $display( "Time %t ", $time ) ;
9293
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9294
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9295
            #20 $stop ;
9296
        end
9297
 
9298
        // clear Master Abort status if set
9299
        if ( data[29] !== 0 )
9300
        begin
9301
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9302
        end
9303
    end
9304
end //main
9305
endtask //find_pci_devices
9306
 
9307
task find_device ;
9308
    input [31:0] device_num ;
9309
    output  found ;
9310
 
9311
    reg [31:0] read_data ;
9312
begin
9313
    found = 1'b0 ;
9314
 
9315
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9316
    if ( read_data == 32'hFFFF_FFFF)
9317
        $display("Device %d not present on PCI bus!", device_num) ;
9318
    else
9319
    begin
9320
        $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]) ;
9321
        found = 1'b1 ;
9322
    end
9323
end
9324
endtask //find_device
9325
 
9326
/*task set_bridge_parameters ;
9327
    reg [11:0] current_offset ;
9328
    reg [2:0] result ;
9329
    reg [31:0] write_data ;
9330
begin
9331
    // set burst size
9332
    // set latency timer
9333
    current_offset = 12'h00C ;
9334
    // set burst size to 16 and latency timer to 8
9335
    write_data     = {24'h0000_08, system_burst_size} ;
9336
    config_write(current_offset, write_data, 4'b1111) ;
9337
 
9338
    // set io image
9339
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9340
    write_data = 32'h0000_000_3 ;
9341
    config_write(current_offset, write_data, 4'b1111) ;
9342
 
9343
 
9344
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9345
    write_data = 32'h0001_000_1 ;
9346
    config_write(current_offset, write_data, 4'b1111) ;
9347
 
9348
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9349
    write_data = 32'hFFFF_0000 ;
9350
    config_write(current_offset, write_data, 4'b1111) ;
9351
 
9352
    // set memory image
9353
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9354
    write_data = 32'h0000_000_7 ;
9355
    config_write(current_offset, write_data, 4'b1111) ;
9356
 
9357
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9358
    write_data = 32'h0002_000_0 ;
9359
    config_write(current_offset, write_data, 4'b1111) ;
9360
 
9361
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9362
    write_data = 32'h0001_0000 ;
9363
    config_write(current_offset, write_data, 4'b1111) ;
9364
 
9365
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9366
    write_data = 32'hFFFF_0000 ;
9367
    config_write(current_offset, write_data, 4'b1111) ;
9368
 
9369
    // set parameters for bridge's target unit
9370
    // image control 0
9371
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9372
    write_data     = 32'h0000_0002 ;
9373
    config_write(current_offset, write_data, 4'b0001) ;
9374
 
9375
    // base_address 0
9376
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9377
    write_data      = 32'h2000_0000 ;
9378
    config_write(current_offset, write_data, 4'b1111) ;
9379
 
9380
    // address mask 0
9381
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9382
    write_data     = 32'hFFFF_F000 ;
9383
    config_write(current_offset, write_data, 4'b1111) ;
9384
 
9385
    // command register - enable response to io and mem space and PCI master
9386
    current_offset = 12'h004 ;
9387
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9388
    config_write(current_offset, write_data, 4'b1111) ;
9389
end
9390
endtask // set_bridge_parameters
9391
*/
9392
 
9393
task configuration_cycle_write ;
9394
    input [7:0]  bus_num ;
9395
    input [4:0]  device_num ;
9396
    input [2:0]  func_num ;
9397
    input [5:0]  reg_num ;
9398
    input [1:0]  type ;
9399
    input [3:0]  byte_enables ;
9400
    input [31:0] data ;
9401
 
9402
    `ifdef HOST
9403
    reg `WRITE_STIM_TYPE write_data ;
9404
    reg `WB_TRANSFER_FLAGS write_flags ;
9405
    reg `WRITE_RETURN_TYPE write_status ;
9406
    `endif
9407
 
9408
    reg [31:0] write_address ;
9409
    reg [31:0] temp_var ;
9410
    reg in_use ;
9411
    reg ok ;
9412
begin:main
9413
 
9414
    if ( in_use === 1 )
9415
    begin
9416
        $display(" Task conf_write re-entered! Time %t ", $time ) ;
9417
        disable main ;
9418
    end
9419
 
9420
    if ( device_num > 20 )
9421
    begin
9422
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9423
        disable main ;
9424
    end
9425
 
9426
    in_use = 1 ;
9427
 
9428
    if ( type )
9429
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9430
    else
9431
    begin
9432
        write_address = 0 ;
9433
        write_address[10:0] = { func_num, reg_num, type } ;
9434
        write_address[11 + device_num] = 1'b1 ;
9435
    end
9436
 
9437
fork
9438
begin
9439
    `ifdef HOST
9440
    // setup write flags
9441
    write_flags                    = 0 ;
9442
    write_flags`INIT_WAITS         = tb_init_waits ;
9443
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
9444
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
9445
 
9446
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9447
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9448
 
9449
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9450
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9451
    write_data`WRITE_SEL      = 4'hF ;
9452
    write_data`WRITE_TAG_STIM = 0 ;
9453
 
9454
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9455
 
9456
    // check if write succeeded
9457
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9458
    begin
9459
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9460
        $stop ;
9461
    end
9462
 
9463
    // write to configuration data register
9464
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
9465
 
9466
    write_data`WRITE_ADDRESS = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9467
    write_data`WRITE_DATA    = data ;
9468
    write_data`WRITE_SEL     = byte_enables ;
9469
 
9470
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9471
 
9472
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9473
    begin
9474
        $display("Configuration cycle generation failed! Time %t ", $time) ;
9475
        $stop ;
9476
    end
9477
 
9478
    `else
9479
    `ifdef GUEST
9480
 
9481
     if ( type )
9482
         write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9483
     else
9484
     begin
9485
         write_address = 0 ;
9486
         write_address[10:0] = { func_num, reg_num, type } ;
9487
         write_address[11 + device_num] = 1'b1 ;
9488
     end
9489
     PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9490
                 write_address,
9491
                 data, ~byte_enables,
9492
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9493
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9494
     do_pause(1) ;
9495
    `endif
9496
    `endif
9497
end
9498
begin
9499
    pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9500
end
9501
join
9502
 
9503
    in_use = 0 ;
9504
end
9505
endtask // configuration_cycle_write
9506
 
9507
task configuration_cycle_read ;
9508
    input [7:0]  bus_num ;
9509
    input [4:0]  device_num ;
9510
    input [2:0]  func_num ;
9511
    input [5:0]  reg_num ;
9512
    input [1:0]  type ;
9513
    input [3:0]  byte_enables ;
9514
    output [31:0] data ;
9515
 
9516
    reg `READ_STIM_TYPE read_data ;
9517
    reg `WB_TRANSFER_FLAGS  flags ;
9518
    reg `READ_RETURN_TYPE   read_status ;
9519
 
9520
    reg `WRITE_STIM_TYPE   write_data ;
9521
    reg `WRITE_RETURN_TYPE write_status ;
9522
 
9523
    reg [31:0] read_address ;
9524
    reg in_use ;
9525
 
9526
    reg [31:0] temp_var ;
9527
    reg master_check_data_prev ;
9528
begin:main
9529
 
9530
    if ( in_use === 1 )
9531
    begin
9532
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9533
        data = 32'hxxxx_xxxx ;
9534
        disable main ;
9535
    end
9536
 
9537
    if ( device_num > 20 )
9538
    begin
9539
        $display("Configuration cycle generation only supports access to 20 devices!") ;
9540
        data = 32'hxxxx_xxxx ;
9541
        disable main ;
9542
    end
9543
 
9544
    in_use = 1 ;
9545
 
9546
    `ifdef HOST
9547
    // setup flags
9548
    flags = 0 ;
9549
 
9550
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9551
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9552
 
9553
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9554
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9555
    write_data`WRITE_SEL      = 4'hF ;
9556
    write_data`WRITE_TAG_STIM = 0 ;
9557
 
9558
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9559
 
9560
    // check if write succeeded
9561
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9562
    begin
9563
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9564
        $stop ;
9565
        data = 32'hFFFF_FFFF ;
9566
        disable main ;
9567
    end
9568
 
9569
    // read from configuration data register
9570
    // setup flags for wb master to handle retries
9571
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9572
 
9573
    read_data`READ_ADDRESS  = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9574
    read_data`READ_SEL      = 4'hF ;
9575
    read_data`READ_TAG_STIM = 0 ;
9576
 
9577
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
9578
 
9579
    // check if read succeeded
9580
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
9581
    begin
9582
        $display("Configuration cycle generation failed! Configuration read not processed correctly by the bridge! Time %t ", $time) ;
9583
        $stop ;
9584
        data = 32'hFFFF_FFFF ;
9585
        disable main ;
9586
    end
9587
 
9588
 
9589
    data = read_status`READ_DATA ;
9590
    `else
9591
    `ifdef GUEST
9592
     master_check_data_prev = master1_check_received_data ;
9593
     if ( type )
9594
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9595
     else
9596
     begin
9597
         read_address = 0 ;
9598
         read_address[10:0] = { func_num, reg_num, type } ;
9599
         read_address[11 + device_num] = 1'b1 ;
9600
     end
9601
 
9602
     fork
9603
     begin
9604
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9605
                 read_address,
9606
                 data, ~byte_enables,
9607
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9608
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9609
         do_pause(1) ;
9610
     end
9611
     begin
9612
         @(master1_received_data_valid) ;
9613
         data = master1_received_data ;
9614
     end
9615
     join
9616
 
9617
    master1_check_received_data = master_check_data_prev ;
9618
    `endif
9619
    `endif
9620
 
9621
    in_use = 0 ;
9622
 
9623
end //main
9624
endtask // configuration_cycle_read
9625
 
9626
task display_warning;
9627
    input [31:0] error_address ;
9628
    input [31:0] expected_data ;
9629
    input [31:0] actual ;
9630
begin
9631
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
9632
end
9633
endtask // display warning
9634
 
9635
/*############################################################################
9636
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
9637
=====================
9638
############################################################################*/
9639
 
9640
// Task reslease the PCI bus for 'delay' clocks
9641
task do_pause;
9642
  input  [15:0] delay;
9643
  reg    [15:0] cnt;
9644
  begin
9645
    test_start <= 1'b0;  // no device is allowed to take this
9646
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
9647
    begin
9648
      if (~pci_reset_comb)
9649
      begin
9650
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9651
      end
9652
      `NO_ELSE;
9653
    end
9654
  end
9655
endtask // do_pause
9656
 
9657
// Reference task for using pci_behavioral_master! (from Blue Beaver)
9658
task DO_REF;
9659
  input  [79:0] name;
9660
  input  [2:0] master_number;
9661
  input  [PCI_BUS_DATA_RANGE:0] address;
9662
  input  [3:0] command;
9663
  input  [PCI_BUS_DATA_RANGE:0] data;
9664
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
9665
  input  [9:0] size;
9666
  input   make_addr_par_error, make_data_par_error;
9667
  input  [7:0] master_wait_states;
9668
  input  [7:0] target_wait_states;
9669
  input  [1:0] target_devsel_speed;
9670
  input   fast_back_to_back;
9671
  input  [2:0] target_termination;
9672
  input   expect_master_abort;
9673
  reg     waiting;
9674
  begin
9675
// Cautiously wait for previous command to be done
9676
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
9677
    begin
9678
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
9679
      begin
9680
        if (~pci_reset_comb)
9681
        begin
9682
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9683
        end
9684
        `NO_ELSE;
9685
      end
9686
      else
9687
      begin
9688
        waiting = 1'b0;  // ready to do next command
9689
      end
9690
    end
9691
    next_test_name[79:0] <= name[79:0];
9692
    test_master_number <= master_number[2:0];
9693
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
9694
    test_command[3:0] <= command[3:0] ;
9695
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
9696
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
9697
    test_size <= size;
9698
    test_make_addr_par_error <= make_addr_par_error;
9699
    test_make_data_par_error <= make_data_par_error;
9700
    test_master_initial_wait_states <= 4 - tb_init_waits ;
9701
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
9702
    test_target_initial_wait_states <= target_wait_states[7:4];
9703
    test_target_subsequent_wait_states <= target_wait_states[3:0];
9704
    test_target_devsel_speed <= target_devsel_speed[1:0];
9705
    test_fast_back_to_back <= fast_back_to_back;
9706
    test_target_termination <= target_termination[2:0];
9707
    test_expect_master_abort <= expect_master_abort;
9708
    test_start <= 1'b1;
9709
    if (~pci_reset_comb)
9710
    begin
9711
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9712
    end
9713
    `NO_ELSE;
9714
// wait for new command to start
9715
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
9716
    begin
9717
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
9718
      begin
9719
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9720
      end
9721
      else
9722
      begin
9723
        waiting = 1'b0;  // ready to do next command
9724
      end
9725
    end
9726
  end
9727
endtask // DO_REF
9728
 
9729
// Use Macros defined in pci_defines.vh as paramaters
9730
 
9731
// DO_REF (name[79:0], master_number[2:0],
9732
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
9733
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
9734
//          make_addr_par_error, make_data_par_error,
9735
//          master_wait_states[8:0], target_wait_states[8:0],
9736
//          target_devsel_speed[1:0], fast_back_to_back,
9737
//          target_termination[2:0],
9738
//          expect_master_abort);
9739
//
9740
// Example:
9741
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
9742
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
9743
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
9744
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
9745
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
9746
 
9747
// Access a location with no high-order bits set, assuring that no device responds
9748
task PCIU_CONFIG_READ_MASTER_ABORT;
9749
  input  [79:0] name;
9750
  input  [2:0] master_number;
9751
  input  [9:0] size;
9752
  begin
9753
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9754
               PCI_COMMAND_CONFIG_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9755
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9756
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9757
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9758
  end
9759
endtask // PCIU_CONFIG_READ_MASTER_ABORT
9760
 
9761
// Access a location with no high-order bits set, assuring that no device responds
9762
task PCIU_CONFIG_WRITE_MASTER_ABORT;
9763
  input  [79:0] name;
9764
  input  [2:0] master_number;
9765
  input  [9:0] size;
9766
  begin
9767
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9768
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9769
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9770
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9771
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9772
  end
9773
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
9774
 
9775
// Access a location with no high-order bits set, assuring that no device responds
9776
task PCIU_MEM_READ_MASTER_ABORT;
9777
  input  [79:0] name;
9778
  input  [2:0] master_number;
9779
  input  [9:0] size;
9780
  begin
9781
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9782
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9783
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9784
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9785
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9786
  end
9787
endtask // PCIU_MEM_READ_MASTER_ABORT
9788
 
9789
// Access a location with no high-order bits set, assuring that no device responds
9790
task PCIU_MEM_WRITE_MASTER_ABORT;
9791
  input  [79:0] name;
9792
  input  [2:0] master_number;
9793
  input  [9:0] size;
9794
  begin
9795
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9796
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9797
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9798
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9799
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9800
  end
9801
endtask // PCIU_MEM_WRITE_MASTER_ABORT
9802
 
9803
// Do variable length transfers with various paramaters
9804
task PCIU_CONFIG_READ;
9805
  input  [79:0] name;
9806
  input  [2:0] master_number;
9807
  input  [PCI_BUS_DATA_RANGE:0] address;
9808
  input  [PCI_BUS_DATA_RANGE:0] data;
9809
  input  [3:0] be ;
9810
  input  [9:0] size;
9811
  input  [7:0] master_wait_states;
9812
  input  [7:0] target_wait_states;
9813
  input  [1:0] target_devsel_speed;
9814
  input  [2:0] target_termination;
9815
  begin
9816
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9817
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
9818
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9819
              8'h0_0, target_wait_states[7:0],
9820
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9821
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9822
  end
9823
endtask // PCIU_CONFIG_READ
9824
 
9825
task PCIU_CONFIG_WRITE;
9826
  input  [79:0] name;
9827
  input  [2:0] master_number;
9828
  input  [PCI_BUS_DATA_RANGE:0] address;
9829
  input  [PCI_BUS_DATA_RANGE:0] data;
9830
  input  [3:0] be ;
9831
  input  [9:0] size;
9832
  input  [7:0] master_wait_states;
9833
  input  [7:0] target_wait_states;
9834
  input  [1:0] target_devsel_speed;
9835
  input  [2:0] target_termination;
9836
  begin
9837
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9838
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
9839
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9840
              8'h0_0, target_wait_states[7:0],
9841
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9842
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9843
  end
9844
endtask // PCIU_CONFIG_WRITE
9845
 
9846
task PCIU_READ;
9847
  input  [2:0] master_number;
9848
  input  [PCI_BUS_DATA_RANGE:0] address;
9849
  input  [3:0] command;
9850
  input  [PCI_BUS_DATA_RANGE:0] data;
9851
  input  [3:0] byte_en;
9852
  input  [9:0] size;
9853
  input  [7:0] master_wait_states;
9854
  input  [7:0] target_wait_states;
9855
  input  [1:0] target_devsel_speed;
9856
  input  [2:0] target_termination;
9857
  reg    [79:0] name;
9858
  begin
9859
    if (command == `BC_MEM_READ)
9860
        name = "MEM_READ  " ;
9861
    else if (command == `BC_MEM_READ_LN)
9862
        name = "MEM_RD_LN " ;
9863
    else if (command == `BC_MEM_READ_MUL )
9864
        name = "MEM_RD_MUL" ;
9865
    else
9866
        name = "WRONG_READ" ;
9867
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9868
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9869
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9870
              8'h0_0, target_wait_states[7:0],
9871
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9872
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9873
  end
9874
endtask // PCIU_READ
9875
 
9876
task PCIU_MEM_READ;
9877
  input  [79:0] name;
9878
  input  [2:0] master_number;
9879
  input  [PCI_BUS_DATA_RANGE:0] address;
9880
  input  [PCI_BUS_DATA_RANGE:0] data;
9881
  input  [9:0] size;
9882
  input  [7:0] master_wait_states;
9883
  input  [7:0] target_wait_states;
9884
  input  [1:0] target_devsel_speed;
9885
  input  [2:0] target_termination;
9886
  begin
9887
 
9888
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9889
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9890
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9891
              8'h0_0, target_wait_states[7:0],
9892
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9893
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9894
  end
9895
endtask // PCIU_MEM_READ
9896
 
9897
task PCIU_IO_READ;
9898
  input  [2:0] master_number;
9899
  input  [PCI_BUS_DATA_RANGE:0] address;
9900
  input  [PCI_BUS_DATA_RANGE:0] data;
9901
  input  [3:0] byte_en ;
9902
  input  [9:0] size;
9903
  input  [2:0] target_termination ;
9904
  begin
9905
 
9906
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9907
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9908
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9909
              8'h0_0, `Test_One_Zero_Target_WS,
9910
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9911
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9912
  end
9913
endtask // PCIU_IO_READ
9914
 
9915
task PCIU_IO_READ_MAKE_PERR;
9916
  input  [2:0] master_number;
9917
  input  [PCI_BUS_DATA_RANGE:0] address;
9918
  input  [PCI_BUS_DATA_RANGE:0] data;
9919
  input  [3:0] byte_en ;
9920
  input  [9:0] size;
9921
  input  [2:0] target_termination ;
9922
  begin
9923
 
9924
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9925
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9926
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9927
              8'h0_0, `Test_One_Zero_Target_WS,
9928
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9929
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9930
  end
9931
endtask // PCIU_IO_READ_MAKE_PERR
9932
 
9933
task PCIU_MEM_READ_LN;
9934
  input  [79:0] name;
9935
  input  [2:0] master_number;
9936
  input  [PCI_BUS_DATA_RANGE:0] address;
9937
  input  [PCI_BUS_DATA_RANGE:0] data;
9938
  input  [9:0] size;
9939
  input  [7:0] master_wait_states;
9940
  input  [7:0] target_wait_states;
9941
  input  [1:0] target_devsel_speed;
9942
  input  [2:0] target_termination;
9943
  begin
9944
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9945
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9946
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9947
              8'h0_0, target_wait_states[7:0],
9948
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9949
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9950
  end
9951
endtask // PCIU_MEM_READ_LN
9952
 
9953
task PCIU_MEM_READ_MUL;
9954
  input  [79:0] name;
9955
  input  [2:0] master_number;
9956
  input  [PCI_BUS_DATA_RANGE:0] address;
9957
  input  [PCI_BUS_DATA_RANGE:0] data;
9958
  input  [9:0] size;
9959
  input  [7:0] master_wait_states;
9960
  input  [7:0] target_wait_states;
9961
  input  [1:0] target_devsel_speed;
9962
  input  [2:0] target_termination;
9963
  begin
9964
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9965
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9966
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9967
              8'h0_0, target_wait_states[7:0],
9968
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9969
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9970
  end
9971
endtask // PCIU_MEM_READ_MUL
9972
 
9973
task PCIU_MEM_READ_MAKE_PERR;
9974
  input  [79:0] name;
9975
  input  [2:0] master_number;
9976
  input  [PCI_BUS_DATA_RANGE:0] address;
9977
  input  [PCI_BUS_DATA_RANGE:0] data;
9978
  input  [9:0] size;
9979
  input  [7:0] master_wait_states;
9980
  input  [7:0] target_wait_states;
9981
  input  [1:0] target_devsel_speed;
9982
  input  [2:0] target_termination;
9983
  begin
9984
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9985
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9986
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9987
              8'h0_0, target_wait_states[7:0],
9988
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9989
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9990
  end
9991
endtask // PCIU_MEM_READ_MAKE_PERR
9992
 
9993
task PCIU_MEM_WRITE;
9994
  input  [79:0] name;
9995
  input  [2:0] master_number;
9996
  input  [PCI_BUS_DATA_RANGE:0] address;
9997
  input  [PCI_BUS_DATA_RANGE:0] data;
9998
  input  [3:0] byte_en;
9999
  input  [9:0] size;
10000
  input  [7:0] master_wait_states;
10001
  input  [7:0] target_wait_states;
10002
  input  [1:0] target_devsel_speed;
10003
  input  [2:0] target_termination;
10004
  begin
10005
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10006
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
10007
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
10008
              8'h0_0, target_wait_states[7:0],
10009
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10010
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10011
  end
10012
endtask // PCIU_MEM_WRITE
10013
 
10014
task PCIU_IO_WRITE;
10015
  input  [2:0] master_number;
10016
  input  [PCI_BUS_DATA_RANGE:0] address;
10017
  input  [PCI_BUS_DATA_RANGE:0] data;
10018
  input  [3:0] byte_en;
10019
  input  [9:0] size;
10020
  input  [2:0] target_termination ;
10021
  begin
10022
 
10023
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10024
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
10025
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
10026
              8'h0_0, `Test_One_Zero_Target_WS,
10027
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
10028
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10029
  end
10030
endtask // PCIU_IO_WRITE
10031
 
10032
task PCIU_IO_WRITE_MAKE_PERR ;
10033
  input  [2:0] master_number;
10034
  input  [PCI_BUS_DATA_RANGE:0] address;
10035
  input  [PCI_BUS_DATA_RANGE:0] data;
10036
  input  [3:0] byte_en;
10037
  input  [9:0] size;
10038
  input  [2:0] target_termination ;
10039
  begin
10040
 
10041
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10042
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
10043
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
10044
              8'h0_0, `Test_One_Zero_Target_WS,
10045
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
10046
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10047
  end
10048
endtask // PCIU_IO_WRITE
10049
 
10050
task PCIU_MEM_WRITE_MAKE_SERR;
10051
  input  [79:0] name;
10052
  input  [2:0] master_number;
10053
  input  [PCI_BUS_DATA_RANGE:0] address;
10054
  input  [PCI_BUS_DATA_RANGE:0] data;
10055
  input  [9:0] size;
10056
  input  [7:0] master_wait_states;
10057
  input  [7:0] target_wait_states;
10058
  input  [1:0] target_devsel_speed;
10059
  input  [2:0] target_termination;
10060
  begin
10061
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10062
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
10063
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
10064
              8'h0_0, target_wait_states[7:0],
10065
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10066
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10067
  end
10068
endtask // PCIU_MEM_WRITE_MAKE_SERR
10069
 
10070
task PCIU_MEM_WRITE_MAKE_PERR;
10071
  input  [79:0] name;
10072
  input  [2:0] master_number;
10073
  input  [PCI_BUS_DATA_RANGE:0] address;
10074
  input  [PCI_BUS_DATA_RANGE:0] data;
10075
  input  [9:0] size;
10076
  input  [7:0] master_wait_states;
10077
  input  [7:0] target_wait_states;
10078
  input  [1:0] target_devsel_speed;
10079
  input  [2:0] target_termination;
10080
  begin
10081
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10082
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
10083
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
10084
              8'h0_0, target_wait_states[7:0],
10085
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10086
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10087
  end
10088
endtask // PCIU_MEM_WRITE
10089
 
10090
/*--------------------------------------------------------------------------
10091
Initialization CASES
10092
--------------------------------------------------------------------------*/
10093
 
10094
// Initialize the basic Config Registers of the PCI bridge target device
10095
task configure_bridge_target;
10096
    reg [11:0] offset ;
10097
    reg [31:0] data ;
10098
    `ifdef HOST
10099
    reg `WRITE_STIM_TYPE   write_data ;
10100
    reg `WB_TRANSFER_FLAGS write_flags ;
10101
    reg `WRITE_RETURN_TYPE write_status ;
10102
    `else
10103
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10104
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10105
    `endif
10106
 
10107
    reg [31:0] temp_var ;
10108
begin
10109
`ifdef HOST //  set Header
10110
    offset  = 12'h4 ; // PCI Header Command register
10111
    data    = 32'h0000_0007 ; // enable master & target operation
10112
 
10113
    write_flags                      = 0 ;
10114
    write_flags`INIT_WAITS           = tb_init_waits ;
10115
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10116
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10117
 
10118
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
10119
    write_data`WRITE_SEL      = 4'h1 ;
10120
    write_data`WRITE_TAG_STIM = 0 ;
10121
    write_data`WRITE_DATA     = data ;
10122
 
10123
    next_test_name[79:0] <= "Init_Tar_R";
10124
 
10125
    $display(" bridge target - Enabling master and target operation!");
10126
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10127
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10128
    begin
10129
        $display("Write to configuration space failed! Time %t ", $time) ;
10130
    end
10131
 
10132
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10133
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10134
 
10135
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10136
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10137
 
10138
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10139
    write_data`WRITE_SEL      = 4'hf ;
10140
    write_data`WRITE_TAG_STIM = 0 ;
10141
    write_data`WRITE_DATA     = data ;
10142
 
10143
 `ifdef  NO_CNF_IMAGE
10144
  `ifdef PCI_IMAGE0 //      set P_BA0
10145
 
10146
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10147
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10148
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10149
    begin
10150
        $display("Write to configuration space failed! Time %t ", $time) ;
10151
    end
10152
  `endif
10153
 `else //      set P_BA0
10154
 
10155
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10156
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10157
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10158
    begin
10159
        $display("Write to configuration space failed! Time %t ", $time) ;
10160
    end
10161
 `endif
10162
 
10163
`else // GUEST, set Header, set P_BA0
10164
    data            = 32'h0000_0007 ; // enable master & target operation
10165
    byte_enables    = 4'hF ;
10166
    $display(" bridge target - Enabling master and target operation!");
10167
    configuration_cycle_write(0,             // bus number
10168
                              0,             // device number
10169
                              0,             // function number
10170
                              1,             // register number
10171
                              0,             // type of configuration cycle
10172
                              byte_enables,  // byte enables
10173
                              data           // data
10174
                             ) ;
10175
 
10176
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10177
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10178
    byte_enables = 4'hf ;
10179
    configuration_cycle_write(0,             // bus number
10180
                              0,             // device number
10181
                              0,             // function number
10182
                              4,             // register number
10183
                              0,             // type of configuration cycle
10184
                              byte_enables,  // byte enables
10185
                              data           // data
10186
                             ) ;
10187
 
10188
`endif
10189
end
10190
endtask // configure_bridge_target
10191
 
10192
// Initialize the basic Config Registers of the PCI bridge target device
10193
task configure_bridge_target_base_addresses;
10194
    reg [11:0] offset ;
10195
    reg [31:0] data ;
10196
    `ifdef HOST
10197
    reg `WRITE_STIM_TYPE   write_data ;
10198
    reg `WB_TRANSFER_FLAGS write_flags ;
10199
    reg `WRITE_RETURN_TYPE write_status ;
10200
    `else
10201
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10202
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10203
    `endif
10204
 
10205
    reg [31:0] temp_var ;
10206
begin
10207
`ifdef HOST //  set Header
10208
    offset  = 12'h4 ; // PCI Header Command register
10209
    data    = 32'h0000_0007 ; // enable master & target operation
10210
 
10211
    write_flags                    = 0 ;
10212
    write_flags`INIT_WAITS         = tb_init_waits ;
10213
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
10214
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10215
 
10216
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10217
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10218
 
10219
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10220
    write_data`WRITE_SEL      = 4'h1 ;
10221
    write_data`WRITE_TAG_STIM = 0 ;
10222
    write_data`WRITE_DATA     = data ;
10223
 
10224
    next_test_name[79:0] <= "Init_Tar_R";
10225
 
10226
    $display(" bridge target - Enabling master and target operation!");
10227
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10228
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10229
    begin
10230
        $display("Write to configuration space failed! Time %t ", $time) ;
10231
    end
10232
 
10233
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10234
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10235
 
10236
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10237
    write_data`WRITE_SEL      = 4'hf ;
10238
    write_data`WRITE_TAG_STIM = 0 ;
10239
    write_data`WRITE_DATA     = data ;
10240
 
10241
 `ifdef  NO_CNF_IMAGE
10242
  `ifdef PCI_IMAGE0 //      set P_BA0
10243
 
10244
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10245
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10246
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10247
    begin
10248
        $display("Write to configuration space failed! Time %t ", $time) ;
10249
    end
10250
  `endif
10251
 `else //      set P_BA0
10252
 
10253
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10254
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10255
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10256
    begin
10257
        $display("Write to configuration space failed! Time %t ", $time) ;
10258
    end
10259
 `endif
10260
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
10261
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10262
 
10263
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10264
    write_data`WRITE_SEL      = 4'hf ;
10265
    write_data`WRITE_TAG_STIM = 0 ;
10266
    write_data`WRITE_DATA     = data ;
10267
 
10268
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10269
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10270
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10271
    begin
10272
        $display("Write to configuration space failed! Time %t ", $time) ;
10273
    end
10274
 `ifdef PCI_IMAGE2
10275
 
10276
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
10277
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10278
 
10279
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10280
    write_data`WRITE_SEL      = 4'hf ;
10281
    write_data`WRITE_TAG_STIM = 0 ;
10282
    write_data`WRITE_DATA     = data ;
10283
 
10284
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10285
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10286
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10287
    begin
10288
        $display("Write to configuration space failed! Time %t ", $time) ;
10289
    end
10290
 `endif
10291
 `ifdef PCI_IMAGE3
10292
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
10293
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10294
 
10295
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10296
    write_data`WRITE_SEL      = 4'hf ;
10297
    write_data`WRITE_TAG_STIM = 0 ;
10298
    write_data`WRITE_DATA     = data ;
10299
 
10300
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10301
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10302
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10303
    begin
10304
        $display("Write to configuration space failed! Time %t ", $time) ;
10305
    end
10306
 `endif
10307
 `ifdef PCI_IMAGE4
10308
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
10309
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10310
 
10311
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10312
    write_data`WRITE_SEL      = 4'hf ;
10313
    write_data`WRITE_TAG_STIM = 0 ;
10314
    write_data`WRITE_DATA     = data ;
10315
 
10316
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10317
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10318
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10319
    begin
10320
        $display("Write to configuration space failed! Time %t ", $time) ;
10321
    end
10322
 `endif
10323
 `ifdef PCI_IMAGE5
10324
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
10325
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10326
 
10327
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10328
    write_data`WRITE_SEL      = 4'hf ;
10329
    write_data`WRITE_TAG_STIM = 0 ;
10330
    write_data`WRITE_DATA     = data ;
10331
 
10332
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10333
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10334
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10335
    begin
10336
        $display("Write to configuration space failed! Time %t ", $time) ;
10337
    end
10338
 `endif
10339
 
10340
`else // GUEST, set Header, set P_BA0
10341
    data            = 32'h0000_0007 ; // enable master & target operation
10342
    byte_enables    = 4'hF ;
10343
    $display(" bridge target - Enabling master and target operation!");
10344
    configuration_cycle_write(0,             // bus number
10345
                              0,             // device number
10346
                              0,             // function number
10347
                              1,             // register number
10348
                              0,             // type of configuration cycle
10349
                              byte_enables,  // byte enables
10350
                              data           // data
10351
                             ) ;
10352
 
10353
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10354
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10355
    byte_enables = 4'hf ;
10356
    configuration_cycle_write(0,             // bus number
10357
                              0,             // device number
10358
                              0,             // function number
10359
                              4,             // register number
10360
                              0,             // type of configuration cycle
10361
                              byte_enables,  // byte enables
10362
                              data           // data
10363
                             ) ;
10364
 
10365
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10366
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10367
    byte_enables = 4'hf ;
10368
    configuration_cycle_write(0,             // bus number
10369
                              0,             // device number
10370
                              0,             // function number
10371
                              5,             // register number
10372
                              0,             // type of configuration cycle
10373
                              byte_enables,  // byte enables
10374
                              data           // data
10375
                             ) ;
10376
 `ifdef PCI_IMAGE2
10377
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10378
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10379
    byte_enables = 4'hf ;
10380
    configuration_cycle_write(0,             // bus number
10381
                              0,             // device number
10382
                              0,             // function number
10383
                              6,             // register number
10384
                              0,             // type of configuration cycle
10385
                              byte_enables,  // byte enables
10386
                              data           // data
10387
                             ) ;
10388
 `endif
10389
 `ifdef PCI_IMAGE3
10390
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10391
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10392
    byte_enables = 4'hf ;
10393
    configuration_cycle_write(0,             // bus number
10394
                              0,             // device number
10395
                              0,             // function number
10396
                              7,             // register number
10397
                              0,             // type of configuration cycle
10398
                              byte_enables,  // byte enables
10399
                              data           // data
10400
                             ) ;
10401
 `endif
10402
 `ifdef PCI_IMAGE4
10403
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10404
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10405
    byte_enables = 4'hf ;
10406
    configuration_cycle_write(0,             // bus number
10407
                              0,             // device number
10408
                              0,             // function number
10409
                              8,             // register number
10410
                              0,             // type of configuration cycle
10411
                              byte_enables,  // byte enables
10412
                              data           // data
10413
                             ) ;
10414
 `endif
10415
 `ifdef PCI_IMAGE5
10416
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10417
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10418
    byte_enables = 4'hf ;
10419
    configuration_cycle_write(0,             // bus number
10420
                              0,             // device number
10421
                              0,             // function number
10422
                              9,             // register number
10423
                              0,             // type of configuration cycle
10424
                              byte_enables,  // byte enables
10425
                              data           // data
10426
                             ) ;
10427
 `endif
10428
`endif
10429
end
10430
endtask // configure_bridge_target_base_addresses
10431
 
10432
/*--------------------------------------------------------------------------
10433
Test CASES
10434
--------------------------------------------------------------------------*/
10435
 
10436
// function converts PCI address to WB with the same data as the pci_decoder does
10437
function [31:0] pci_to_wb_addr_convert ;
10438
 
10439
    input [31:0] pci_address ;
10440
    input [31:0] translation_address ;
10441
    input [31:0] translate ;
10442
 
10443
    reg   [31:0] temp_address ;
10444
begin
10445
    if ( translate !== 1 )
10446
    begin
10447
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10448
    end
10449
    else
10450
    begin
10451
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10452
    end
10453
 
10454
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
10455
    pci_to_wb_addr_convert = temp_address ;
10456
end
10457
endfunction // pci_to_wb_addr_convert
10458
 
10459
// Test normal write and read to WB slave
10460
task test_normal_wr_rd;
10461
  input  [2:0]  Master_ID;
10462
  input  [PCI_BUS_DATA_RANGE:0] Address;
10463
  input  [PCI_BUS_DATA_RANGE:0] Data;
10464
  input  [3:0]  Be;
10465
  input  [2:0]  Image_num;
10466
  input  [9:0]  Set_size;
10467
  input         Set_addr_translation;
10468
  input         Set_prefetch_enable;
10469
  input  [7:0]  Cache_lsize;
10470
  input         Set_wb_wait_states;
10471
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
10472
 
10473
  reg    [31:0] rd_address;
10474
  reg    [31:0] rd_data;
10475
  reg    [3:0]  rd_be;
10476
  reg    [11:0] addr_offset;
10477
  reg    [31:0] read_data;
10478
  reg           continue ;
10479
  reg           ok   ;
10480
  reg    [31:0] expect_address ;
10481
  reg    [31:0] expect_rd_address ;
10482
  reg           expect_we ;
10483
  reg    [9:0]  expect_length_wr ;
10484
  reg    [9:0]  expect_length_rd ;
10485
  reg    [9:0]  expect_length_rd1 ;
10486
  reg    [9:0]  expect_length_rd2 ;
10487
  reg    [3:0]  use_rd_cmd ;
10488
  integer       i ;
10489 35 mihad
  reg           error_monitor_done ;
10490 15 mihad
begin:main
10491
 
10492
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
10493
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10494
    $display(" - errors will be reported, but they should not occur!");
10495
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
10496
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10497
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
10498
    if ( ok !== 1 )
10499
    begin
10500
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10501
        test_fail("write to P_ERR_CS register didn't succeede") ;
10502
        disable main;
10503
    end
10504
 
10505
    `ifdef  ADDR_TRAN_IMPL
10506
 
10507
    // set or clear address translation
10508
    if (Set_addr_translation)
10509
    begin
10510
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10511
        $display(" - address translation will be performed!");
10512
    end
10513
    else
10514
    begin
10515
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10516
        $display(" - address translation will not be performed!");
10517
    end
10518
    // set or clear pre-fetch enable
10519
    if (Set_prefetch_enable)
10520
    begin
10521
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10522
        $display(" - bursts can be performed!");
10523
    end
10524
    else
10525
    begin
10526
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10527
        $display(" - bursts can not be performed!");
10528
    end
10529
 
10530
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10531
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10532
    if ( ok !== 1 )
10533
    begin
10534
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10535
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10536
        disable main;
10537
    end
10538
 
10539
    // predict the address and control signals on WB bus
10540
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
10541
    expect_we      = 1'b1 ; // WRITE
10542
 
10543
    `else
10544
 
10545
    // address translation is not implemented
10546
    $display("Address translation is NOT implemented for PCI images!");
10547
    // set or clear pre-fetch enable
10548
    if (Set_prefetch_enable)
10549
    begin
10550
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10551
        $display(" - bursts can be performed!");
10552
    end
10553
    else
10554
    begin
10555
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10556
        $display(" - bursts can not be performed!");
10557
    end
10558
 
10559
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10560
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10561
    if ( ok !== 1 )
10562
    begin
10563
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10564
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10565
        disable main;
10566
    end
10567
 
10568
    // predict the address and control signals on WB bus
10569
    expect_address = Address ;
10570
    expect_we      = 1'b1 ; // WRITE
10571
 
10572
    `endif
10573
 
10574
    // set WB SLAVE parameters
10575
    if (Set_wb_wait_states)
10576
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
10577
    else
10578
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
10579
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
10580
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
10581
 
10582
    if ( Set_size > (`PCIW_DEPTH - 2) )
10583
    begin
10584
        expect_length_wr = `PCIW_DEPTH - 2 ;
10585
    end
10586
    else
10587
    begin
10588
        expect_length_wr = Set_size ;
10589
    end
10590
    // write through the PCI bridge to WB slave
10591
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
10592
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
10593
 
10594
    fork
10595
    begin
10596
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
10597
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
10598
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10599
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10600
        do_pause( 1 ) ;
10601
    end
10602
    begin
10603
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
10604
       if ( ok !== 1 )
10605
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10606
       else
10607
           test_ok ;
10608
    end
10609
    join
10610
 
10611
    // predict the address and control signals on WB bus
10612
    expect_we      = 1'b0 ; // READ
10613
 
10614
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
10615
    $display("Memory read through PCI bridge to WB slave!");
10616
 
10617
    if ( expect_length_wr == 1 )
10618
    begin
10619
        if (Set_prefetch_enable)
10620
        begin
10621
            expect_length_rd1 = Cache_lsize ;
10622
            expect_length_rd2 = 0 ;
10623
                // If PCI behavioral master must check received DATA
10624
                master2_check_received_data = 0 ;
10625
                    master1_check_received_data = 0 ;
10626
        end
10627
        else
10628
        begin
10629
            expect_length_rd1 = 1 ;
10630
            expect_length_rd2 = 0 ;
10631
                // If PCI behavioral master must check received DATA
10632
                master2_check_received_data = 1 ;
10633
                    master1_check_received_data = 1 ;
10634
        end
10635
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10636
        expect_length_rd  = expect_length_rd1 ;
10637
    end
10638
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
10639
    begin
10640
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10641
        expect_length_rd2 = 0 ;
10642
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10643
        expect_length_rd  = expect_length_rd1 ;
10644
                // If PCI behavioral master must check received DATA
10645
        master2_check_received_data = 1 ;
10646
            master1_check_received_data = 1 ;
10647
    end
10648
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
10649
    begin
10650
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10651
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
10652
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10653
        expect_length_rd  = expect_length_rd1 ;
10654
                // If PCI behavioral master must check received DATA
10655
                master2_check_received_data = 1 ;
10656
            master1_check_received_data = 1 ;
10657
    end
10658
    else
10659
    begin
10660
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10661
        begin
10662
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10663
            expect_length_rd2 = 0 ;
10664
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10665
            expect_length_rd  = expect_length_rd1 ;
10666
                // If PCI behavioral master must check received DATA
10667
                master2_check_received_data = 0 ;
10668
                    master1_check_received_data = 0 ;
10669
        end
10670
        else
10671
        begin
10672
            if ( expect_length_wr > Cache_lsize )
10673
            begin
10674
                expect_length_rd1 = Cache_lsize ;
10675
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
10676
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10677
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10678
                else
10679
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10680
                expect_length_rd  = expect_length_rd1 ;
10681
                        // If PCI behavioral master must check received DATA
10682
                        master2_check_received_data = 1 ;
10683
                            master1_check_received_data = 1 ;
10684
            end
10685
            else
10686
            begin
10687
                expect_length_rd1 = Cache_lsize ;
10688
                expect_length_rd2 = 0 ;
10689
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10690
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10691
                else
10692
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10693
                expect_length_rd  = expect_length_wr ;
10694
                                if ( expect_length_wr == Cache_lsize )
10695
                        begin
10696
                                // If PCI behavioral master must check received DATA
10697
                                master2_check_received_data = 1 ;
10698
                                    master1_check_received_data = 1 ;
10699
                                end
10700
                                else
10701
                                begin
10702
                                // If PCI behavioral master must check received DATA
10703
                                master2_check_received_data = 0 ;
10704
                                    master1_check_received_data = 0 ;
10705
                end
10706
            end
10707
        end
10708
    end
10709
 
10710
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
10711
    expect_rd_address = expect_address ;
10712
    rd_data[31:0] = Data[31:0];
10713
    rd_be[3:0] = Be[3:0];
10714
 
10715
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
10716
    while (expect_length_rd2 > 0)
10717
    begin
10718
        // do read
10719
        $display("Read %d words!", expect_length_rd);
10720
 
10721
        fork
10722
        begin
10723
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10724
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10725
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10726
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10727
 
10728
            wb_transaction_stop( expect_length_rd - 1) ;
10729
 
10730
            do_pause( 1 ) ;
10731
        end
10732
        begin
10733
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10734
            if ( ok !== 1 )
10735
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
10736
 
10737
            repeat( 3 )
10738
                @(posedge pci_clock) ;
10739
 
10740
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10741
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10742
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10743
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10744
 
10745
            do_pause( 1 ) ;
10746
            while ( FRAME === 0 )
10747
                @(posedge pci_clock) ;
10748
 
10749
            while ( IRDY === 0 )
10750
                @(posedge pci_clock) ;
10751
 
10752 35 mihad
            #1 ;
10753
            if ( !error_monitor_done )
10754
                disable monitor_error_event1 ;
10755 15 mihad
        end
10756
        begin:monitor_error_event1
10757 35 mihad
            error_monitor_done = 0 ;
10758 15 mihad
            @(error_event_int) ;
10759
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10760
            ok = 0 ;
10761 35 mihad
            error_monitor_done = 1 ;
10762 15 mihad
        end
10763
        join
10764
 
10765
        // increasing the starting address for PCI master and for WB transaction monitor
10766
        rd_address = rd_address + (4 * expect_length_rd) ;
10767
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
10768
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
10769
        rd_data[31:24] = Data[31:24] + expect_length_rd;
10770
        rd_data[23:16] = Data[23:16] + expect_length_rd;
10771
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
10772
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
10773
        for (i=0; i<expect_length_rd; i=i+1)
10774
            rd_be[3:0] = {Be[2:0], Be[3]};
10775
 
10776
        // set parameters for next read
10777
        if ( expect_length_rd2 == 1 )
10778
        begin
10779
                if (Set_prefetch_enable)
10780
                begin
10781
                    expect_length_rd1 = Cache_lsize ;
10782
                    expect_length_rd2 = 0 ;
10783
                        // If PCI behavioral master must check received DATA
10784
                        master2_check_received_data = 0 ;
10785
                            master1_check_received_data = 0 ;
10786
                end
10787
                else
10788
                begin
10789
                    expect_length_rd1 = 1 ;
10790
                    expect_length_rd2 = 0 ;
10791
                        // If PCI behavioral master must check received DATA
10792
                        master2_check_received_data = 1 ;
10793
                            master1_check_received_data = 1 ;
10794
                end
10795
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10796
            expect_length_rd  = expect_length_rd1 ;
10797
        end
10798
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
10799
        begin
10800
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10801
            expect_length_rd2 = 0 ;
10802
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10803
            expect_length_rd  = expect_length_rd1 ;
10804
                        // If PCI behavioral master must check received DATA
10805
                        master2_check_received_data = 1 ;
10806
                    master1_check_received_data = 1 ;
10807
        end
10808
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
10809
        begin
10810
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10811
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
10812
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10813
            expect_length_rd  = expect_length_rd1 ;
10814
                        // If PCI behavioral master must check received DATA
10815
                        master2_check_received_data = 1 ;
10816
                    master1_check_received_data = 1 ;
10817
        end
10818
        else
10819
        begin
10820
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10821
            begin
10822
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
10823
                expect_length_rd2 = 0 ;
10824
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10825
                expect_length_rd  = expect_length_rd1 ;
10826
                        // If PCI behavioral master must check received DATA
10827
                        master2_check_received_data = 0 ;
10828
                            master1_check_received_data = 0 ;
10829
            end
10830
            else
10831
            begin
10832
                if ( expect_length_rd2 > Cache_lsize )
10833
                begin
10834
                    expect_length_rd1 = Cache_lsize ;
10835
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
10836
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10837
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10838
                    else
10839
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10840
                    expect_length_rd  = expect_length_rd1 ;
10841
                                // If PCI behavioral master must check received DATA
10842
                                master2_check_received_data = 1 ;
10843
                                    master1_check_received_data = 1 ;
10844
                end
10845
                else
10846
                begin
10847
                    expect_length_rd  = expect_length_rd2 ;
10848
                    expect_length_rd1 = Cache_lsize ;
10849
                    expect_length_rd2 = 0 ;
10850
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10851
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10852
                    else
10853
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10854
                                        if ( expect_length_rd2 == Cache_lsize )
10855
                                begin
10856
                                        // If PCI behavioral master must check received DATA
10857
                                        master2_check_received_data = 1 ;
10858
                                            master1_check_received_data = 1 ;
10859
                                        end
10860
                                        else
10861
                                        begin
10862
                                        // If PCI behavioral master must check received DATA
10863
                                        master2_check_received_data = 0 ;
10864
                                            master1_check_received_data = 0 ;
10865
                        end
10866
                end
10867
            end
10868
        end
10869
    end
10870
    // do last read
10871
    $display("Read %d words!", expect_length_rd);
10872
 
10873
    fork
10874
    begin
10875
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10876
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10877
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10878
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10879
 
10880
        wb_transaction_stop(expect_length_rd - 1) ;
10881
        do_pause( 1 ) ;
10882
    end
10883
    begin
10884
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10885
 
10886
        do_pause(3) ;
10887
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10888
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10889
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10890
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10891
        do_pause(1) ;
10892
 
10893
        while ( FRAME === 0 )
10894
            @(posedge pci_clock) ;
10895
 
10896
        while ( IRDY === 0 )
10897
            @(posedge pci_clock) ;
10898
 
10899 35 mihad
        #1 ;
10900
        if ( !error_monitor_done )
10901
            disable monitor_error_event2 ;
10902 15 mihad
    end
10903
    begin:monitor_error_event2
10904 35 mihad
        error_monitor_done = 0 ;
10905 15 mihad
        @(error_event_int) ;
10906
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10907
        ok = 0 ;
10908 35 mihad
        error_monitor_done = 1 ;
10909 15 mihad
    end
10910
    join
10911
 
10912
    if ( ok )
10913
        test_ok ;
10914
 
10915
    // Check that no ERRORs were reported
10916
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
10917
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
10918
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10919
    config_read( addr_offset, 4'hF, read_data ) ;
10920
    if ( read_data[8] !== 0 )
10921
    begin
10922
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
10923
        test_fail("error status was set even though no errors occured on WB bus") ;
10924
    end
10925
    else
10926
    begin
10927
        $display("No error was signaled, as expected!");
10928
        test_ok ;
10929
    end
10930
 
10931
end // main
10932
endtask // test_normal_wr_rd
10933
 
10934
// Test erroneous write to WB slave
10935
task test_wb_error_wr;
10936
  input  [2:0]  Master_ID;
10937
  input  [PCI_BUS_DATA_RANGE:0] Address;
10938
  input  [PCI_BUS_DATA_RANGE:0] Data;
10939
  input  [3:0]  Be;
10940
  input  [2:0]  Image_num;
10941
  input  [9:0]  Set_size;
10942
  input         Set_err_and_int_report;
10943
  input         Set_wb_wait_states;
10944
  input  [1:0]  Imm_BefLast_Last_error;
10945
 
10946
  reg    [11:0] addr_offset;
10947
  reg    [31:0] read_data;
10948
  reg           continue ;
10949
  reg           ok   ;
10950
  reg    [9:0]  expect_length ;
10951
  reg    [31:0] expect_address ;
10952
  reg    [0:0]  expect_we ;
10953
  reg    [31:0] rd_address;
10954
  reg    [31:0] rd_data;
10955
  reg    [3:0]  rd_be;
10956
  integer       i ;
10957
begin:main
10958
    if (Set_err_and_int_report)
10959
    begin
10960
        // enable ERROR reporting, because error must be reported and interrupt if required!
10961
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10962
        $display(" - errors will be reported when they will occur!");
10963
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
10964
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10965
        $display(" - interrupt will be reported when error will occur!");
10966
    end
10967
    else
10968
    begin
10969
        // disable ERROR reporting, because error and interrupt must not be reported!
10970
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10971
        $display(" - errors will NOT be reported when they will occur!");
10972
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
10973
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10974
        $display(" - interrupt will NOT be reported when error will occur!");
10975
    end
10976
    // enable/disable ERROR reporting
10977
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
10978
 
10979
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10980
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
10981
    if ( ok !== 1 )
10982
    begin
10983
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10984
        test_fail("PCI Error Control and Status register could not be written") ;
10985
        disable main;
10986
    end
10987
    // enable/disable INTERRUPT reporting
10988
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
10989
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
10990
    if ( ok !== 1 )
10991
    begin
10992
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
10993
        test_fail("Interrupt Control register could not be written") ;
10994
        disable main;
10995
    end
10996
 
10997
    `ifdef  ADDR_TRAN_IMPL
10998
 
10999
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
11000
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
11001
    config_read( addr_offset, 4'hF, read_data ) ;
11002
    if ( read_data[2] !== 0 )
11003
    begin
11004
        $display("Address translation is set for PCI image%d!", Image_num);
11005
        // predict the address and control signals on WB bus
11006
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
11007
        expect_we      = 1'b1 ; // WRITE
11008
    end
11009
    else
11010
    begin
11011
        $display("Address translation is NOT set for PCI image%d!", Image_num);
11012
        // predict the address and control signals on WB bus
11013
        expect_address = Address ;
11014
        expect_we      = 1'b1 ; // WRITE
11015
    end
11016
 
11017
    `else
11018
 
11019
    // address translation is not implemented
11020
    $display("Address translation is NOT implemented for PCI images!");
11021
    // predict the address and control signals on WB bus
11022
    expect_address = Address ;
11023
    expect_we      = 1'b1 ; // WRITE
11024
 
11025
    `endif
11026
 
11027
    if ( Set_size > (`PCIW_DEPTH - 2) )
11028
    begin
11029
        expect_length = `PCIW_DEPTH - 2 ;
11030
    end
11031
    else
11032
    begin
11033
        expect_length = Set_size ;
11034
    end
11035
 
11036
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11037
    begin
11038
        $display("ERR termination with first data!");
11039
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
11040
    end
11041
    else if (Imm_BefLast_Last_error == 1)
11042
    begin
11043
        $display("ERR termination before last data!");
11044
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
11045
    end
11046
    else
11047
    begin
11048
        $display("ERR termination with last data!");
11049
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
11050
    end
11051
 
11052
    // write through the PCI bridge to WB slave
11053
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
11054
    fork
11055
    begin
11056
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
11057
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
11058
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11059
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
11060
        do_pause( 1 ) ;
11061
    end
11062
    begin
11063
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11064
        begin
11065
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
11066
            if ( ok !== 1 )
11067
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11068
        end
11069
        else if (Imm_BefLast_Last_error == 1)
11070
        begin
11071
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
11072
            if ( ok !== 1 )
11073
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11074
        end
11075
        else
11076
        begin
11077
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
11078
            if ( ok !== 1 )
11079
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11080
        end
11081
    end
11082
    begin
11083
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11084
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11085
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11086
        else if (Imm_BefLast_Last_error == 1)
11087
        begin
11088
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
11089
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11090
            wb_transaction_stop(expect_length-2) ;
11091
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11092
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11093
        end
11094
        else
11095
        begin
11096
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
11097
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11098
            wb_transaction_stop(expect_length-1) ;
11099
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11100
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11101
        end
11102
    end
11103
    join
11104
 
11105
    if ( ok )
11106
        test_ok ;
11107
 
11108
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11109
    begin
11110
        rd_data[31:0] = Data[31:0];
11111
        rd_address[31:0] = expect_address;
11112
        rd_be[3:0] = Be[3:0];
11113
    end
11114
    else if (Imm_BefLast_Last_error == 1)
11115
    begin
11116
        rd_data[31:24] = Data[31:24] + expect_length - 2;
11117
        rd_data[23:16] = Data[23:16] + expect_length - 2;
11118
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
11119
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
11120
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
11121
        rd_be[3:0] = Be[3:0];
11122
        for (i=0; i<(expect_length-2); i=i+1)
11123
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11124
    end
11125
    else
11126
    begin
11127
        rd_data[31:24] = Data[31:24] + expect_length - 1;
11128
        rd_data[23:16] = Data[23:16] + expect_length - 1;
11129
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
11130
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
11131
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
11132
        rd_be[3:0] = Be[3:0];
11133
        for (i=0; i<(expect_length-1); i=i+1)
11134
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11135
    end
11136
 
11137
    master2_check_received_data = 0 ;
11138
    master1_check_received_data = 0 ;
11139
 
11140
    // Check if ERRORs were reported
11141
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
11142
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11143
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
11144
 
11145
    ok = 1 ;
11146
    config_read( addr_offset, 4'hF, read_data ) ;
11147
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
11148
    begin
11149
        $display("Error was signaled and reported, as expected!");
11150
        if (read_data[31:28] === rd_be)
11151
            $display("Byte enables written into P_ERR_CS register are as expected!");
11152
        else
11153
        begin
11154
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
11155
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
11156
            ok = 0 ;
11157
        end
11158
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
11159
            $display("Bus command written into P_ERR_CS register is as expected!");
11160
        else
11161
        begin
11162
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
11163
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
11164
            ok = 0 ;
11165
        end
11166
 
11167
        if ( ok )
11168
            test_ok ;
11169
 
11170
        $display("Reading the PCI Error Data register P_ERR_DATA.");
11171
 
11172
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11173
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
11174
        config_read( addr_offset, 4'hF, read_data ) ;
11175
        if (read_data === rd_data)
11176
        begin
11177
            $display("Data written into P_ERR_DATA register is as expected!");
11178
            test_ok ;
11179
        end
11180
        else
11181
        begin
11182
            $display("Data written into P_ERR_DATA register is NOT as expected!");
11183
            test_fail("PCI Erroneous Data register value was wrong") ;
11184
        end
11185
 
11186
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
11187
 
11188
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11189
 
11190
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
11191
        config_read( addr_offset, 4'hF, read_data ) ;
11192
        if (read_data === rd_address)
11193
        begin
11194
            $display("Address written into P_ERR_ADDR register is as expected!");
11195
            test_ok ;
11196
        end
11197
        else
11198
        begin
11199
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
11200
            test_fail("PCI Erroneous Address register value was wrong") ;
11201
        end
11202
    end
11203
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
11204
    begin
11205
        $display("Error was signaled and not reported, as expected!");
11206
        test_ok ;
11207
    end
11208
    else
11209
    begin
11210
        $display("Error was signaled and reported, as NOT expected!");
11211
        test_fail("Error status bit was set event though error reporting was disabled") ;
11212
    end
11213
 
11214
    // Check if Interrupts were reported
11215
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
11216
 
11217
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11218
    ok = 1 ;
11219
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11220
    config_read( addr_offset, 4'hF, read_data ) ;
11221
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
11222
    begin
11223
        $display("Interrupts was signaled and reported, as expected!");
11224
    end
11225
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
11226
    begin
11227
        $display("Interrupts was signaled and not reported, as expected!");
11228
    end
11229
    else
11230
    begin
11231
        $display("Interrupt was signaled and reported, as NOT expected!");
11232
        test_fail("PCI Error Interrupt status was set when not expected") ;
11233
        ok = 0 ;
11234
    end
11235
 
11236
    `ifdef HOST
11237
    repeat( 4 )
11238
        @(posedge wb_clock) ;
11239
 
11240
    if ( INT_O === Set_err_and_int_report )
11241
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
11242
    else
11243
    begin
11244
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
11245
        test_fail("Interrupt request didn't have expected value") ;
11246
        ok = 0 ;
11247
    end
11248
 
11249
    `else // GUEST
11250
    repeat( 4 )
11251
        @(posedge pci_clock) ;
11252
 
11253
    if ( INTA === !Set_err_and_int_report )
11254
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
11255
    else
11256
    begin
11257
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
11258
        test_fail("Interrupt request didn't have expected value") ;
11259
        ok = 0 ;
11260
    end
11261
 
11262
    `endif
11263
 
11264
    if ( ok )
11265
        test_ok ;
11266
 
11267
    if (Set_err_and_int_report)
11268
    begin
11269
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11270
        $display("Error and Interrupt must be cleared!");
11271
        // clear  ERROR reporting bit
11272
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11273
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
11274
        if ( ok !== 1 )
11275
        begin
11276
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11277
            test_fail("PCI Error Control and Status register could not be written to") ;
11278
            disable main;
11279
        end
11280
 
11281
        // clear INTERRUPT reporting bit
11282
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11283
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
11284
        if ( ok !== 1 )
11285
        begin
11286
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
11287
            test_fail("Interrupt Status register could not be written to") ;
11288
            disable main;
11289
        end
11290
 
11291
        test_ok ;
11292
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
11293
        `ifdef HOST
11294
 
11295
        repeat(4)
11296
            @(posedge wb_clock) ;
11297
        if ( INT_O === 1'b0 )
11298
        begin
11299
            $display("Interrupt pin INT_O was correctly cleared!");
11300
            test_ok ;
11301
        end
11302
        else
11303
        begin
11304
            $display("Interrupt pin INT_O was NOT correctly cleared!");
11305
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11306
            disable main;
11307
        end
11308
 
11309
        `else // GUEST
11310
 
11311
        repeat(4)
11312
            @(posedge pci_clock) ;
11313
        if ( INTA === 1'b1 )
11314
        begin
11315
            $display("Interrupt pin INTA was correctly cleared!");
11316
            test_ok ;
11317
        end
11318
        else
11319
        begin
11320
            $display("Interrupt pin INTA was NOT correctly cleared!");
11321
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11322
            disable main;
11323
        end
11324
 
11325
        `endif
11326
 
11327
    end
11328
    else
11329
    begin
11330
        $display("Error and Interrupt don't need to be cleared!");
11331
    end
11332
end // main
11333
endtask // test_wb_error_wr
11334
 
11335
task test_wb_error_rd;
11336
    reg    [11:0] addr_offset ;
11337
    reg    [11:0] ctrl_offset ;
11338
    reg    [11:0] ba_offset ;
11339
    reg    [11:0] am_offset ;
11340
    reg    [11:0] ta_offset ;
11341
    reg    [31:0] read_data;
11342
    reg           ok   ;
11343
    reg    [9:0]  expect_length ;
11344
    reg    [31:0] expect_address ;
11345
    reg    [0:0]  expect_we ;
11346
    reg    [31:0] rd_address;
11347
    reg    [31:0] rd_data;
11348
    reg    [3:0]  rd_be;
11349
    integer       i ;
11350
    reg           do_mem_aborts ;
11351
    reg           do_io_aborts ;
11352 35 mihad
    reg           error_monitor_done ;
11353 15 mihad
begin:main
11354
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
11355
 
11356
    if ( target_mem_image !== -1 )
11357
    begin
11358
        do_mem_aborts = 1 ;
11359
 
11360
        if (target_mem_image === 1)
11361
        begin
11362
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
11363
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
11364
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
11365
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
11366
        end
11367
        else if (target_mem_image === 2)
11368
        begin
11369
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
11370
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
11371
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
11372
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
11373
        end
11374
        else if (target_mem_image === 3)
11375
        begin
11376
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
11377
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
11378
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
11379
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
11380
        end
11381
        else if (target_mem_image === 4)
11382
        begin
11383
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
11384
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
11385
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
11386
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
11387
        end
11388
        else if (target_mem_image === 5)
11389
        begin
11390
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
11391
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
11392
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
11393
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
11394
        end
11395
    end
11396
    else
11397
        do_mem_aborts = 0 ;
11398
 
11399
    if ( do_mem_aborts )
11400
    begin
11401
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
11402
 
11403
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11404
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
11405
        if ( ok !== 1 )
11406
        begin
11407
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11408
            test_fail("PCI Error Control and Status register could not be written") ;
11409
            disable main;
11410
        end
11411
 
11412
        // enable INTERRUPT reporting
11413
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
11414
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
11415
        if ( ok !== 1 )
11416
        begin
11417
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
11418
            test_fail("Interrupt Control register could not be written") ;
11419
            disable main;
11420
        end
11421
 
11422
        addr_offset = 12'h010 + (4*target_mem_image) ;
11423
 
11424
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
11425
        if ( ok !== 1 )
11426
        begin
11427
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
11428
            test_fail("PCI Base Address register could not be written") ;
11429
            disable main;
11430
        end
11431
 
11432
        // disable address translation and enable prefetch so read bursts can be performed
11433
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
11434
        if ( ok !== 1 )
11435
        begin
11436
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
11437
            test_fail("PCI Image Control register could not be written") ;
11438
            disable main;
11439
        end
11440
 
11441
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
11442
        if ( ok !== 1 )
11443
        begin
11444
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
11445
            test_fail("PCI Address Mask register could not be written") ;
11446
            disable main;
11447
        end
11448
 
11449
        addr_offset = 12'h00C ;
11450
 
11451
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
11452
        if ( ok !== 1 )
11453
        begin
11454
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
11455
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
11456
            disable main;
11457
        end
11458
 
11459
        // disable PCI master data checking
11460
        master1_check_received_data = 0 ;
11461
 
11462
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11463
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11464
 
11465
 
11466
        // do a single read error terminated on WB bus
11467
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
11468
 
11469
        fork
11470
        begin
11471
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11472
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11473
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11474
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
11475
 
11476
            do_pause( 1 ) ;
11477
        end
11478
        begin
11479
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11480
 
11481
            if ( ok !== 1 )
11482
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11483
 
11484
            do_pause(3) ;
11485
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11486
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11487
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11488
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11489
            do_pause(1) ;
11490
 
11491
            while ( FRAME === 0 )
11492
                @(posedge pci_clock) ;
11493
 
11494
            while ( IRDY === 0 )
11495
                @(posedge pci_clock) ;
11496
 
11497 35 mihad
            #1 ;
11498
            if ( !error_monitor_done )
11499
                disable monitor_error_event1 ;
11500 15 mihad
        end
11501
        begin:monitor_error_event1
11502 35 mihad
            error_monitor_done = 0 ;
11503 15 mihad
            @(error_event_int) ;
11504
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11505
            ok = 0 ;
11506 35 mihad
            error_monitor_done = 1 ;
11507 15 mihad
        end
11508
        join
11509
 
11510
        if ( ok )
11511
            test_ok ;
11512 26 mihad
 
11513
        @(posedge pci_clock) ;
11514
        @(posedge pci_clock) ;
11515
        @(posedge wb_clock) ;
11516
        @(posedge wb_clock) ;
11517 15 mihad
 
11518
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11519
        addr_offset = 12'h004 ;
11520
        config_read(addr_offset, 4'hF, read_data) ;
11521
        ok = 1 ;
11522
        if ( read_data[27] !== 1 )
11523
        begin
11524
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11525
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11526
            ok = 0 ;
11527
        end
11528
        if ( read_data[28] !== 0 )
11529
        begin
11530
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11531
            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") ;
11532
            ok = 0 ;
11533
        end
11534
        if ( read_data[29] !== 0 )
11535
        begin
11536
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11537
            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") ;
11538
            ok = 0 ;
11539
        end
11540
 
11541
        // clear statuses
11542
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11543
        if ( !ok )
11544
        begin
11545
            test_fail("write to PCI Device Status register failed") ;
11546
            $display("Couldn't write PCI Device Status register") ;
11547
            disable main ;
11548
        end
11549
 
11550
        if ( ok )
11551
            test_ok ;
11552
 
11553
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11554
 
11555
        ok = 1 ;
11556
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11557
 
11558
        config_read(addr_offset, 4'hF, read_data) ;
11559
        if (read_data[8] !== 0)
11560
        begin
11561
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11562
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11563
            ok = 0 ;
11564
        end
11565
        else
11566
            test_ok ;
11567
 
11568
        if ( ok !== 1 )
11569
        begin
11570
            config_write(addr_offset, read_data, 4'hF, ok) ;
11571
            if ( !ok )
11572
            begin
11573
                test_fail("PCI Error Control and Status register could not be written") ;
11574
                disable main ;
11575
            end
11576
        end
11577
 
11578
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11579
        fork
11580
        begin
11581
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11582
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11583
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11584
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11585
 
11586
            do_pause( 1 ) ;
11587
        end
11588
        begin
11589
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11590
 
11591
            if ( ok !== 1 )
11592
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11593
 
11594
            do_pause(3) ;
11595
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11596
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11597
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11598
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11599
            do_pause(1) ;
11600
 
11601
            while ( FRAME === 0 )
11602
                @(posedge pci_clock) ;
11603
 
11604
            while ( IRDY === 0 )
11605
                @(posedge pci_clock) ;
11606
 
11607 35 mihad
            #1 ;
11608
            if ( !error_monitor_done )
11609
                disable monitor_error_event2 ;
11610 15 mihad
        end
11611
        begin:monitor_error_event2
11612 35 mihad
            error_monitor_done = 0 ;
11613 15 mihad
            @(error_event_int) ;
11614
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11615
            ok = 0 ;
11616 35 mihad
            error_monitor_done = 1 ;
11617 15 mihad
        end
11618
        join
11619
 
11620
        if ( ok )
11621
            test_ok ;
11622
 
11623 26 mihad
        @(posedge pci_clock) ;
11624
        @(posedge pci_clock) ;
11625
        @(posedge wb_clock) ;
11626
        @(posedge wb_clock) ;
11627
 
11628 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11629
        addr_offset = 12'h004 ;
11630
        config_read(addr_offset, 4'hF, read_data) ;
11631
        ok = 1 ;
11632
        if ( read_data[27] !== 1 )
11633
        begin
11634
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11635
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11636
            ok = 0 ;
11637
        end
11638
        if ( read_data[28] !== 0 )
11639
        begin
11640
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11641
            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") ;
11642
            ok = 0 ;
11643
        end
11644
        if ( read_data[29] !== 0 )
11645
        begin
11646
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11647
            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") ;
11648
            ok = 0 ;
11649
        end
11650
 
11651
        // clear statuses
11652
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11653
        if ( !ok )
11654
        begin
11655
            test_fail("write to PCI Device Status register failed") ;
11656
            $display("Couldn't write PCI Device Status register") ;
11657
            disable main ;
11658
        end
11659
 
11660
        if ( ok )
11661
            test_ok ;
11662
 
11663
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11664
 
11665
        ok = 1 ;
11666
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11667
 
11668
        config_read(addr_offset, 4'hF, read_data) ;
11669
        if (read_data[8] !== 0)
11670
        begin
11671
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11672
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11673
            ok = 0 ;
11674
        end
11675
        else
11676
            test_ok ;
11677
 
11678
        if ( ok !== 1 )
11679
        begin
11680
            config_write(addr_offset, read_data, 4'hF, ok) ;
11681
            if ( !ok )
11682
            begin
11683
                test_fail("PCI Error Control and Status register could not be written") ;
11684
                disable main ;
11685
            end
11686
        end
11687
 
11688
        // do a single read error terminated on WB bus
11689
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
11690
 
11691
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11692
 
11693
        fork
11694
        begin
11695
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11696
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11697
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11698
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11699
 
11700
            do_pause( 1 ) ;
11701
        end
11702
        begin
11703
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11704
 
11705
            if ( ok !== 1 )
11706
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11707
 
11708
            do_pause(3) ;
11709
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11710
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11711
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11712
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11713
            do_pause(1) ;
11714
 
11715
            while ( FRAME === 0 )
11716
                @(posedge pci_clock) ;
11717
 
11718
            while ( IRDY === 0 )
11719
                @(posedge pci_clock) ;
11720
 
11721 35 mihad
            if ( !error_monitor_done )
11722
                disable monitor_error_event3 ;
11723 15 mihad
        end
11724
        begin:monitor_error_event3
11725 35 mihad
            error_monitor_done = 0 ;
11726 15 mihad
            @(error_event_int) ;
11727
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11728
            ok = 0 ;
11729 35 mihad
            error_monitor_done = 1 ;
11730 15 mihad
        end
11731
        join
11732
 
11733
        if ( ok )
11734
            test_ok ;
11735
 
11736 26 mihad
        @(posedge pci_clock) ;
11737
        @(posedge pci_clock) ;
11738
        @(posedge wb_clock) ;
11739
        @(posedge wb_clock) ;
11740
 
11741 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11742
        addr_offset = 12'h004 ;
11743
        config_read(addr_offset, 4'hF, read_data) ;
11744
        ok = 1 ;
11745
        if ( read_data[27] !== 1 )
11746
        begin
11747
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11748
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11749
            ok = 0 ;
11750
        end
11751
        if ( read_data[28] !== 0 )
11752
        begin
11753
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11754
            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") ;
11755
            ok = 0 ;
11756
        end
11757
        if ( read_data[29] !== 0 )
11758
        begin
11759
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11760
            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") ;
11761
            ok = 0 ;
11762
        end
11763
 
11764
        // clear statuses
11765
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11766
        if ( !ok )
11767
        begin
11768
            test_fail("write to PCI Device Status register failed") ;
11769
            $display("Couldn't write PCI Device Status register") ;
11770
            disable main ;
11771
        end
11772
 
11773
        if ( ok )
11774
            test_ok ;
11775
 
11776
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11777
 
11778
        ok = 1 ;
11779
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11780
 
11781
        config_read(addr_offset, 4'hF, read_data) ;
11782
        if (read_data[8] !== 0)
11783
        begin
11784
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11785
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11786
            ok = 0 ;
11787
        end
11788
        else
11789
            test_ok ;
11790
 
11791
        if ( ok !== 1 )
11792
        begin
11793
            config_write(addr_offset, read_data, 4'hF, ok) ;
11794
            if ( !ok )
11795
            begin
11796
                test_fail("PCI Error Control and Status register could not be written") ;
11797
                disable main ;
11798
            end
11799
        end
11800
 
11801
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
11802
 
11803
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11804
 
11805
        fork
11806
        begin
11807
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11808
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11809
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11810
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11811
 
11812
            do_pause( 1 ) ;
11813
        end
11814
        begin
11815
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
11816
 
11817
            if ( ok !== 1 )
11818
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11819
 
11820
            do_pause(3) ;
11821
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11822
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11823
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11824
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11825
            do_pause(1) ;
11826
 
11827
            while ( FRAME === 0 )
11828
                @(posedge pci_clock) ;
11829
 
11830
            while ( IRDY === 0 )
11831
                @(posedge pci_clock) ;
11832
 
11833 35 mihad
            #1 ;
11834
            if ( !error_monitor_done )
11835
                disable monitor_error_event4 ;
11836 15 mihad
        end
11837
        begin:monitor_error_event4
11838 35 mihad
            error_monitor_done = 0 ;
11839 15 mihad
            @(error_event_int) ;
11840
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11841
            ok = 0 ;
11842 35 mihad
            error_monitor_done = 1 ;
11843 15 mihad
        end
11844
        begin
11845
            wb_transaction_stop( 1 ) ;
11846
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11847
        end
11848
        join
11849
 
11850
        if ( ok )
11851
            test_ok ;
11852
 
11853 26 mihad
        @(posedge pci_clock) ;
11854
        @(posedge pci_clock) ;
11855
        @(posedge wb_clock) ;
11856
        @(posedge wb_clock) ;
11857
 
11858 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11859
        addr_offset = 12'h004 ;
11860
        config_read(addr_offset, 4'hF, read_data) ;
11861
        ok = 1 ;
11862
        if ( read_data[27] !== 1 )
11863
        begin
11864
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11865
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11866
            ok = 0 ;
11867
        end
11868
        if ( read_data[28] !== 0 )
11869
        begin
11870
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11871
            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") ;
11872
            ok = 0 ;
11873
        end
11874
        if ( read_data[29] !== 0 )
11875
        begin
11876
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11877
            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") ;
11878
            ok = 0 ;
11879
        end
11880
 
11881
        // clear statuses
11882
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11883
        if ( !ok )
11884
        begin
11885
            test_fail("write to PCI Device Status register failed") ;
11886
            $display("Couldn't write PCI Device Status register") ;
11887
            disable main ;
11888
        end
11889
 
11890
        if ( ok )
11891
            test_ok ;
11892
 
11893
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11894
 
11895
        ok = 1 ;
11896
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11897
 
11898
        config_read(addr_offset, 4'hF, read_data) ;
11899
        if (read_data[8] !== 0)
11900
        begin
11901
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11902
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11903
            ok = 0 ;
11904
        end
11905
        else
11906
            test_ok ;
11907
 
11908
        if ( ok !== 1 )
11909
        begin
11910
            config_write(addr_offset, read_data, 4'hF, ok) ;
11911
            if ( !ok )
11912
            begin
11913
                test_fail("PCI Error Control and Status register could not be written") ;
11914
                disable main ;
11915
            end
11916
        end
11917
 
11918
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
11919
 
11920
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11921
 
11922
        fork
11923
        begin
11924
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11925
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11926
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11927
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11928
 
11929
            do_pause( 1 ) ;
11930
        end
11931
        begin
11932
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11933
 
11934
            if ( ok !== 1 )
11935
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11936
 
11937
            do_pause(3) ;
11938
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11939
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11940
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11941
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11942
            do_pause(1) ;
11943
 
11944
            while ( FRAME === 0 )
11945
                @(posedge pci_clock) ;
11946
 
11947
            while ( IRDY === 0 )
11948
                @(posedge pci_clock) ;
11949
 
11950 35 mihad
            #1 ;
11951
            if ( !error_monitor_done )
11952
                disable monitor_error_event5 ;
11953 15 mihad
        end
11954
        begin:monitor_error_event5
11955 35 mihad
            error_monitor_done = 0 ;
11956 15 mihad
            @(error_event_int) ;
11957
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11958
            ok = 0 ;
11959 35 mihad
            error_monitor_done = 1 ;
11960 15 mihad
        end
11961
        begin
11962
            wb_transaction_stop( 3 ) ;
11963
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11964
        end
11965
        join
11966
 
11967
        if ( ok )
11968
            test_ok ;
11969
 
11970 26 mihad
        @(posedge pci_clock) ;
11971
        @(posedge pci_clock) ;
11972
        @(posedge wb_clock) ;
11973
        @(posedge wb_clock) ;
11974
 
11975 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11976
        addr_offset = 12'h004 ;
11977
        config_read(addr_offset, 4'hF, read_data) ;
11978
        ok = 1 ;
11979
        if ( read_data[27] !== 1 )
11980
        begin
11981
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11982
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11983
            ok = 0 ;
11984
        end
11985
        if ( read_data[28] !== 0 )
11986
        begin
11987
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11988
            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") ;
11989
            ok = 0 ;
11990
        end
11991
        if ( read_data[29] !== 0 )
11992
        begin
11993
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11994
            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") ;
11995
            ok = 0 ;
11996
        end
11997
 
11998
        // clear statuses
11999
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12000
        if ( !ok )
12001
        begin
12002
            test_fail("write to PCI Device Status register failed") ;
12003
            $display("Couldn't write PCI Device Status register") ;
12004
            disable main ;
12005
        end
12006
 
12007
        if ( ok )
12008
            test_ok ;
12009
 
12010
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12011
 
12012
        ok = 1 ;
12013
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12014
 
12015
        config_read(addr_offset, 4'hF, read_data) ;
12016
        if (read_data[8] !== 0)
12017
        begin
12018
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12019
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12020
            ok = 0 ;
12021
        end
12022
        else
12023
            test_ok ;
12024
 
12025
        if ( ok !== 1 )
12026
        begin
12027
            config_write(addr_offset, read_data, 4'hF, ok) ;
12028
            if ( !ok )
12029
            begin
12030
                test_fail("PCI Error Control and Status register could not be written") ;
12031
                disable main ;
12032
            end
12033
        end
12034
 
12035
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
12036
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12037
        fork
12038
        begin
12039
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12040
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12041
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12042
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12043
 
12044
            do_pause( 1 ) ;
12045
        end
12046
        begin
12047
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
12048
 
12049
            if ( ok !== 1 )
12050
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12051
 
12052
            do_pause(3) ;
12053
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12054
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12055
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12056
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
12057
            do_pause(1) ;
12058
 
12059
            while ( FRAME === 0 )
12060
                @(posedge pci_clock) ;
12061
 
12062
            while ( IRDY === 0 )
12063
                @(posedge pci_clock) ;
12064
 
12065 35 mihad
            #1 ;
12066
            if ( !error_monitor_done )
12067
                disable monitor_error_event6 ;
12068 15 mihad
        end
12069
        begin:monitor_error_event6
12070 35 mihad
            error_monitor_done = 0 ;
12071 15 mihad
            @(error_event_int) ;
12072
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12073
            ok = 0 ;
12074 35 mihad
            error_monitor_done = 1 ;
12075 15 mihad
        end
12076
        begin
12077
            wb_transaction_stop( 3 ) ;
12078
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12079
        end
12080
        join
12081
 
12082
        if ( ok )
12083
            test_ok ;
12084
 
12085 26 mihad
        @(posedge pci_clock) ;
12086
        @(posedge pci_clock) ;
12087
        @(posedge wb_clock) ;
12088
        @(posedge wb_clock) ;
12089
 
12090 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12091
        addr_offset = 12'h004 ;
12092
        config_read(addr_offset, 4'hF, read_data) ;
12093
        ok = 1 ;
12094
        if ( read_data[27] !== 1 )
12095
        begin
12096
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12097
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12098
            ok = 0 ;
12099
        end
12100
        if ( read_data[28] !== 0 )
12101
        begin
12102
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12103
            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") ;
12104
            ok = 0 ;
12105
        end
12106
        if ( read_data[29] !== 0 )
12107
        begin
12108
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12109
            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") ;
12110
            ok = 0 ;
12111
        end
12112
 
12113
        // clear statuses
12114
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12115
        if ( !ok )
12116
        begin
12117
            test_fail("write to PCI Device Status register failed") ;
12118
            $display("Couldn't write PCI Device Status register") ;
12119
            disable main ;
12120
        end
12121
 
12122
        if ( ok )
12123
            test_ok ;
12124
 
12125
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12126
 
12127
        ok = 1 ;
12128
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12129
 
12130
        config_read(addr_offset, 4'hF, read_data) ;
12131
        if (read_data[8] !== 0)
12132
        begin
12133
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12134
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12135
            ok = 0 ;
12136
        end
12137
        else
12138
            test_ok ;
12139
 
12140
        if ( ok !== 1 )
12141
        begin
12142
            config_write(addr_offset, read_data, 4'hF, ok) ;
12143
            if ( !ok )
12144
            begin
12145
                test_fail("PCI Error Control and Status register could not be written") ;
12146
                disable main ;
12147
            end
12148
        end
12149
 
12150
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
12151
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12152
        fork
12153
        begin
12154
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12155
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12156
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12157
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12158
 
12159
            do_pause( 1 ) ;
12160
        end
12161
        begin
12162
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12163
 
12164
            if ( ok !== 1 )
12165
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12166
 
12167
            do_pause(3) ;
12168
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12169
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12170
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12171
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
12172
            do_pause(1) ;
12173
 
12174
            while ( FRAME === 0 )
12175
                @(posedge pci_clock) ;
12176
 
12177
            while ( IRDY === 0 )
12178
                @(posedge pci_clock) ;
12179
 
12180 35 mihad
            #1 ;
12181
            if ( !error_monitor_done )
12182
                disable monitor_error_event7 ;
12183 15 mihad
        end
12184
        begin:monitor_error_event7
12185 35 mihad
            error_monitor_done = 0 ;
12186 15 mihad
            @(error_event_int) ;
12187
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12188
            ok = 0 ;
12189 35 mihad
            error_monitor_done = 1 ;
12190 15 mihad
        end
12191
        begin
12192
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12193
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12194
        end
12195
        join
12196
 
12197
        if ( ok )
12198
            test_ok ;
12199
 
12200 26 mihad
        @(posedge pci_clock) ;
12201
        @(posedge pci_clock) ;
12202
        @(posedge wb_clock) ;
12203
        @(posedge wb_clock) ;
12204
 
12205 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12206
        addr_offset = 12'h004 ;
12207
        config_read(addr_offset, 4'hF, read_data) ;
12208
        ok = 1 ;
12209
        if ( read_data[27] !== 1 )
12210
        begin
12211
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12212
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12213
            ok = 0 ;
12214
        end
12215
        if ( read_data[28] !== 0 )
12216
        begin
12217
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12218
            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") ;
12219
            ok = 0 ;
12220
        end
12221
        if ( read_data[29] !== 0 )
12222
        begin
12223
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12224
            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") ;
12225
            ok = 0 ;
12226
        end
12227
 
12228
        // clear statuses
12229
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12230
        if ( !ok )
12231
        begin
12232
            test_fail("write to PCI Device Status register failed") ;
12233
            $display("Couldn't write PCI Device Status register") ;
12234
            disable main ;
12235
        end
12236
 
12237
        if ( ok )
12238
            test_ok ;
12239
 
12240
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12241
 
12242
        ok = 1 ;
12243
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12244
 
12245
        config_read(addr_offset, 4'hF, read_data) ;
12246
        if (read_data[8] !== 0)
12247
        begin
12248
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12249
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12250
            ok = 0 ;
12251
        end
12252
        else
12253
            test_ok ;
12254
 
12255
        if ( ok !== 1 )
12256
        begin
12257
            config_write(addr_offset, read_data, 4'hF, ok) ;
12258
            if ( !ok )
12259
            begin
12260
                test_fail("PCI Error Control and Status register could not be written") ;
12261
                disable main ;
12262
            end
12263
        end
12264
 
12265
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
12266
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12267
        fork
12268
        begin
12269
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12270
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12271
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12272
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12273
 
12274
            do_pause( 1 ) ;
12275
        end
12276
        begin
12277
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12278
 
12279
            if ( ok !== 1 )
12280
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12281
 
12282
            do_pause(3) ;
12283
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12284
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12285
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12286
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
12287
            do_pause(1) ;
12288
 
12289
            while ( FRAME === 0 )
12290
                @(posedge pci_clock) ;
12291
 
12292
            while ( IRDY === 0 )
12293
                @(posedge pci_clock) ;
12294
 
12295 35 mihad
            #1 ;
12296
            if ( !error_monitor_done )
12297
                disable monitor_error_event8 ;
12298 15 mihad
        end
12299
        begin:monitor_error_event8
12300 35 mihad
            error_monitor_done = 0 ;
12301 15 mihad
            @(error_event_int) ;
12302
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12303
            ok = 0 ;
12304 35 mihad
            error_monitor_done = 1 ;
12305 15 mihad
        end
12306
        begin
12307
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12308
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12309
        end
12310
        join
12311
 
12312
        if ( ok )
12313
            test_ok ;
12314
 
12315 26 mihad
        @(posedge pci_clock) ;
12316
        @(posedge pci_clock) ;
12317
        @(posedge wb_clock) ;
12318
        @(posedge wb_clock) ;
12319
 
12320 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12321
 
12322
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12323
        addr_offset = 12'h004 ;
12324
        config_read(addr_offset, 4'hF, read_data) ;
12325
        ok = 1 ;
12326
        if ( read_data[27] !== 1 )
12327
        begin
12328
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12329
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12330
            ok = 0 ;
12331
        end
12332
        if ( read_data[28] !== 0 )
12333
        begin
12334
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12335
            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") ;
12336
            ok = 0 ;
12337
        end
12338
        if ( read_data[29] !== 0 )
12339
        begin
12340
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12341
            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") ;
12342
            ok = 0 ;
12343
        end
12344
 
12345
        // clear statuses
12346
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12347
        if ( !ok )
12348
        begin
12349
            test_fail("write to PCI Device Status register failed") ;
12350
            $display("Couldn't write PCI Device Status register") ;
12351
            disable main ;
12352
        end
12353
 
12354
        if ( ok )
12355
            test_ok ;
12356
 
12357
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12358
 
12359
        ok = 1 ;
12360
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12361
 
12362
        config_read(addr_offset, 4'hF, read_data) ;
12363
        if (read_data[8] !== 0)
12364
        begin
12365
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12366
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12367
            ok = 0 ;
12368
        end
12369
        else
12370
            test_ok ;
12371
 
12372
        if ( ok !== 1 )
12373
        begin
12374
            config_write(addr_offset, read_data, 4'hF, ok) ;
12375
            if ( !ok )
12376
            begin
12377
                test_fail("PCI Error Control and Status register could not be written") ;
12378
                disable main ;
12379
            end
12380
        end
12381
 
12382
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
12383
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12384
        fork
12385
        begin
12386
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12387
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12388
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12389
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12390
 
12391
            do_pause( 1 ) ;
12392
        end
12393
        begin
12394
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
12395
 
12396
            if ( ok !== 1 )
12397
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12398
 
12399
            do_pause(3) ;
12400
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12401
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12402
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12403
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12404
            do_pause(1) ;
12405
 
12406
            while ( FRAME === 0 )
12407
                @(posedge pci_clock) ;
12408
 
12409
            while ( IRDY === 0 )
12410
                @(posedge pci_clock) ;
12411
 
12412 35 mihad
            #1 ;
12413
            if ( !error_monitor_done )
12414
                disable monitor_error_event9 ;
12415 15 mihad
        end
12416
        begin:monitor_error_event9
12417 35 mihad
            error_monitor_done = 0 ;
12418 15 mihad
            @(error_event_int) ;
12419
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12420
            ok = 0 ;
12421 35 mihad
            error_monitor_done = 1 ;
12422 15 mihad
        end
12423
        begin
12424
            wb_transaction_stop( 3 ) ;
12425
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12426
        end
12427
        join
12428
 
12429
        if ( ok )
12430
            test_ok ;
12431
 
12432
        // now check all other statuses too
12433
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
12434
        ok = 1 ;
12435
 
12436
        addr_offset = 12'h004 ;
12437
        config_read(addr_offset, 4'hF, read_data) ;
12438
        if (read_data[31] !== 0)
12439
        begin
12440
            $display("Detected Parity Error bit set for no reason") ;
12441
            test_fail("Detected Parity Error bit was set for no reason") ;
12442
            ok = 0 ;
12443
        end
12444
 
12445
        if (read_data[30] !== 0)
12446
        begin
12447
            $display("Signaled System Error bit set for no reason") ;
12448
            test_fail("Signaled System Error bit was set for no reason") ;
12449
            ok = 0 ;
12450
        end
12451
 
12452
        if (read_data[29] !== 0)
12453
        begin
12454
            $display("Received Master Abort bit set for no reason") ;
12455
            test_fail("Received Master Abort bit was set for no reason") ;
12456
            ok = 0 ;
12457
        end
12458
 
12459
        if (read_data[28] !== 0)
12460
        begin
12461
            $display("Received Target Abort bit set for no reason");
12462
            test_fail("Received Target Abort bit was set for no reason") ;
12463
            ok = 0 ;
12464
        end
12465
 
12466
        if (read_data[27] !== 0)
12467
        begin
12468
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
12469
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
12470
            ok = 0 ;
12471
        end
12472
 
12473
        if (read_data[24] !== 0)
12474
        begin
12475
            $display("Master Data Parity Error bit set for no reason") ;
12476
            test_fail("Master Data Parity Error bit was set for no reason") ;
12477
            ok = 0 ;
12478
        end
12479
 
12480
        if ( ok )
12481
            test_ok ;
12482
 
12483
        test_name = "DISABLE IMAGE" ;
12484
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12485
        if ( ok !== 1 )
12486
        begin
12487
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12488
            test_fail("PCI Address Mask register could not be written") ;
12489
            disable main;
12490
        end
12491
    end
12492
 
12493
    if ( target_io_image !== -1 )
12494
    begin
12495
        do_io_aborts = 1 ;
12496
 
12497
        if (target_io_image === 1)
12498
        begin
12499
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12500
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12501
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12502
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12503
        end
12504
        else if (target_io_image === 2)
12505
        begin
12506
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12507
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12508
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12509
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12510
        end
12511
        else if (target_io_image === 3)
12512
        begin
12513
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12514
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12515
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12516
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12517
        end
12518
        else if (target_io_image === 4)
12519
        begin
12520
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12521
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12522
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12523
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12524
        end
12525
        else if (target_io_image === 5)
12526
        begin
12527
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12528
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12529
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12530
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12531
        end
12532
    end
12533
    else
12534
        do_io_aborts = 0 ;
12535
 
12536
    if ( do_io_aborts )
12537
    begin
12538
 
12539
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
12540
 
12541
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12542
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
12543
        if ( ok !== 1 )
12544
        begin
12545
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12546
            test_fail("PCI Error Control and Status register could not be written") ;
12547
            disable main;
12548
        end
12549
 
12550
        // enable INTERRUPT reporting
12551
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12552
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
12553
        if ( ok !== 1 )
12554
        begin
12555
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
12556
            test_fail("Interrupt Control register could not be written") ;
12557
            disable main;
12558
        end
12559
 
12560
        addr_offset = 12'h010 + (4*target_io_image) ;
12561
 
12562
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
12563
        if ( ok !== 1 )
12564
        begin
12565
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
12566
            test_fail("PCI Base Address register could not be written") ;
12567
            disable main;
12568
        end
12569
 
12570
        // disable address translation and enable prefetch so read bursts can be performed
12571
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
12572
        if ( ok !== 1 )
12573
        begin
12574
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
12575
            test_fail("PCI Image Control register could not be written") ;
12576
            disable main;
12577
        end
12578
 
12579
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
12580
        if ( ok !== 1 )
12581
        begin
12582
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12583
            test_fail("PCI Address Mask register could not be written") ;
12584
            disable main;
12585
        end
12586
 
12587
        addr_offset = 12'h00C ;
12588
 
12589
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
12590
        if ( ok !== 1 )
12591
        begin
12592
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
12593
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
12594
            disable main;
12595
        end
12596
 
12597
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12598
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12599
 
12600
        // do a single read error terminated on WB bus
12601
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
12602
 
12603
        fork
12604
        begin
12605
            PCIU_IO_READ
12606
             (
12607
                `Test_Master_1,
12608
                Target_Base_Addr_R[target_io_image],
12609
                32'hAAAA_5555,
12610
                4'h0,
12611
                1,
12612
                `Test_Target_Retry_On
12613
             );
12614
 
12615
            do_pause( 1 ) ;
12616
        end
12617
        begin
12618
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
12619
 
12620
            if ( ok !== 1 )
12621
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12622
 
12623
            do_pause(3) ;
12624
 
12625
            PCIU_IO_READ
12626
             (
12627
                `Test_Master_1,
12628
                Target_Base_Addr_R[target_io_image],
12629
                32'hAAAA_5555,
12630
                4'h0,
12631
                1,
12632
                `Test_Target_Abort_On
12633
             );
12634
 
12635
            do_pause( 1 ) ;
12636
 
12637
            while ( FRAME === 0 )
12638
                @(posedge pci_clock) ;
12639
 
12640
            while ( IRDY === 0 )
12641
                @(posedge pci_clock) ;
12642
 
12643 35 mihad
            #1 ;
12644
            if ( !error_monitor_done )
12645
                disable monitor_error_event10 ;
12646 15 mihad
        end
12647
        begin:monitor_error_event10
12648 35 mihad
            error_monitor_done = 0 ;
12649 15 mihad
            @(error_event_int) ;
12650
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12651
            ok = 0 ;
12652 35 mihad
            error_monitor_done = 1 ;
12653 15 mihad
        end
12654
        join
12655
 
12656
        if ( ok )
12657
            test_ok ;
12658
 
12659 26 mihad
        @(posedge pci_clock) ;
12660
        @(posedge pci_clock) ;
12661
        @(posedge wb_clock) ;
12662
        @(posedge wb_clock) ;
12663
 
12664 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12665
        addr_offset = 12'h004 ;
12666
        config_read(addr_offset, 4'hF, read_data) ;
12667
        ok = 1 ;
12668
        if ( read_data[27] !== 1 )
12669
        begin
12670
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12671
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12672
            ok = 0 ;
12673
        end
12674
        if ( read_data[28] !== 0 )
12675
        begin
12676
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12677
            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") ;
12678
            ok = 0 ;
12679
        end
12680
        if ( read_data[29] !== 0 )
12681
        begin
12682
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12683
            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") ;
12684
            ok = 0 ;
12685
        end
12686
 
12687
        // clear statuses
12688
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12689
        if ( !ok )
12690
        begin
12691
            test_fail("write to PCI Device Status register failed") ;
12692
            $display("Couldn't write PCI Device Status register") ;
12693
            disable main ;
12694
        end
12695
 
12696
        if ( ok )
12697
            test_ok ;
12698
 
12699
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12700
 
12701
        ok = 1 ;
12702
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12703
 
12704
        config_read(addr_offset, 4'hF, read_data) ;
12705
        if (read_data[8] !== 0)
12706
        begin
12707
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12708
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12709
            ok = 0 ;
12710
        end
12711
        else
12712
            test_ok ;
12713
 
12714
        if ( ok !== 1 )
12715
        begin
12716
            config_write(addr_offset, read_data, 4'hF, ok) ;
12717
            if ( !ok )
12718
            begin
12719
                test_fail("PCI Error Control and Status register could not be written") ;
12720
                disable main ;
12721
            end
12722
        end
12723
 
12724
        test_name = "DISABLE IMAGE" ;
12725
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12726
        if ( ok !== 1 )
12727
        begin
12728
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12729
            test_fail("PCI Address Mask register could not be written") ;
12730
            disable main;
12731
        end
12732
 
12733
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12734
 
12735
    end
12736
end // main
12737
endtask // test_wb_error_rd
12738
 
12739
task test_target_abort ;
12740
    input [2:0]  image_num ;
12741
    reg   [11:0] pci_ctrl_offset ;
12742
    reg   [11:0] ctrl_offset ;
12743
    reg   [11:0] ba_offset ;
12744
    reg   [11:0] am_offset ;
12745
    reg   [11:0] ta_offset ;
12746
    reg   [31:0] pci_address ;
12747
    reg   [3:0]  byte_enables ;
12748
    reg          ok ;
12749 35 mihad
    reg          error_monitor_done ;
12750 15 mihad
begin:main
12751
    pci_ctrl_offset = 12'h4 ;
12752
    if (image_num === 0)
12753
    begin
12754
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
12755
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
12756
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
12757
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
12758
    end
12759
    else if (image_num === 1)
12760
    begin
12761
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12762
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12763
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12764
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12765
    end
12766
    else if (image_num === 2)
12767
    begin
12768
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12769
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12770
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12771
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12772
    end
12773
    else if (image_num === 3)
12774
    begin
12775
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12776
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12777
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12778
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12779
    end
12780
    else if (image_num === 4)
12781
    begin
12782
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12783
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12784
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12785
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12786
    end
12787
    else if (image_num === 5)
12788
    begin
12789
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12790
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12791
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12792
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12793
    end
12794
 
12795
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
12796
 
12797
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
12798
    if ( ok !== 1 )
12799
    begin
12800
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
12801
        test_fail("PCI Base Address register could not be written") ;
12802
        disable main ;
12803
    end
12804
 
12805
    // Set Address Mask of IMAGE
12806
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
12807
    if ( ok !== 1 )
12808
    begin
12809
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
12810
        test_fail("PCI Address Mask register could not be written") ;
12811
        disable main ;
12812
    end
12813
 
12814
    // Set Translation Address of IMAGE
12815
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
12816
    if ( ok !== 1 )
12817
    begin
12818
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
12819
        test_fail("PCI Translation Address Register could not be written") ;
12820
        disable main ;
12821
    end
12822
 
12823
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
12824
    if ( ok !== 1 )
12825
    begin
12826
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
12827
        test_fail("PCI Image Control register could not be written") ;
12828
        disable main ;
12829
    end
12830
 
12831
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
12832
 
12833
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
12834
 
12835
    pci_address  = Target_Base_Addr_R[image_num] ;
12836
    byte_enables = 4'b0001 ;
12837
 
12838
    fork
12839
    begin
12840
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12841
        do_pause ( 1 ) ;
12842
    end
12843
    begin:monitor_error_event1
12844 35 mihad
        error_monitor_done = 0 ;
12845 15 mihad
        @(error_event_int) ;
12846
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12847
        ok = 0 ;
12848 35 mihad
        error_monitor_done = 1 ;
12849 15 mihad
    end
12850
    begin
12851
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12852
        @(posedge pci_clock) ;
12853 35 mihad
        #1 ;
12854
        if ( !error_monitor_done )
12855
            disable monitor_error_event1 ;
12856 15 mihad
    end
12857
    join
12858
 
12859
    if ( ok )
12860
        test_ok ;
12861
 
12862
    ok = 1 ;
12863
 
12864
    fork
12865
    begin
12866
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12867
        do_pause ( 1 ) ;
12868
    end
12869
    begin:monitor_error_event2
12870 35 mihad
        error_monitor_done = 0 ;
12871 15 mihad
        @(error_event_int) ;
12872
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12873
        ok = 0 ;
12874 35 mihad
        error_monitor_done = 1 ;
12875 15 mihad
    end
12876
    begin
12877
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12878
        @(posedge pci_clock) ;
12879 35 mihad
        #1 ;
12880
        if ( !error_monitor_done )
12881
            disable monitor_error_event2 ;
12882 15 mihad
    end
12883
    join
12884
 
12885
    if ( ok )
12886
        test_ok ;
12887
 
12888
    ok = 1 ;
12889
 
12890
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
12891
    byte_enables = 4'b0011 ;
12892
 
12893
    fork
12894
    begin
12895
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12896
        do_pause ( 1 ) ;
12897
    end
12898
    begin:monitor_error_event3
12899 35 mihad
        error_monitor_done = 0 ;
12900 15 mihad
        @(error_event_int) ;
12901
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12902
        ok = 0 ;
12903 35 mihad
        error_monitor_done = 1 ;
12904 15 mihad
    end
12905
    begin
12906
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12907
        @(posedge pci_clock) ;
12908 35 mihad
        if ( !error_monitor_done )
12909
            disable monitor_error_event3 ;
12910 15 mihad
    end
12911
    join
12912
 
12913
    if ( ok )
12914
        test_ok ;
12915
 
12916
    ok = 1 ;
12917
 
12918
    byte_enables = 4'b0000 ;
12919
 
12920
    fork
12921
    begin
12922
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12923
        do_pause ( 1 ) ;
12924
    end
12925
    begin:monitor_error_event4
12926 35 mihad
        error_monitor_done = 0 ;
12927 15 mihad
        @(error_event_int) ;
12928
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12929
        ok = 0 ;
12930 35 mihad
        error_monitor_done = 1 ;
12931 15 mihad
    end
12932
    begin
12933
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12934
        @(posedge pci_clock) ;
12935 35 mihad
        #1 ;
12936
        if ( !error_monitor_done )
12937
            disable monitor_error_event4 ;
12938 15 mihad
    end
12939
    join
12940
 
12941
    if ( ok )
12942
        test_ok ;
12943
 
12944
    ok = 1 ;
12945
 
12946
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
12947
    byte_enables = 4'b0111 ;
12948
 
12949
    fork
12950
    begin
12951
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12952
        do_pause ( 1 ) ;
12953
    end
12954
    begin:monitor_error_event5
12955 35 mihad
        error_monitor_done = 0 ;
12956 15 mihad
        @(error_event_int) ;
12957
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12958
        ok = 0 ;
12959 35 mihad
        error_monitor_done = 1 ;
12960 15 mihad
    end
12961
    begin
12962
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12963
        @(posedge pci_clock) ;
12964 35 mihad
        #1 ;
12965
        if ( !error_monitor_done )
12966
            disable monitor_error_event5 ;
12967 15 mihad
    end
12968
    join
12969
 
12970
    if ( ok )
12971
        test_ok ;
12972
 
12973
    ok = 1 ;
12974
 
12975
    byte_enables = 4'b0010 ;
12976
 
12977
    fork
12978
    begin
12979
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12980
        do_pause ( 1 ) ;
12981
    end
12982
    begin:monitor_error_event6
12983 35 mihad
        error_monitor_done = 0 ;
12984 15 mihad
        @(error_event_int) ;
12985
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12986
        ok = 0 ;
12987 35 mihad
        error_monitor_done = 1 ;
12988 15 mihad
    end
12989
    begin
12990
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12991
        @(posedge pci_clock) ;
12992 35 mihad
        #1 ;
12993
        if ( !error_monitor_done )
12994
            disable monitor_error_event6 ;
12995 15 mihad
    end
12996
    join
12997
 
12998
    if ( ok )
12999
        test_ok ;
13000
 
13001
    ok = 1 ;
13002
    byte_enables = 4'b0001 ;
13003
 
13004
    fork
13005
    begin
13006
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13007
        do_pause ( 1 ) ;
13008
    end
13009
    begin:monitor_error_event7
13010 35 mihad
        error_monitor_done = 0 ;
13011 15 mihad
        @(error_event_int) ;
13012
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13013
        ok = 0 ;
13014 35 mihad
        error_monitor_done = 1 ;
13015 15 mihad
    end
13016
    begin
13017
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13018
        @(posedge pci_clock) ;
13019 35 mihad
        #1 ;
13020
        if ( !error_monitor_done )
13021
            disable monitor_error_event7 ;
13022 15 mihad
    end
13023
    join
13024
 
13025
    if ( ok )
13026
        test_ok ;
13027
 
13028
    ok = 1 ;
13029
    byte_enables = 4'b0000 ;
13030
 
13031
    fork
13032
    begin
13033
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
13034
        do_pause ( 1 ) ;
13035
    end
13036
    begin:monitor_error_event8
13037 35 mihad
        error_monitor_done = 0 ;
13038 15 mihad
        @(error_event_int) ;
13039
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13040
        ok = 0 ;
13041 35 mihad
        error_monitor_done = 1 ;
13042 15 mihad
    end
13043
    begin
13044
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13045
        @(posedge pci_clock) ;
13046 35 mihad
        #1 ;
13047
        if ( !error_monitor_done )
13048
            disable monitor_error_event8 ;
13049 15 mihad
    end
13050
    join
13051
 
13052
    if ( ok )
13053
        test_ok ;
13054
 
13055
    ok = 1 ;
13056
 
13057
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
13058
    byte_enables = 4'b0110 ;
13059
 
13060
    fork
13061
    begin
13062
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
13063
        do_pause ( 1 ) ;
13064
    end
13065
    begin:monitor_error_event9
13066 35 mihad
        error_monitor_done = 0 ;
13067 15 mihad
        @(error_event_int) ;
13068
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13069
        ok = 0 ;
13070 35 mihad
        error_monitor_done = 1 ;
13071 15 mihad
    end
13072
    begin
13073
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13074
        @(posedge pci_clock) ;
13075 35 mihad
        #1 ;
13076
        if ( !error_monitor_done )
13077
            disable monitor_error_event9 ;
13078 15 mihad
    end
13079
    join
13080
 
13081
    if ( ok )
13082
        test_ok ;
13083
 
13084
    ok = 1 ;
13085
    fork
13086
    begin
13087
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
13088
        do_pause ( 1 ) ;
13089
    end
13090
    begin:monitor_error_event10
13091 35 mihad
        error_monitor_done = 0 ;
13092 15 mihad
        @(error_event_int) ;
13093
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13094
        ok = 0 ;
13095 35 mihad
        error_monitor_done = 1 ;
13096 15 mihad
    end
13097
    begin
13098
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13099
        @(posedge pci_clock) ;
13100 35 mihad
 
13101
        #1 ;
13102
        if ( !error_monitor_done )
13103
            disable monitor_error_event10 ;
13104 15 mihad
    end
13105
    join
13106
 
13107
    if ( ok )
13108
        test_ok ;
13109
 
13110
    ok = 1 ;
13111
 
13112
    byte_enables = 4'b0001 ;
13113
 
13114
    fork
13115
    begin
13116
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13117
        do_pause ( 1 ) ;
13118
    end
13119
    begin:monitor_error_event11
13120 35 mihad
        error_monitor_done = 0 ;
13121 15 mihad
        @(error_event_int) ;
13122
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13123
        ok = 0 ;
13124 35 mihad
        error_monitor_done = 1 ;
13125 15 mihad
    end
13126
    begin
13127
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13128
        @(posedge pci_clock) ;
13129 35 mihad
        #1 ;
13130
        if ( !error_monitor_done )
13131
            disable monitor_error_event11 ;
13132 15 mihad
    end
13133
    join
13134
 
13135
    if ( ok )
13136
        test_ok ;
13137
 
13138
    ok = 1 ;
13139
 
13140
    byte_enables = 4'b0101 ;
13141
 
13142
    fork
13143
    begin
13144
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13145
        do_pause ( 1 ) ;
13146
    end
13147
    begin:monitor_error_event12
13148 35 mihad
        error_monitor_done = 0 ;
13149 15 mihad
        @(error_event_int) ;
13150
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13151
        ok = 0 ;
13152 35 mihad
        error_monitor_done = 1 ;
13153 15 mihad
    end
13154
    begin
13155
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13156
        @(posedge pci_clock) ;
13157 35 mihad
        #1 ;
13158
        if ( !error_monitor_done )
13159
            disable monitor_error_event12 ;
13160 15 mihad
    end
13161
    join
13162
 
13163
    if ( ok )
13164
        test_ok ;
13165
 
13166
    ok = 1 ;
13167
 
13168
    byte_enables = 4'b0011 ;
13169
 
13170
    fork
13171
    begin
13172
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13173
        do_pause ( 1 ) ;
13174
    end
13175
    begin:monitor_error_event13
13176 35 mihad
        error_monitor_done = 0 ;
13177 15 mihad
        @(error_event_int) ;
13178
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13179
        ok = 0 ;
13180 35 mihad
        error_monitor_done = 1 ;
13181 15 mihad
    end
13182
    begin
13183
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13184
        @(posedge pci_clock) ;
13185 35 mihad
        #1 ;
13186
        if ( !error_monitor_done )
13187
            disable monitor_error_event13 ;
13188 15 mihad
    end
13189
    join
13190
 
13191
    if ( ok )
13192
        test_ok ;
13193
 
13194
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13195
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
13196
    ok = 1 ;
13197
    if ( pci_address[27] !== 1 )
13198
    begin
13199
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
13200
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
13201
        ok = 0 ;
13202
    end
13203
    if ( pci_address[28] !== 0 )
13204
    begin
13205
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
13206
        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") ;
13207
        ok = 0 ;
13208
    end
13209
    if ( pci_address[29] !== 0 )
13210
    begin
13211
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
13212
        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") ;
13213
        ok = 0 ;
13214
    end
13215
 
13216
    // clear statuses
13217
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
13218
    if ( !ok )
13219
    begin
13220
        test_fail("write to PCI Device Status register failed") ;
13221
        $display("Couldn't write PCI Device Status register") ;
13222
        disable main ;
13223
    end
13224
 
13225
    if ( ok )
13226
        test_ok ;
13227
 
13228
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
13229
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
13230
    if ( pci_address[8] !== 0 )
13231
    begin
13232
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
13233
    end
13234
    else
13235
        test_ok ;
13236
 
13237
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13238
 
13239
    test_name = "DISABLE IMAGE" ;
13240
 
13241
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
13242
    if ( ok !== 1 )
13243
    begin
13244
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
13245
        test_fail("PCI Address Mask register could not be written") ;
13246
        disable main ;
13247
    end
13248
end
13249
endtask // test_target_abort
13250
 
13251
task test_target_io_wr_rd ;
13252
    input [2:0]  image_num ;
13253
    input        translate_address ;
13254
    input [11:0] img_ctrl_offset ;
13255
    reg   [31:0] expect_address ;
13256
    reg   [31:0] pci_address ;
13257
    reg          translation ;
13258
    reg   [31:0] read_data ;
13259
    reg   [3:0]  byte_enables ;
13260
    reg          ok ;
13261
    reg          pci_ok ;
13262
    reg          wb_ok ;
13263
    integer      i ;
13264 35 mihad
    reg          error_monitor_done ;
13265 15 mihad
begin:main
13266
    `ifdef ADDR_TRAN_IMPL
13267
        translation = translate_address ;
13268
    `else
13269
        translation = 0 ;
13270
    `endif
13271
 
13272
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13273
 
13274
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13275
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13276
    if ( translation )
13277
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13278
    else
13279
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13280
 
13281
    if ( !ok )
13282
    begin
13283
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13284
        test_fail("PCI Image Control register could not be written") ;
13285
    end
13286
 
13287
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
13288
    pci_address  = Target_Base_Addr_R[image_num] ;
13289
    byte_enables = 4'b0000 ;
13290
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13291
 
13292
    fork
13293
    begin
13294
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
13295
        do_pause ( 1 ) ;
13296
    end
13297
    begin
13298
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13299
        if ( wb_ok !== 1 )
13300
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13301
 
13302 35 mihad
        #1 ;
13303
        if ( !error_monitor_done )
13304
            disable monitor_pci_error_1 ;
13305 15 mihad
    end
13306
    begin:monitor_pci_error_1
13307 35 mihad
        error_monitor_done = 0 ;
13308 15 mihad
        pci_ok = 1 ;
13309
        @(error_event_int) ;
13310
        pci_ok = 0 ;
13311
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
13312 35 mihad
        error_monitor_done = 1 ;
13313 15 mihad
    end
13314
    join
13315
 
13316
    byte_enables = 4'b1111 ;
13317
    for ( i = 0 ; i < 4 ; i = i + 1 )
13318
    begin:loop_1
13319
        byte_enables[i] = 0 ;
13320
        if ( i > 0 )
13321
            byte_enables[i - 1] = 1 ;
13322
        fork
13323
        begin
13324
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13325
            do_pause ( 1 ) ;
13326
        end
13327
        begin
13328
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13329
            if ( wb_ok !== 1 )
13330
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13331
 
13332 35 mihad
            #1 ;
13333
            if ( !error_monitor_done )
13334
                disable monitor_pci_error_2 ;
13335 15 mihad
        end
13336
        begin:monitor_pci_error_2
13337 35 mihad
            error_monitor_done = 0 ;
13338 15 mihad
            pci_ok = 1 ;
13339
            @(error_event_int) ;
13340
            pci_ok = 0 ;
13341
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13342 35 mihad
            error_monitor_done = 1 ;
13343 15 mihad
        end
13344
        join
13345
 
13346
        if ( !pci_ok || !wb_ok )
13347
            disable loop_1 ;
13348
 
13349
        pci_address = pci_address + 1 ;
13350
        expect_address = expect_address + 1 ;
13351
    end
13352
 
13353
    if ( pci_ok && wb_ok )
13354
        test_ok ;
13355
 
13356
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
13357
    pci_address  = Target_Base_Addr_R[image_num] ;
13358
    byte_enables = 4'b1100 ;
13359
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13360
 
13361
    master1_check_received_data = 1 ;
13362
    fork
13363
    begin
13364
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13365
        do_pause( 1 ) ;
13366
    end
13367
    begin
13368
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13369
        if ( wb_ok !== 1 )
13370
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13371
 
13372
        do_pause ( 2 ) ;
13373
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13374
        do_pause ( 16 ) ;
13375
 
13376 35 mihad
        #1 ;
13377
        if ( !error_monitor_done )
13378
            disable monitor_pci_error_3 ;
13379 15 mihad
    end
13380
    begin:monitor_pci_error_3
13381 35 mihad
        error_monitor_done = 0 ;
13382 15 mihad
        pci_ok = 1 ;
13383
        @(error_event_int) ;
13384
        pci_ok = 0 ;
13385
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13386 35 mihad
        error_monitor_done = 1 ;
13387 15 mihad
    end
13388
    join
13389
 
13390
    if ( !pci_ok || !wb_ok )
13391
    begin
13392
        disable main ;
13393
    end
13394
 
13395
    pci_address  = Target_Base_Addr_R[image_num] + 2;
13396
    byte_enables = 4'b0011 ;
13397
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13398
 
13399
    master1_check_received_data = 1 ;
13400
    fork
13401
    begin
13402
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13403
        do_pause( 1 ) ;
13404
    end
13405
    begin
13406
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13407
        if ( wb_ok !== 1 )
13408
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13409
 
13410
        do_pause ( 2 ) ;
13411
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13412
        do_pause ( 16 ) ;
13413
 
13414 35 mihad
        #1 ;
13415
        if ( !error_monitor_done )
13416
            disable monitor_pci_error_4 ;
13417 15 mihad
    end
13418
    begin:monitor_pci_error_4
13419 35 mihad
        error_monitor_done = 0 ;
13420 15 mihad
        pci_ok = 1 ;
13421
        @(error_event_int) ;
13422
        pci_ok = 0 ;
13423
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13424 35 mihad
        error_monitor_done = 1 ;
13425 15 mihad
    end
13426
    join
13427
 
13428
    if ( !pci_ok || !wb_ok )
13429
    begin
13430
        disable main ;
13431
    end
13432
 
13433
    pci_address  = Target_Base_Addr_R[image_num] ;
13434
    byte_enables = 4'b0000 ;
13435
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13436
 
13437
    master1_check_received_data = 1 ;
13438
    fork
13439
    begin
13440
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13441
        do_pause( 1 ) ;
13442
    end
13443
    begin
13444
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13445
        if ( wb_ok !== 1 )
13446
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13447
 
13448
        do_pause ( 2 ) ;
13449
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13450
        do_pause ( 16 ) ;
13451
 
13452 35 mihad
        #1 ;
13453
        if ( !error_monitor_done )
13454
            disable monitor_pci_error_5 ;
13455 15 mihad
    end
13456
    begin:monitor_pci_error_5
13457 35 mihad
        error_monitor_done = 0 ;
13458 15 mihad
        pci_ok = 1 ;
13459
        @(error_event_int) ;
13460
        pci_ok = 0 ;
13461
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13462 35 mihad
        error_monitor_done = 1 ;
13463 15 mihad
    end
13464
    join
13465
 
13466
    if ( pci_ok && wb_ok )
13467
        test_ok ;
13468
end
13469
endtask // test_target_io_wr_rd
13470
 
13471
task test_target_io_err_wr ;
13472
    input [2:0]  image_num ;
13473
    input        translate_address ;
13474
    input [11:0] img_ctrl_offset ;
13475
    input        enable_error_report ;
13476
    input        enable_error_interrupt ;
13477
 
13478
    reg   [31:0] expect_address ;
13479
    reg   [31:0] pci_address ;
13480
    reg          translation ;
13481
    reg   [31:0] read_data ;
13482
    reg   [3:0]  byte_enables ;
13483
    reg          ok ;
13484
    reg          pci_ok ;
13485
    reg          wb_ok ;
13486
    integer      i ;
13487
    reg   [11:0] offset ;
13488 35 mihad
    reg          error_monitor_done ;
13489 15 mihad
begin:main
13490
    `ifdef ADDR_TRAN_IMPL
13491
        translation = translate_address ;
13492
    `else
13493
        translation = 0 ;
13494
    `endif
13495
 
13496
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
13497
 
13498
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13499
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13500
    if ( translation )
13501
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13502
    else
13503
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13504
 
13505
    if ( !ok )
13506
    begin
13507
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13508
        test_fail("PCI Image Control register could not be written") ;
13509
    end
13510
 
13511
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
13512
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13513
    if ( enable_error_report )
13514
    begin
13515
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
13516
        if ( !ok )
13517
        begin
13518
            test_fail("PCI Error Control and Status register could not be written") ;
13519
            disable main ;
13520
        end
13521
    end
13522
    else
13523
    begin
13524
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13525
        if ( !ok )
13526
        begin
13527
            test_fail("PCI Error Control and Status register could not be written") ;
13528
            disable main ;
13529
        end
13530
    end
13531
 
13532
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
13533
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
13534
    if ( enable_error_interrupt )
13535
    begin
13536
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
13537
        if ( !ok )
13538
        begin
13539
            test_fail("Interrupt Control register could not be written") ;
13540
            disable main ;
13541
        end
13542
    end
13543
    else
13544
    begin
13545
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13546
        if ( !ok )
13547
        begin
13548
            test_fail("Interrupt Control register could not be written") ;
13549
            disable main ;
13550
        end
13551
    end
13552
 
13553
    pci_address  = Target_Base_Addr_R[image_num] ;
13554
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13555
 
13556
    byte_enables = 4'b1111 ;
13557
 
13558
    for ( i = 0 ; i < 4 ; i = i + 1 )
13559
    begin:loop_1
13560
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
13561
        byte_enables[i] = 0 ;
13562
        if ( i > 0 )
13563
            byte_enables[i - 1] = 1 ;
13564
 
13565
        fork
13566
        begin
13567
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13568
            do_pause ( 1 ) ;
13569
        end
13570
        begin
13571
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
13572
            if ( wb_ok !== 1 )
13573
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13574
 
13575 35 mihad
            #1 ;
13576
            if ( !error_monitor_done )
13577
                disable monitor_pci_error_2 ;
13578 15 mihad
        end
13579
        begin:monitor_pci_error_2
13580 35 mihad
            error_monitor_done = 0 ;
13581 15 mihad
            pci_ok = 1 ;
13582
            @(error_event_int) ;
13583
            pci_ok = 0 ;
13584
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13585 35 mihad
            error_monitor_done = 1 ;
13586 15 mihad
        end
13587
        join
13588
 
13589
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13590
        `ifdef HOST
13591
 
13592
            repeat ( 4 )
13593
                @( posedge wb_clock ) ;
13594
 
13595
            if ( enable_error_interrupt && enable_error_report )
13596
            begin
13597
                if ( INT_O !== 1 )
13598
                begin
13599
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
13600
                end
13601
            end
13602
            else
13603
            begin
13604
                if ( INT_O !== 0 )
13605
                begin
13606
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
13607
                end
13608
            end
13609
        `else
13610
            repeat ( 4 )
13611
                @( posedge pci_clock ) ;
13612
 
13613
            if ( enable_error_interrupt && enable_error_report )
13614
            begin
13615
                if ( INTA !== 0 )
13616
                begin
13617
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
13618
                end
13619
            end
13620
            else
13621
            begin
13622
                if ( INTA !== 1 )
13623
                begin
13624
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
13625
                end
13626
            end
13627
        `endif
13628
 
13629
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
13630
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13631
        config_read( offset, 4'hF, read_data ) ;
13632
        ok = 1 ;
13633
        if ( enable_error_report )
13634
        begin
13635
            if ( read_data[8] !== 1 )
13636
            begin
13637
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
13638
                ok = 0 ;
13639
            end
13640
 
13641
            if ( read_data[9] !== 0 )
13642
            begin
13643
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
13644
                ok = 0 ;
13645
            end
13646
 
13647
            if ( read_data[31:28] !== byte_enables )
13648
            begin
13649
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
13650
                ok = 0 ;
13651
            end
13652
 
13653
            if ( read_data[27:24] !== `BC_IO_WRITE )
13654
            begin
13655
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
13656
                ok = 0 ;
13657
            end
13658
 
13659
            if ( ok )
13660
                test_ok ;
13661
 
13662
            test_name = "CLEAR ERROR STATUS" ;
13663
            config_write( offset, read_data, 4'hF, ok ) ;
13664
            if ( !ok )
13665
                test_fail("PCI Error Control and Status register could not be written") ;
13666
 
13667
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
13668
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13669
            config_read ( offset, 4'hf, read_data ) ;
13670
 
13671
            if ( read_data !== expect_address )
13672
            begin
13673
                test_fail("value in Erroneous Address register was incorrect") ;
13674
                ok = 0 ;
13675
            end
13676
 
13677
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13678
            config_read ( offset, 4'hf, read_data ) ;
13679
 
13680
            if ( read_data !== 32'hAAAA_AAAA )
13681
            begin
13682
                test_fail("value in Erroneous Data register was incorrect") ;
13683
                ok = 0 ;
13684
            end
13685
 
13686
            if ( ok )
13687
                test_ok ;
13688
 
13689
        end
13690
        else
13691
        begin
13692
            if ( read_data[8] !== 0 )
13693
            begin
13694
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
13695
                ok = 0 ;
13696
            end
13697
            else
13698
                test_ok ;
13699
        end
13700
 
13701
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13702
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
13703
        ok = 1 ;
13704
 
13705
        config_read ( offset, 4'hF, read_data ) ;
13706
        if ( enable_error_report && enable_error_interrupt )
13707
        begin
13708
            if ( read_data[2] !== 1 )
13709
            begin
13710
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
13711
                ok = 0 ;
13712
            end
13713
 
13714
            test_name = "CLEARING INTERRUPT STATUS" ;
13715
            config_write( offset, read_data, 4'hF, ok ) ;
13716
            if ( !ok )
13717
                test_fail("Interrupt Status register could not be written") ;
13718
        end
13719
        else
13720
        begin
13721
            if ( read_data[2] !== 0 )
13722
            begin
13723
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
13724
                ok = 0 ;
13725
            end
13726
        end
13727
 
13728
        if ( ok )
13729
            test_ok ;
13730
 
13731
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
13732
        `ifdef HOST
13733
 
13734
            repeat ( 4 )
13735
                @( posedge wb_clock ) ;
13736
 
13737
            if ( INT_O !== 0 )
13738
            begin
13739
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
13740
            end
13741
            else
13742
                test_ok ;
13743
 
13744
        `else
13745
            repeat ( 4 )
13746
                @( posedge pci_clock ) ;
13747
 
13748
            if ( INTA !== 1 )
13749
            begin
13750
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
13751
            end
13752
            else
13753
                test_ok ;
13754
 
13755
        `endif
13756
 
13757
        pci_address = pci_address + 1 ;
13758
        expect_address = expect_address + 1 ;
13759
    end
13760
 
13761
end
13762
endtask // test_target_io_err_wr
13763
 
13764
task test_pci_image ;
13765
    input [2:0]  image_num ;
13766
    reg   [11:0] pci_ctrl_offset ;
13767
    reg   [11:0] ctrl_offset ;
13768
    reg   [11:0] ba_offset ;
13769
    reg   [11:0] am_offset ;
13770
    reg   [11:0] ta_offset ;
13771
    reg   [7:0]  cache_lsize ;
13772
    reg          ok ;
13773
    reg          test_io ;
13774
    reg          test_mem ;
13775
begin
13776
    pci_ctrl_offset = 12'h4 ;
13777
    if (image_num === 0)
13778
    begin
13779
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
13780
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
13781
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
13782
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
13783
    end
13784
    else if (image_num === 1)
13785
    begin
13786
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13787
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13788
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13789
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13790
    end
13791
    else if (image_num === 2)
13792
    begin
13793
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13794
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13795
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13796
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13797
    end
13798
    else if (image_num === 3)
13799
    begin
13800
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13801
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13802
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13803
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13804
    end
13805
    else if (image_num === 4)
13806
    begin
13807
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13808
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13809
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13810
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13811
    end
13812
    else if (image_num === 5)
13813
    begin
13814
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13815
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13816
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13817
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13818
    end
13819
 
13820
    `ifdef HOST
13821
        test_io  = 1 ;
13822
        test_mem = 1 ;
13823
    `else
13824
        if (image_num == 1)
13825
            test_io = `PCI_BA1_MEM_IO ;
13826
        else if ( image_num == 2 )
13827
            test_io = `PCI_BA2_MEM_IO ;
13828
        else if ( image_num == 3 )
13829
            test_io = `PCI_BA3_MEM_IO ;
13830
        else if ( image_num == 4 )
13831
            test_io = `PCI_BA4_MEM_IO ;
13832
        else if ( image_num == 5 )
13833
            test_io = `PCI_BA5_MEM_IO ;
13834
 
13835
        test_mem = !test_io ;
13836
    `endif
13837
 
13838
    $display(" ");
13839
    $display("########################################################################") ;
13840
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
13841
    test_name = "PCI IMAGE SETTINGS" ;
13842
 
13843
    // Set Base Address of IMAGE
13844
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
13845
    if ( ok !== 1 )
13846
    begin
13847
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13848
        test_fail("PCI Base Address register could not be written") ;
13849
    end
13850
 
13851
    // Set Address Mask of IMAGE
13852
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13853
    if ( ok !== 1 )
13854
    begin
13855
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13856
        test_fail("PCI Address Mask register could not be written") ;
13857
    end
13858
 
13859
    // Set Translation Address of IMAGE
13860
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13861
    if ( ok !== 1 )
13862
    begin
13863
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13864
        test_fail("PCI Translation Address register could not be written") ;
13865
    end
13866
 
13867
// Following are defines for byte enable signals !
13868
//      Byte Masks
13869
//      `Test_Byte_0                            (4'b1110)
13870
//      `Test_Byte_1                            (4'b1101)
13871
//      `Test_Byte_2                            (4'b1011)
13872
//      `Test_Byte_3                            (4'b0111)
13873
//      `Test_Half_0                            (4'b1100)
13874
//      `Test_Half_1                            (4'b0011)
13875
//      `Test_All_Bytes                         (4'b0000)
13876
 
13877
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
13878
    // Set Cache Line Size
13879
    cache_lsize = 8'h4 ;
13880
 
13881
    $display(" ");
13882
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13883
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13884
    if ( ok !== 1 )
13885
    begin
13886
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13887
        test_fail("PCI Device Control and Status register could not be written") ;
13888
    end
13889
 
13890
    if (test_mem)
13891
    begin
13892
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
13893
        // Task test_normal_wr_rd has the following parameters:
13894
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13895
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13896
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13897
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
13898
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
13899
 
13900
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13901
        // Set Cache Line Size
13902
        cache_lsize = 8'h4 ;
13903
 
13904
        $display(" ");
13905
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13906
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13907
        if ( ok !== 1 )
13908
        begin
13909
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13910
            test_fail("Cache Line Size register could not be written" ) ;
13911
        end
13912
 
13913
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
13914
        // Task test_normal_wr_rd has the following parameters:
13915
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13916
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13917
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13918
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
13919
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
13920
 
13921
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13922
        // Set Cache Line Size
13923
        cache_lsize = 8'h8 ;
13924
 
13925
        $display(" ");
13926
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13927
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13928
        if ( ok !== 1 )
13929
        begin
13930
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13931
            test_fail("Cache Line Size register could not be written" ) ;
13932
        end
13933
 
13934
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
13935
        // Task test_normal_wr_rd has the following parameters:
13936
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13937
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13938
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13939
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
13940
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13941
 
13942
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13943
        // Set Cache Line Size
13944
        cache_lsize = 8'h4 ;
13945
 
13946
        $display(" ");
13947
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13948
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13949
        if ( ok !== 1 )
13950
        begin
13951
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13952
            test_fail("Cache Line Size register could not be written" ) ;
13953
        end
13954
 
13955
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
13956
        // Task test_normal_wr_rd has the following parameters:
13957
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13958
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13959
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13960
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
13961
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13962
 
13963
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13964
        $display(" ");
13965
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
13966
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13967
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13968
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
13969
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
13970
 
13971
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13972
        $display(" ");
13973
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
13974
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13975
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13976
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
13977
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
13978
 
13979
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13980
        $display(" ");
13981
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
13982
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13983
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13984
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
13985
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
13986
 
13987
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13988
        $display(" ");
13989
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
13990
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13991
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13992
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
13993
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
13994
    end
13995
 
13996
    if ( test_io )
13997
    begin
13998
        test_name = "PCI IMAGE SETTINGS" ;
13999
 
14000
        // Set Base Address of IMAGE
14001
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
14002
        if ( ok !== 1 )
14003
        begin
14004
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
14005
            test_fail("PCI Base Address register could not be written") ;
14006
        end
14007
 
14008
        // Set Address Mask of IMAGE
14009
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14010
        if ( ok !== 1 )
14011
        begin
14012
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
14013
            test_fail("PCI Address Mask register could not be written") ;
14014
        end
14015
 
14016
        // Set Translation Address of IMAGE
14017
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14018
        if ( ok !== 1 )
14019
        begin
14020
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
14021
            test_fail("PCI Translation Address register could not be written") ;
14022
        end
14023
 
14024
        // Set Cache Line Size
14025
        cache_lsize = 8'h4 ;
14026
 
14027
        $display(" ");
14028
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
14029
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
14030
        if ( ok !== 1 )
14031
        begin
14032
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
14033
            test_fail("Cache Line Size register could not be written" ) ;
14034
        end
14035
 
14036
        test_target_io_wr_rd
14037
        (
14038
            image_num,    // image number
14039
            0,            // test with address translation
14040
            ctrl_offset   // image control register offset
14041
        ) ;
14042
 
14043
        test_target_io_wr_rd
14044
        (
14045
            image_num,    // image number
14046
            1,            // test with address translation
14047
            ctrl_offset   // image control register offset
14048
        ) ;
14049
 
14050
        test_target_io_err_wr
14051
        (
14052
            image_num,      // image number
14053
            0,              // address translation on/off
14054
            ctrl_offset,    // image control register offset
14055
            0,              // enable error reporting
14056
 
14057
        ) ;
14058
 
14059
        test_target_io_err_wr
14060
        (
14061
            image_num,      // image number
14062
            1,              // address translation on/off
14063
            ctrl_offset,    // image control register offset
14064
            0,              // enable error reporting
14065
            1               // enable error interrupts
14066
        ) ;
14067
 
14068
        test_target_io_err_wr
14069
        (
14070
            image_num,      // image number
14071
            0,              // address translation on/off
14072
            ctrl_offset,    // image control register offset
14073
            1,              // enable error reporting
14074
 
14075
        ) ;
14076
 
14077
        test_target_io_err_wr
14078
        (
14079
            image_num,      // image number
14080
            1,              // address translation on/off
14081
            ctrl_offset,    // image control register offset
14082
            1,              // enable error reporting
14083
            1               // enable error interrupts
14084
        ) ;
14085
    end
14086
 
14087
    // Test master abort with NON supported commands
14088
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
14089
 
14090
    // disable the image
14091
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14092
end
14093
endtask //test_pci_image
14094
 
14095
task target_fast_back_to_back ;
14096
    reg   [11:0] pci_ctrl_offset ;
14097
    reg   [11:0] ctrl_offset ;
14098
    reg   [11:0] ba_offset ;
14099
    reg   [11:0] am_offset ;
14100
    reg   [11:0] ta_offset ;
14101
    reg   [11:0] cls_offset ;
14102
    reg          do_mem_fb2b ;
14103
    reg          do_io_fb2b ;
14104
    reg          ok ;
14105
begin:main
14106
 
14107
    if ( target_mem_image !== -1 )
14108
    begin
14109
        do_mem_fb2b = 1 ;
14110
 
14111
        if (target_mem_image === 1)
14112
        begin
14113
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14114
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14115
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14116
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14117
        end
14118
        else if (target_mem_image === 2)
14119
        begin
14120
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14121
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14122
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14123
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14124
        end
14125
        else if (target_mem_image === 3)
14126
        begin
14127
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14128
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14129
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14130
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14131
        end
14132
        else if (target_mem_image === 4)
14133
        begin
14134
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14135
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14136
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14137
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14138
        end
14139
        else if (target_mem_image === 5)
14140
        begin
14141
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14142
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14143
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14144
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14145
        end
14146
    end
14147
    else
14148
        do_mem_fb2b = 0 ;
14149
 
14150
    pci_ctrl_offset = 12'h4 ;
14151
    cls_offset      = 12'h00C ;
14152
 
14153
    if ( do_mem_fb2b )
14154
    begin
14155
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
14156
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
14157
        if ( ok !== 1 )
14158
        begin
14159
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14160
            test_fail("PCI Base Address register could not be written") ;
14161
            disable main ;
14162
        end
14163
 
14164
        // Set Address Mask of IMAGE
14165
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
14166
        if ( ok !== 1 )
14167
        begin
14168
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14169
            test_fail("PCI Address Mask register could not be written") ;
14170
            disable main ;
14171
        end
14172
 
14173
        // Set Translation Address of IMAGE
14174
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14175
        if ( ok !== 1 )
14176
        begin
14177
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14178
            test_fail("PCI Translation Address Register could not be written") ;
14179
            disable main ;
14180
        end
14181
 
14182
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14183
        if ( ok !== 1 )
14184
        begin
14185
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14186
            test_fail("PCI Image Control register could not be written") ;
14187
            disable main ;
14188
        end
14189
 
14190
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14191
        if ( ok !== 1 )
14192
        begin
14193
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14194
            test_fail("Cache Line Size register could not be written") ;
14195
            disable main ;
14196
        end
14197
 
14198
        // enable master 1 fast_b2b
14199
        configuration_cycle_write(0,             // bus number
14200
                                  1,             // device number
14201
                                  0,             // function number
14202
                                  1,             // register number
14203
                                  0,             // type of configuration cycle
14204
                                  4'b1111,       // byte enables
14205
                                  32'hFFFF_FFFF  // data
14206
                                 ) ;
14207
 
14208
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14209
 
14210
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
14211
        fork
14212
        begin
14213
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14214
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14215
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14216
                  0, `Test_One_Zero_Target_WS,
14217
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14218
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14219
 
14220
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14221
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14222
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14223
                  0, `Test_One_Zero_Target_WS,
14224
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14225
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14226
            do_pause(5) ;
14227
 
14228
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14229
        end
14230
        begin:wb_monitor1
14231
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14232
            if ( ok !== 1 )
14233
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14234
 
14235
            disable monitor_error_event1 ;
14236
        end
14237
        begin:monitor_error_event1
14238
            @(error_event_int) ;
14239
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14240
            ok = 0 ;
14241
            disable wb_monitor1 ;
14242
        end
14243
        join
14244
 
14245
        if ( ok )
14246
            test_ok ;
14247
 
14248
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
14249
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14250
        fork
14251
        begin
14252
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14253
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14254
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14255
                  0, `Test_One_Zero_Target_WS,
14256
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14257
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14258
 
14259
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
14260
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14261
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14262
                  0, `Test_One_Zero_Target_WS,
14263
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14264
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14265
            do_pause(5) ;
14266
 
14267
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14268
 
14269
        end
14270
        begin:wb_monitor2
14271
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
14272
            if ( ok !== 1 )
14273
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14274
            else
14275
            begin
14276
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
14277
                if ( ok !== 1 )
14278
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14279
            end
14280
 
14281
            disable monitor_error_event2 ;
14282
        end
14283
        begin:monitor_error_event2
14284
            @(error_event_int) ;
14285
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14286
            ok = 0 ;
14287
            disable wb_monitor2 ;
14288
        end
14289
        join
14290
 
14291
        if ( ok )
14292
            test_ok ;
14293
 
14294
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
14295
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14296
        fork
14297
        begin
14298
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14299
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14300
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14301
                  0, `Test_One_Zero_Target_WS,
14302
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14303
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14304
 
14305
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14306
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14307
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14308
                  0, `Test_One_Zero_Target_WS,
14309
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14310
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14311
            do_pause(5) ;
14312
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14313
 
14314
        end
14315
        begin:wb_monitor3
14316
            fork
14317
            begin
14318
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14319
                if ( ok !== 1 )
14320
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14321
            end
14322
            begin
14323
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
14324
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
14325
                if ( ok !== 1 )
14326
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14327
            end
14328
            join
14329
 
14330
            if ( ok )
14331
            begin
14332
                fork
14333
                begin
14334
                    do_pause(3) ;
14335
 
14336
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14337
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
14338
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14339
                        0, `Test_One_Zero_Target_WS,
14340
                        `Test_Devsel_Medium, `Test_Fast_B2B,
14341
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14342
 
14343
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14344
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14345
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14346
                            0, `Test_One_Zero_Target_WS,
14347
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14348
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14349
 
14350
                    do_pause(1) ;
14351
                end
14352
                begin
14353
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
14354
                    if ( ok !== 1 )
14355
                    begin
14356
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14357
                        disable monitor_error_event3 ;
14358
                    end
14359
                    else
14360
                    begin
14361
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
14362
                        if ( ok !== 1 )
14363
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14364
                    end
14365
                end
14366 26 mihad
                begin
14367
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14368
                        if ( ok !== 1 )
14369
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14370
                end
14371 15 mihad
                join
14372
            end
14373
            disable monitor_error_event3 ;
14374
        end
14375
        begin:monitor_error_event3
14376
            @(error_event_int) ;
14377
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14378
            ok = 0 ;
14379
            disable wb_monitor3 ;
14380
        end
14381
        join
14382
 
14383
        if ( ok )
14384
            test_ok ;
14385
 
14386
        test_name = "DISABLING MEM IMAGE" ;
14387
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14388
        if ( ok !== 1 )
14389
        begin
14390
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14391
            test_fail("PCI Address Mask register could not be written") ;
14392
            disable main ;
14393
        end
14394
    end
14395
 
14396
    if ( target_io_image !== -1 )
14397
    begin
14398
        do_io_fb2b = 1 ;
14399
 
14400
        if (target_io_image === 1)
14401
        begin
14402
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14403
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14404
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14405
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14406
        end
14407
        else if (target_io_image === 2)
14408
        begin
14409
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14410
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14411
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14412
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14413
        end
14414
        else if (target_io_image === 3)
14415
        begin
14416
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14417
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14418
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14419
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14420
        end
14421
        else if (target_io_image === 4)
14422
        begin
14423
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14424
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14425
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14426
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14427
        end
14428
        else if (target_io_image === 5)
14429
        begin
14430
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14431
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14432
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14433
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14434
        end
14435
    end
14436
    else
14437
        do_io_fb2b = 0 ;
14438
 
14439
    if ( do_io_fb2b )
14440
    begin
14441
 
14442
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
14443
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14444
        if ( ok !== 1 )
14445
        begin
14446
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14447
            test_fail("PCI Base Address register could not be written") ;
14448
            disable main ;
14449
        end
14450
 
14451
        // Set Address Mask of IMAGE
14452
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
14453
        if ( ok !== 1 )
14454
        begin
14455
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14456
            test_fail("PCI Address Mask register could not be written") ;
14457
            disable main ;
14458
        end
14459
 
14460
        // Set Translation Address of IMAGE
14461
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
14462
        if ( ok !== 1 )
14463
        begin
14464
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14465
            test_fail("PCI Translation Address Register could not be written") ;
14466
            disable main ;
14467
        end
14468
 
14469
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14470
        if ( ok !== 1 )
14471
        begin
14472
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14473
            test_fail("PCI Image Control register could not be written") ;
14474
            disable main ;
14475
        end
14476
 
14477
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14478
        if ( ok !== 1 )
14479
        begin
14480
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14481
            test_fail("Cache Line Size register could not be written") ;
14482
            disable main ;
14483
        end
14484
 
14485
        // enable master 1 fast_b2b
14486
        configuration_cycle_write(0,             // bus number
14487
                                  1,             // device number
14488
                                  0,             // function number
14489
                                  1,             // register number
14490
                                  0,             // type of configuration cycle
14491
                                  4'b1111,       // byte enables
14492
                                  32'hFFFF_FFFF  // data
14493
                                 ) ;
14494
 
14495
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14496
 
14497
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
14498
        fork
14499
        begin
14500
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
14501
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
14502
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14503
                  0, `Test_One_Zero_Target_WS,
14504
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14505
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14506
 
14507
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
14508
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
14509
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14510
                  0, `Test_One_Zero_Target_WS,
14511
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14512
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14513
            do_pause(5) ;
14514
 
14515
        end
14516
        begin:wb_monitor4
14517
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
14518
            if ( ok !== 1 )
14519
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14520
 
14521
            if ( ok )
14522
            begin
14523
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
14524
                if ( ok !== 1 )
14525
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14526
            end
14527
 
14528
            disable monitor_error_event4 ;
14529
        end
14530
        begin:monitor_error_event4
14531
            @(error_event_int) ;
14532
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14533
            ok = 0 ;
14534
            disable wb_monitor4 ;
14535
        end
14536
        join
14537
 
14538
        if ( ok )
14539
            test_ok ;
14540
 
14541
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
14542
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14543
        fork
14544
        begin
14545
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14546
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
14547
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14548
                  0, `Test_One_Zero_Target_WS,
14549
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14550
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14551
 
14552
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14553
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14554
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14555
                  0, `Test_One_Zero_Target_WS,
14556
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14557
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14558
            do_pause(5) ;
14559
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14560
        end
14561
        begin:wb_monitor5
14562
            fork
14563
            begin
14564
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
14565
                if ( ok !== 1 )
14566
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14567
            end
14568
            begin
14569
                wb_transaction_stop( 1 ) ;
14570
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
14571
                if ( ok !== 1 )
14572
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14573
            end
14574
            join
14575
 
14576
            if ( ok )
14577
            begin
14578
                fork
14579
                begin
14580
                    do_pause(3) ;
14581
 
14582
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14583
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
14584
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14585
                            0, `Test_One_Zero_Target_WS,
14586
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14587
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14588
 
14589
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14590
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14591
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14592
                            0, `Test_One_Zero_Target_WS,
14593
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14594
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14595
 
14596
                    do_pause(1) ;
14597
                end
14598
                begin
14599
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
14600
                    if ( ok !== 1 )
14601
                    begin
14602
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14603
                        disable monitor_error_event5 ;
14604
                    end
14605
                    else
14606
                    begin
14607
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
14608
                        if ( ok !== 1 )
14609
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14610
                    end
14611
                end
14612
                join
14613
            end
14614
            disable monitor_error_event5 ;
14615
        end
14616
        begin:monitor_error_event5
14617
            @(error_event_int) ;
14618
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14619
            ok = 0 ;
14620
            disable wb_monitor5 ;
14621
        end
14622
        join
14623
 
14624
        if ( ok )
14625
            test_ok ;
14626
 
14627
        test_name = "DISABLING IO IMAGE" ;
14628
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14629
        if ( ok !== 1 )
14630
        begin
14631
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14632
            test_fail("PCI Address Mask register could not be written") ;
14633
            disable main ;
14634
        end
14635
    end
14636
 
14637
end
14638
endtask //target_fast_back_to_back
14639
 
14640
task target_disconnects ;
14641
    reg   [11:0] pci_ctrl_offset ;
14642
    reg   [11:0] ctrl_offset ;
14643
    reg   [11:0] ba_offset ;
14644
    reg   [11:0] am_offset ;
14645
    reg   [11:0] ta_offset ;
14646
    reg   [11:0] cls_offset ;
14647
    reg          pci_ok ;
14648
    reg          wb_ok ;
14649
    reg          ok ;
14650
    reg   [31:0] pci_address ;
14651
    reg   [31:0] data ;
14652
    reg   [3:0]  byte_enables ;
14653
    reg   [9:0]  expect_length ;
14654
 
14655
    reg          do_mem_disconnects ;
14656
    reg          do_io_disconnects ;
14657 35 mihad
    reg          error_monitor_done ;
14658 15 mihad
begin:main
14659
    if ( target_mem_image !== -1 )
14660
    begin
14661
        do_mem_disconnects = 1 ;
14662
 
14663
        if (target_mem_image === 1)
14664
        begin
14665
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14666
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14667
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14668
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14669
        end
14670
        else if (target_mem_image === 2)
14671
        begin
14672
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14673
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14674
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14675
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14676
        end
14677
        else if (target_mem_image === 3)
14678
        begin
14679
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14680
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14681
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14682
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14683
        end
14684
        else if (target_mem_image === 4)
14685
        begin
14686
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14687
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14688
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14689
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14690
        end
14691
        else if (target_mem_image === 5)
14692
        begin
14693
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14694
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14695
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14696
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14697
        end
14698
    end
14699
    else
14700
        do_mem_disconnects = 0 ;
14701
 
14702
    pci_ctrl_offset = 12'h4 ;
14703
    cls_offset = 12'h00C ;
14704
 
14705
    master1_check_received_data = 0 ;
14706
    master2_check_received_data = 0 ;
14707
 
14708
    `ifdef HOST
14709
        `ifdef NO_CNF_IMAGE
14710
        `else
14711
            `define TEST_BURST_CONFIG_READ
14712
        `endif
14713
    `else
14714
        `define TEST_BURST_CONFIG_READ
14715
        `define TEST_BURST_CONFIG_WRITE
14716
    `endif
14717
 
14718
    `ifdef TEST_BURST_CONFIG_WRITE
14719
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14720
 
14721
        data = 32'h0000_08_08 ;
14722
 
14723
        test_name = "TARGET DISCONNECT ON BURST WRITE TO CONFIGURATION SPACE" ;
14724
        byte_enables = 4'b0000 ;
14725
 
14726
        fork
14727
        begin
14728
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14729
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14730
                    byte_enables,
14731
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14732
                    8'h0_0, `Test_One_Zero_Target_WS,
14733
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14734
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14735
 
14736
            data = 32'h0000_04_04 ;
14737
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14738
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14739
                    byte_enables,
14740
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14741
                    8'h0_0, `Test_One_Zero_Target_WS,
14742
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14743
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14744
            do_pause( 1 ) ;
14745
            while ( FRAME !== 1 || IRDY !== 1 )
14746
                @(posedge pci_clock) ;
14747
 
14748 35 mihad
            #1 ;
14749
            if ( !error_monitor_done )
14750
                disable monitor_error_event1 ;
14751 15 mihad
        end
14752
        begin:monitor_error_event1
14753 35 mihad
            error_monitor_done = 0 ;
14754 15 mihad
            ok = 1 ;
14755
            @(error_event_int) ;
14756
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14757
            ok = 0 ;
14758 35 mihad
            error_monitor_done = 1 ;
14759 15 mihad
        end
14760
        join
14761
 
14762
        config_read(pci_address, 4'hF, data) ;
14763
        if ( data [15:0] !== 16'h04_04 )
14764
        begin
14765
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14766
        end
14767
        else if ( ok )
14768
            test_ok ;
14769
 
14770
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14771
        data         = 32'h0000_0808 ;
14772
        byte_enables = 4'h0 ;
14773
        fork
14774
        begin
14775
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14776
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14777
                    byte_enables,
14778
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14779
                    8'h0_0, `Test_One_Zero_Target_WS,
14780
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14781
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14782
 
14783
            data = 32'h0000_04_04 ;
14784
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14785
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14786
                    byte_enables,
14787
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14788
                    8'h0_0, `Test_One_Zero_Target_WS,
14789
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14790
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14791
 
14792
            do_pause( 1 ) ;
14793
            while ( FRAME !== 1 || IRDY !== 1 )
14794
                @(posedge pci_clock) ;
14795
 
14796 35 mihad
            #1 ;
14797
            if ( !error_monitor_done )
14798
                disable monitor_error_event2 ;
14799 15 mihad
        end
14800
        begin:monitor_error_event2
14801 35 mihad
            error_monitor_done = 0 ;
14802 15 mihad
            ok = 1 ;
14803
            @(error_event_int) ;
14804
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14805
            ok = 0 ;
14806 35 mihad
            error_monitor_done = 1 ;
14807 15 mihad
        end
14808
        join
14809
 
14810
        config_read(pci_address, 4'hF, data) ;
14811
        if ( data [15:0] !== 16'h04_04 )
14812
        begin
14813
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14814
        end
14815
        else if ( ok )
14816
            test_ok ;
14817
    `endif
14818
 
14819
    `ifdef TEST_BURST_CONFIG_READ
14820
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14821
 
14822
        data = 32'h0000_04_04 ;
14823
 
14824
        test_name = "TARGET DISCONNECT ON BURST READ FROM CONFIGURATION SPACE" ;
14825
        byte_enables = 4'b0000 ;
14826
 
14827
        fork
14828
        begin
14829
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14830
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14831
                    byte_enables,
14832
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14833
                    8'h0_0, `Test_One_Zero_Target_WS,
14834
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14835
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14836
            do_pause( 1 ) ;
14837
 
14838
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14839
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14840
                    byte_enables,
14841
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14842
                    8'h0_0, `Test_One_Zero_Target_WS,
14843
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14844
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14845
            do_pause( 1 ) ;
14846
 
14847
            while ( FRAME !== 1 || IRDY !== 1 )
14848
                @(posedge pci_clock) ;
14849
 
14850 35 mihad
            if ( !error_monitor_done )
14851
                disable monitor_error_event3 ;
14852 15 mihad
        end
14853
        begin:monitor_error_event3
14854 35 mihad
            error_monitor_done = 0 ;
14855 15 mihad
            ok = 1 ;
14856
            @(error_event_int) ;
14857
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14858
            ok = 0 ;
14859 35 mihad
            error_monitor_done = 1 ;
14860 15 mihad
        end
14861
        join
14862
 
14863
        if ( ok )
14864
            test_ok ;
14865
 
14866
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14867
        fork
14868
        begin
14869
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14870
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14871
                    byte_enables,
14872
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14873
                    8'h0_0, `Test_One_Zero_Target_WS,
14874
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14875
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14876
            do_pause( 1 ) ;
14877
 
14878
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14879
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14880
                    byte_enables,
14881
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14882
                    8'h0_0, `Test_One_Zero_Target_WS,
14883
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14884
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14885
            do_pause( 1 ) ;
14886
 
14887
            while ( FRAME !== 1 || IRDY !== 1 )
14888
                @(posedge pci_clock) ;
14889
 
14890 35 mihad
            #1 ;
14891
            if ( !error_monitor_done )
14892
                disable monitor_error_event4 ;
14893 15 mihad
        end
14894
        begin:monitor_error_event4
14895 35 mihad
            error_monitor_done = 0 ;
14896 15 mihad
            ok = 1 ;
14897
            @(error_event_int) ;
14898
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14899
            ok = 0 ;
14900 35 mihad
            error_monitor_done = 1 ;
14901 15 mihad
        end
14902
        join
14903
 
14904
        if ( ok )
14905
            test_ok ;
14906
    `endif
14907
 
14908
    `ifdef TEST_BURST_CONFIG_READ
14909
        `undef TEST_BURST_CONFIG_READ
14910
    `endif
14911
 
14912
    `ifdef TEST_BURST_CONFIG_WRITE
14913
        `undef TEST_BURST_CONFIG_WRITE
14914
    `endif
14915
 
14916
    master1_check_received_data = 1 ;
14917
    master2_check_received_data = 1 ;
14918
 
14919
    if ( do_mem_disconnects )
14920
    begin
14921
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
14922
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
14923
        if ( ok !== 1 )
14924
        begin
14925
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14926
            test_fail("PCI Base Address register could not be written") ;
14927
            disable main ;
14928
        end
14929
 
14930
        // Set Address Mask of IMAGE
14931
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
14932
        if ( ok !== 1 )
14933
        begin
14934
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14935
            test_fail("PCI Address Mask register could not be written") ;
14936
            disable main ;
14937
        end
14938
 
14939
        // Set Translation Address of IMAGE
14940
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14941
        if ( ok !== 1 )
14942
        begin
14943
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14944
            test_fail("PCI Translation Address Register could not be written") ;
14945
            disable main ;
14946
        end
14947
 
14948
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14949
        if ( ok !== 1 )
14950
        begin
14951
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14952
            test_fail("PCI Image Control register could not be written") ;
14953
            disable main ;
14954
        end
14955
 
14956
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
14957
        if ( ok !== 1 )
14958
        begin
14959
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14960
            test_fail("Cache Line Size register could not be written") ;
14961
            disable main ;
14962
        end
14963
 
14964
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14965
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14966
        data = 32'hAAAA_AAAA ;
14967
        byte_enables = 4'h0 ;
14968
        expect_length = `PCIW_DEPTH - 2 ;
14969
 
14970
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14971
        fork
14972
        begin
14973
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14974
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14975
                        byte_enables,
14976
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
14977
                        8'h0_0, `Test_One_Zero_Target_WS,
14978
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14979
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14980
            do_pause( 3 ) ;
14981
 
14982
            while ( FRAME !== 1 || IRDY !== 1 )
14983
                @(posedge pci_clock) ;
14984
 
14985 35 mihad
            #1 ;
14986
            if ( !error_monitor_done )
14987
                disable monitor_error_event5 ;
14988 15 mihad
        end
14989
        begin:monitor_error_event5
14990 35 mihad
            error_monitor_done = 0 ;
14991 15 mihad
            pci_ok = 1 ;
14992
            @(error_event_int) ;
14993
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14994
            pci_ok = 0 ;
14995 35 mihad
            error_monitor_done = 1 ;
14996 15 mihad
        end
14997
        begin
14998
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14999
            if ( wb_ok !== 1 )
15000
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15001
        end
15002
        join
15003
 
15004
        if ( wb_ok && pci_ok )
15005
            test_ok ;
15006
 
15007
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
15008
        pci_address = Target_Base_Addr_R[target_mem_image] ;
15009
        data = 32'hAAAA_AAAA ;
15010
        byte_enables = 4'h0 ;
15011
        expect_length = `PCIW_DEPTH - 2 ;
15012
 
15013
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15014
        fork
15015
        begin
15016
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
15017
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15018
                        byte_enables,
15019
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
15020
                        8'h0_0, `Test_One_Zero_Target_WS,
15021
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15022
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15023
            do_pause( 3 ) ;
15024
 
15025
            while ( FRAME !== 1 || IRDY !== 1 )
15026
                @(posedge pci_clock) ;
15027
 
15028 35 mihad
            #1 ;
15029
            if ( !error_monitor_done )
15030
                disable monitor_error_event6 ;
15031 15 mihad
        end
15032
        begin:monitor_error_event6
15033 35 mihad
            error_monitor_done = 0 ;
15034 15 mihad
            pci_ok = 1 ;
15035
            @(error_event_int) ;
15036
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15037
            pci_ok = 0 ;
15038 35 mihad
            error_monitor_done = 1 ;
15039 15 mihad
        end
15040
        begin
15041
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15042
            if ( wb_ok !== 1 )
15043
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15044
        end
15045
        join
15046
 
15047
        if ( wb_ok && pci_ok )
15048
            test_ok ;
15049
 
15050
        master1_check_received_data = 1 ;
15051
//        master2_check_received_data = 0 ;
15052
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
15053
        pci_address = Target_Base_Addr_R[target_mem_image] ;
15054
        data = 32'hAAAA_AAAA ;
15055
        byte_enables = 4'h0 ;
15056
        expect_length = 4 ;
15057
 
15058
        fork
15059
        begin
15060
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15061
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15062
                        byte_enables,
15063
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15064
                        8'h0_0, `Test_One_Zero_Target_WS,
15065
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15066
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15067
            do_pause( 1 ) ;
15068
 
15069
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15070
            if ( wb_ok !== 1 )
15071
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15072
 
15073
            do_pause(2) ;
15074
 
15075
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15076
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15077
                        byte_enables,
15078
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15079
                        8'h0_0, `Test_One_Zero_Target_WS,
15080
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15081
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
15082
            do_pause( 3 ) ;
15083
 
15084
            while ( FRAME !== 1 || IRDY !== 1 )
15085
                @(posedge pci_clock) ;
15086
 
15087 35 mihad
            #1 ;
15088
            if ( !error_monitor_done )
15089
                disable monitor_error_event7 ;
15090 15 mihad
        end
15091
        begin:monitor_error_event7
15092 35 mihad
            error_monitor_done = 0 ;
15093 15 mihad
            pci_ok = 1 ;
15094
            @(error_event_int) ;
15095
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15096
            pci_ok = 0 ;
15097 35 mihad
            error_monitor_done = 1 ;
15098 15 mihad
        end
15099
        join
15100
 
15101
        if ( wb_ok && pci_ok )
15102
            test_ok ;
15103
 
15104
        master1_check_received_data = 1 ;
15105
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
15106
        pci_address = Target_Base_Addr_R[target_mem_image] ;
15107
        data = 32'hAAAA_AAAA ;
15108
        byte_enables = 4'h0 ;
15109
        expect_length = 4 ;
15110
 
15111
        fork
15112
        begin
15113
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15114
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15115
                        byte_enables,
15116
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15117
                        8'h0_0, `Test_One_Zero_Target_WS,
15118
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15119
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15120
            do_pause( 1 ) ;
15121
 
15122
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15123
            if ( wb_ok !== 1 )
15124
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15125
 
15126
            do_pause(2) ;
15127
 
15128
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15129
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15130
                        byte_enables,
15131
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15132
                        8'h0_0, `Test_One_Zero_Target_WS,
15133
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15134
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
15135
            do_pause( 3 ) ;
15136
 
15137
            while ( FRAME !== 1 || IRDY !== 1 )
15138
                @(posedge pci_clock) ;
15139
 
15140 35 mihad
            #1 ;
15141
            if ( !error_monitor_done )
15142
                disable monitor_error_event8 ;
15143 15 mihad
        end
15144
        begin:monitor_error_event8
15145 35 mihad
            error_monitor_done = 0 ;
15146 15 mihad
            pci_ok = 1 ;
15147
            @(error_event_int) ;
15148
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15149
            pci_ok = 0 ;
15150 35 mihad
            error_monitor_done = 1 ;
15151 15 mihad
        end
15152
        join
15153
 
15154
        if ( wb_ok && pci_ok )
15155
            test_ok ;
15156
 
15157
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
15158
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
15159
        data = 32'hDEAF_BEAF ;
15160
        byte_enables = 4'h0 ;
15161
        expect_length = 1 ;
15162
 
15163
        fork
15164
        begin
15165
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15166
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15167
                        byte_enables,
15168
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15169
                        8'h0_0, `Test_One_Zero_Target_WS,
15170
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15171
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
15172
            do_pause( 3 ) ;
15173
 
15174
            while ( FRAME !== 1 || IRDY !== 1 )
15175
                @(posedge pci_clock) ;
15176
 
15177 35 mihad
            #1 ;
15178
            if ( !error_monitor_done )
15179
                disable monitor_error_event9 ;
15180 15 mihad
        end
15181
        begin:monitor_error_event9
15182 35 mihad
            error_monitor_done = 0 ;
15183 15 mihad
            pci_ok = 1 ;
15184
            @(error_event_int) ;
15185
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15186
            pci_ok = 0 ;
15187 35 mihad
            error_monitor_done = 1 ;
15188 15 mihad
        end
15189
        begin
15190
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15191
            if ( wb_ok !== 1 )
15192
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15193
        end
15194
        join
15195
 
15196
        if ( wb_ok && pci_ok )
15197
            test_ok ;
15198
 
15199
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
15200
        data = 32'hDEAD_BEAF ;
15201
        byte_enables = 4'h0 ;
15202
        expect_length = 1 ;
15203
 
15204
        fork
15205
        begin
15206
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15207
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15208
                        byte_enables,
15209
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15210
                        8'h0_0, `Test_One_Zero_Target_WS,
15211
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15212
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15213
            do_pause( 3 ) ;
15214
 
15215
            while ( FRAME !== 1 || IRDY !== 1 )
15216
                @(posedge pci_clock) ;
15217
 
15218 35 mihad
            #1 ;
15219
            if ( !error_monitor_done )
15220
                disable monitor_error_event10 ;
15221 15 mihad
        end
15222
        begin:monitor_error_event10
15223 35 mihad
            error_monitor_done = 0 ;
15224 15 mihad
            pci_ok = 1 ;
15225
            @(error_event_int) ;
15226
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15227
            pci_ok = 0 ;
15228 35 mihad
            error_monitor_done = 1 ;
15229 15 mihad
        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
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15241
        data = 32'hAAAA_AAAA ;
15242
        byte_enables = 4'h0 ;
15243
        expect_length = 1 ;
15244
 
15245
        fork
15246
        begin
15247
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15248
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15249
                        byte_enables,
15250
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15251
                        8'h0_0, `Test_One_Zero_Target_WS,
15252
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15253
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15254
            do_pause( 3 ) ;
15255
 
15256
            while ( FRAME !== 1 || IRDY !== 1 )
15257
                @(posedge pci_clock) ;
15258
 
15259 35 mihad
            #1 ;
15260
            if ( !error_monitor_done )
15261
                disable monitor_error_event11 ;
15262 15 mihad
        end
15263
        begin:monitor_error_event11
15264 35 mihad
            error_monitor_done = 0 ;
15265 15 mihad
            pci_ok = 1 ;
15266
            @(error_event_int) ;
15267
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15268
            pci_ok = 0 ;
15269 35 mihad
            error_monitor_done = 1 ;
15270 15 mihad
        end
15271
        begin
15272
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15273
            if ( wb_ok !== 1 )
15274
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15275
        end
15276
        join
15277
 
15278
        if ( wb_ok && pci_ok )
15279
            test_ok ;
15280
 
15281
        master1_check_received_data = 1 ;
15282
 
15283
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
15284
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
15285
        data = 32'hDEAF_BEAF ;
15286
        byte_enables = 4'h0 ;
15287
        expect_length = 1 ;
15288
 
15289
        fork
15290
        begin
15291
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15292
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15293
                        byte_enables,
15294
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15295
                        8'h0_0, `Test_One_Zero_Target_WS,
15296
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15297
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15298
            do_pause( 1 ) ;
15299
 
15300
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15301
            if ( wb_ok !== 1 )
15302
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15303
 
15304
            do_pause(3) ;
15305
 
15306
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15307
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15308
                        byte_enables,
15309
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15310
                        8'h0_0, `Test_One_Zero_Target_WS,
15311
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15312
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
15313
            do_pause( 3 ) ;
15314
 
15315
            while ( FRAME !== 1 || IRDY !== 1 )
15316
                @(posedge pci_clock) ;
15317
 
15318 35 mihad
            #1 ;
15319
            if ( !error_monitor_done )
15320
                disable monitor_error_event12 ;
15321 15 mihad
        end
15322
        begin:monitor_error_event12
15323 35 mihad
            error_monitor_done = 0 ;
15324 15 mihad
            pci_ok = 1 ;
15325
            @(error_event_int) ;
15326
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15327
            pci_ok = 0 ;
15328 35 mihad
            error_monitor_done = 1 ;
15329 15 mihad
        end
15330
        join
15331
 
15332
        if ( wb_ok && pci_ok )
15333
            test_ok ;
15334
 
15335
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
15336
        data = 32'hDEAD_BEAF ;
15337
        byte_enables = 4'h0 ;
15338
        expect_length = 1 ;
15339
 
15340
        fork
15341
        begin
15342
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15343
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15344
                        byte_enables,
15345
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15346
                        8'h0_0, `Test_One_Zero_Target_WS,
15347
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15348
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15349
            do_pause( 1 ) ;
15350
 
15351
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15352
            if ( wb_ok !== 1 )
15353
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15354
 
15355
            do_pause(3) ;
15356
 
15357
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15358
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15359
                        byte_enables,
15360
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15361
                        8'h0_0, `Test_One_Zero_Target_WS,
15362
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15363
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15364
            do_pause( 3 ) ;
15365
 
15366
            while ( FRAME !== 1 || IRDY !== 1 )
15367
                @(posedge pci_clock) ;
15368
 
15369 35 mihad
            #1 ;
15370
            if ( !error_monitor_done )
15371
                disable monitor_error_event13 ;
15372 15 mihad
        end
15373
        begin:monitor_error_event13
15374 35 mihad
            error_monitor_done = 0 ;
15375 15 mihad
            pci_ok = 1 ;
15376
            @(error_event_int) ;
15377
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15378
            pci_ok = 0 ;
15379 35 mihad
            error_monitor_done = 1 ;
15380 15 mihad
        end
15381
        join
15382
 
15383
        if ( wb_ok && pci_ok )
15384
            test_ok ;
15385
 
15386
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15387
        data = 32'hAAAA_AAAA ;
15388
        byte_enables = 4'h0 ;
15389
        expect_length = 1 ;
15390
 
15391
        fork
15392
        begin
15393
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15394
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15395
                        byte_enables,
15396
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15397
                        8'h0_0, `Test_One_Zero_Target_WS,
15398
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15399
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15400
            do_pause( 1 ) ;
15401
 
15402
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15403
            if ( wb_ok !== 1 )
15404
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15405
 
15406
            do_pause(3) ;
15407
 
15408
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15409
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15410
                        byte_enables,
15411
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15412
                        8'h0_0, `Test_One_Zero_Target_WS,
15413
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15414
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15415
            do_pause( 3 ) ;
15416
 
15417
            while ( FRAME !== 1 || IRDY !== 1 )
15418
                @(posedge pci_clock) ;
15419
 
15420 35 mihad
            #1 ;
15421
            if ( !error_monitor_done )
15422
                disable monitor_error_event14 ;
15423 15 mihad
        end
15424
        begin:monitor_error_event14
15425 35 mihad
            error_monitor_done = 0 ;
15426 15 mihad
            pci_ok = 1 ;
15427
            @(error_event_int) ;
15428
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15429
            pci_ok = 0 ;
15430 35 mihad
            error_monitor_done = 1 ;
15431 15 mihad
        end
15432
        join
15433
 
15434
        if ( wb_ok && pci_ok )
15435
            test_ok ;
15436
 
15437
        // disable the image
15438
        test_name = "DISABLING MEMORY IMAGE" ;
15439
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15440
        if ( ok !== 1 )
15441
        begin
15442
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15443
            test_fail("PCI Address Mask register could not be written") ;
15444
            disable main ;
15445
        end
15446
    end
15447
//*
15448
    if ( target_io_image !== -1 )
15449
    begin
15450
        do_io_disconnects = 1 ;
15451
 
15452
        if (target_io_image === 1)
15453
        begin
15454
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15455
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15456
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15457
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15458
        end
15459
        else if (target_io_image === 2)
15460
        begin
15461
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15462
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15463
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15464
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15465
        end
15466
        else if (target_io_image === 3)
15467
        begin
15468
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15469
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15470
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15471
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15472
        end
15473
        else if (target_io_image === 4)
15474
        begin
15475
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15476
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15477
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15478
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15479
        end
15480
        else if (target_io_image === 5)
15481
        begin
15482
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15483
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15484
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15485
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15486
        end
15487
    end
15488
    else
15489
        do_io_disconnects = 0 ;
15490
 
15491
    if ( do_io_disconnects )
15492
    begin
15493
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
15494
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
15495
        if ( ok !== 1 )
15496
        begin
15497
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15498
            test_fail("PCI Base Address register could not be written") ;
15499
            disable main ;
15500
        end
15501
 
15502
        // Set Address Mask of IMAGE
15503
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
15504
        if ( ok !== 1 )
15505
        begin
15506
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15507
            test_fail("PCI Address Mask register could not be written") ;
15508
            disable main ;
15509
        end
15510
 
15511
        // Set Translation Address of IMAGE
15512
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
15513
        if ( ok !== 1 )
15514
        begin
15515
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15516
            test_fail("PCI Translation Address Register could not be written") ;
15517
            disable main ;
15518
        end
15519
 
15520
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15521
        if ( ok !== 1 )
15522
        begin
15523
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
15524
            test_fail("PCI Image Control register could not be written") ;
15525
            disable main ;
15526
        end
15527
 
15528
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
15529
        if ( ok !== 1 )
15530
        begin
15531
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
15532
            test_fail("Cache Line Size register could not be written") ;
15533
            disable main ;
15534
        end
15535
 
15536
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
15537
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
15538
        data = 32'h5555_5555 ;
15539
        byte_enables = 4'h0 ;
15540
        expect_length = 1 ;
15541
 
15542
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15543
 
15544
        fork
15545
        begin
15546
            PCIU_IO_WRITE
15547
            (
15548
                `Test_Master_1,             // which master
15549
                pci_address,                // to what address
15550
                data,                       // data
15551
                byte_enables,               // byte enable
15552
                expect_length + 1,          // length to request
15553
                `Test_Target_Retry_On       // expected target termination
15554
            ) ;
15555
 
15556
            do_pause( 3 ) ;
15557
 
15558
            while ( FRAME !== 1 || IRDY !== 1 )
15559
                @(posedge pci_clock) ;
15560
 
15561 35 mihad
            #1 ;
15562
            if ( !error_monitor_done )
15563
                disable monitor_error_event15 ;
15564 15 mihad
        end
15565
        begin:monitor_error_event15
15566 35 mihad
            error_monitor_done = 0 ;
15567 15 mihad
            pci_ok = 1 ;
15568
            @(error_event_int) ;
15569
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15570
            pci_ok = 0 ;
15571 35 mihad
            error_monitor_done = 1 ;
15572 15 mihad
        end
15573
        begin
15574
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15575
            if ( wb_ok !== 1 )
15576
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15577
        end
15578
        join
15579
 
15580
        if ( wb_ok && pci_ok )
15581
            test_ok ;
15582
 
15583
        data = 32'hAAAA_AAAA ;
15584
        fork
15585
        begin
15586
            PCIU_IO_WRITE
15587
            (
15588
                `Test_Master_1,             // which master
15589
                pci_address,                // to what address
15590
                data,                       // data
15591
                byte_enables,               // byte enable
15592
                expect_length + 2,          // length to request
15593
                `Test_Target_Retry_Before   // expected target termination
15594
            ) ;
15595
 
15596
            do_pause( 3 ) ;
15597
 
15598
            while ( FRAME !== 1 || IRDY !== 1 )
15599
                @(posedge pci_clock) ;
15600
 
15601 35 mihad
            #1 ;
15602
            if ( !error_monitor_done )
15603
                disable monitor_error_event16 ;
15604 15 mihad
        end
15605
        begin:monitor_error_event16
15606 35 mihad
            error_monitor_done = 0 ;
15607 15 mihad
            pci_ok = 1 ;
15608
            @(error_event_int) ;
15609
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15610
            pci_ok = 0 ;
15611 35 mihad
            error_monitor_done = 1 ;
15612 15 mihad
        end
15613
        begin
15614
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15615
            if ( wb_ok !== 1 )
15616
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15617
        end
15618
        join
15619
 
15620
        if ( wb_ok && pci_ok )
15621
            test_ok ;
15622
 
15623
        master2_check_received_data = 1 ;
15624
 
15625
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
15626
 
15627
        fork
15628
        begin
15629
 
15630
             PCIU_IO_READ
15631
             (
15632
                `Test_Master_2,
15633
                pci_address[PCI_BUS_DATA_RANGE:0],
15634
                data,
15635
                byte_enables,
15636
                2,
15637
                `Test_Target_Retry_Before
15638
             );
15639
 
15640
            do_pause( 1 ) ;
15641
 
15642
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15643
            if ( wb_ok !== 1 )
15644
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15645
 
15646
            do_pause(3) ;
15647
 
15648
            PCIU_IO_READ
15649
             (
15650
                `Test_Master_2,
15651
                pci_address[PCI_BUS_DATA_RANGE:0],
15652
                data,
15653
                byte_enables,
15654
                expect_length + 1,
15655
                `Test_Target_Retry_On
15656
             );
15657
 
15658
            do_pause( 3 ) ;
15659
 
15660
            while ( FRAME !== 1 || IRDY !== 1 )
15661
                @(posedge pci_clock) ;
15662
 
15663 35 mihad
            #1 ;
15664
            if ( !error_monitor_done )
15665
                disable monitor_error_event17 ;
15666 15 mihad
        end
15667
        begin:monitor_error_event17
15668 35 mihad
            error_monitor_done = 0 ;
15669 15 mihad
            pci_ok = 1 ;
15670
            @(error_event_int) ;
15671
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15672
            pci_ok = 0 ;
15673 35 mihad
            error_monitor_done = 1 ;
15674 15 mihad
        end
15675
        join
15676
 
15677
        if ( wb_ok && pci_ok )
15678
            test_ok ;
15679
 
15680
        fork
15681
        begin
15682
 
15683
             PCIU_IO_READ
15684
             (
15685
                `Test_Master_2,
15686
                pci_address[PCI_BUS_DATA_RANGE:0],
15687
                data,
15688
                byte_enables,
15689
                2,
15690
                `Test_Target_Retry_Before
15691
             );
15692
 
15693
            do_pause( 1 ) ;
15694
 
15695
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15696
            if ( wb_ok !== 1 )
15697
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15698
 
15699
            do_pause(3) ;
15700
 
15701
            PCIU_IO_READ
15702
             (
15703
                `Test_Master_2,
15704
                pci_address[PCI_BUS_DATA_RANGE:0],
15705
                data,
15706
                byte_enables,
15707
                expect_length + 2,
15708
                `Test_Target_Retry_Before
15709
             );
15710
 
15711
            do_pause( 3 ) ;
15712
 
15713
            while ( FRAME !== 1 || IRDY !== 1 )
15714
                @(posedge pci_clock) ;
15715
 
15716 35 mihad
            #1 ;
15717
            if ( !error_monitor_done )
15718
                disable monitor_error_event18 ;
15719 15 mihad
        end
15720
        begin:monitor_error_event18
15721 35 mihad
            error_monitor_done = 0 ;
15722 15 mihad
            pci_ok = 1 ;
15723
            @(error_event_int) ;
15724
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15725
            pci_ok = 0 ;
15726 35 mihad
            error_monitor_done = 1 ;
15727 15 mihad
        end
15728
        join
15729
 
15730
        if ( wb_ok && pci_ok )
15731
            test_ok ;
15732
 
15733
        test_name = "DISABLING IO IMAGE" ;
15734
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15735
        if ( ok !== 1 )
15736
        begin
15737
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15738
            test_fail("PCI Address Mask register could not be written") ;
15739
            disable main ;
15740
        end
15741
    end
15742
//*/
15743
end
15744
endtask // target_disconnects
15745
 
15746
task target_unsupported_cmds ;
15747
        input [31:0] Address;
15748
        input [2:0]  image_num ;
15749
    reg          ok ;
15750
begin:main
15751
        // PCI IACK behavioral Target must NOT respond!!!
15752
    irq_respond = 0 ;
15753
 
15754
    $display("  ") ;
15755
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
15756
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
15757
    ipci_unsupported_commands_master.master_reference
15758
    (
15759
        Address,                // first part of address in dual address cycle
15760
        Address,                // second part of address in dual address cycle
15761
        `BC_IACK,                       // dual address cycle command
15762
        `BC_IACK,               // normal command
15763
        4'h0,               // byte enables
15764
        32'h1234_5678,      // data
15765
        1'b0,               // make address parity error on first phase of dual address
15766
        1'b0,               // make address parity error on second phase of dual address
15767
        ok                  // result of operation
15768
    ) ;
15769
    if ( ok )
15770
        test_ok ;
15771
    else
15772
    begin
15773
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15774
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
15775
    end
15776
 
15777
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
15778
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
15779
    ipci_unsupported_commands_master.master_reference
15780
    (
15781
        Address,                // first part of address in dual address cycle
15782
        Address,                // second part of address in dual address cycle
15783
        `BC_SPECIAL,            // dual address cycle command
15784
        `BC_SPECIAL,            // normal command
15785
        4'h0,               // byte enables
15786
        32'h1234_5678,      // data
15787
        1'b0,               // make address parity error on first phase of dual address
15788
        1'b0,               // make address parity error on second phase of dual address
15789
        ok                  // result of operation
15790
    ) ;
15791
    if ( ok )
15792
        test_ok ;
15793
    else
15794
    begin
15795
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15796
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
15797
    end
15798
 
15799
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
15800
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
15801
    ipci_unsupported_commands_master.master_reference
15802
    (
15803
        Address,                // first part of address in dual address cycle
15804
        Address,                // second part of address in dual address cycle
15805
        `BC_RESERVED0,          // dual address cycle command
15806
        `BC_RESERVED0,      // normal command
15807
        4'h0,               // byte enables
15808
        32'h1234_5678,      // data
15809
        1'b0,               // make address parity error on first phase of dual address
15810
        1'b0,               // make address parity error on second phase of dual address
15811
        ok                  // result of operation
15812
    ) ;
15813
    if ( ok )
15814
        test_ok ;
15815
    else
15816
    begin
15817
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15818
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
15819
    end
15820
 
15821
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
15822
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
15823
    ipci_unsupported_commands_master.master_reference
15824
    (
15825
        Address,                // first part of address in dual address cycle
15826
        Address,                // second part of address in dual address cycle
15827
        `BC_RESERVED1,          // dual address cycle command
15828
        `BC_RESERVED1,      // normal command
15829
        4'h0,               // byte enables
15830
        32'h1234_5678,      // data
15831
        1'b0,               // make address parity error on first phase of dual address
15832
        1'b0,               // make address parity error on second phase of dual address
15833
        ok                  // result of operation
15834
    ) ;
15835
    if ( ok )
15836
        test_ok ;
15837
    else
15838
    begin
15839
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15840
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
15841
    end
15842
 
15843
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
15844
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
15845
    ipci_unsupported_commands_master.master_reference
15846
    (
15847
        Address,                // first part of address in dual address cycle
15848
        Address,                // second part of address in dual address cycle
15849
        `BC_RESERVED2,          // dual address cycle command
15850
        `BC_RESERVED2,      // normal command
15851
        4'h0,               // byte enables
15852
        32'h1234_5678,      // data
15853
        1'b0,               // make address parity error on first phase of dual address
15854
        1'b0,               // make address parity error on second phase of dual address
15855
        ok                  // result of operation
15856
    ) ;
15857
    if ( ok )
15858
        test_ok ;
15859
    else
15860
    begin
15861
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15862
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
15863
    end
15864
 
15865
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
15866
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
15867
    ipci_unsupported_commands_master.master_reference
15868
    (
15869
        Address,                // first part of address in dual address cycle
15870
        Address,                // second part of address in dual address cycle
15871
        `BC_RESERVED3,          // dual address cycle command
15872
        `BC_RESERVED3,      // normal command
15873
        4'h0,               // byte enables
15874
        32'h1234_5678,      // data
15875
        1'b0,               // make address parity error on first phase of dual address
15876
        1'b0,               // make address parity error on second phase of dual address
15877
        ok                  // result of operation
15878
    ) ;
15879
    if ( ok )
15880
        test_ok ;
15881
    else
15882
    begin
15883
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15884
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
15885
    end
15886
 
15887
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
15888
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
15889
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
15890
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
15891
    ipci_unsupported_commands_master.master_reference
15892
    (
15893
        Address,                // first part of address in dual address cycle
15894
        Address,                // second part of address in dual address cycle
15895
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
15896
        `BC_MEM_WRITE,      // normal command
15897
        4'h0,               // byte enables;
15898
        32'h1234_5678,      // data
15899
        1'b0,               // make address parity error on first phase of dual address
15900
        1'b0,               // make address parity error on second phase of dual address
15901
        ok                  // result of operation
15902
    ) ;
15903
    if ( ok )
15904
        test_ok ;
15905
    else
15906
    begin
15907
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15908
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
15909
    end
15910
 
15911
    irq_respond = 1 ;
15912
 
15913
end
15914
endtask // target_unsupported_cmds
15915
 
15916
task target_completion_expiration ;
15917
    reg   [11:0] pci_ctrl_offset ;
15918
    reg   [11:0] pci_ba_offset ;
15919
    reg   [11:0] pci_am_offset ;
15920
    reg   [11:0] pci_device_ctrl_offset ;
15921
    reg   [11:0] pci_err_cs_offset ;
15922
    reg   [11:0] icr_offset ;
15923
    reg   [11:0] isr_offset ;
15924
    reg   [11:0] lat_tim_cls_offset ;
15925
 
15926
    reg [31:0] temp_val1 ;
15927
    reg [31:0] temp_val2 ;
15928
    reg        ok   ;
15929 33 mihad
    reg        ok_wb ;
15930
    reg        ok_pci ;
15931 15 mihad
 
15932
    reg [31:0] pci_image_base ;
15933
    integer i ;
15934 33 mihad
    integer clocks_after_completion ;
15935
    reg     error_monitor_done ;
15936
    reg     test_mem ;
15937 15 mihad
 
15938
begin:main
15939
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15940
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
15941
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
15942
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15943
 
15944
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
15945
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
15946
    lat_tim_cls_offset = 12'hC ;
15947
    pci_device_ctrl_offset    = 12'h4 ;
15948
 
15949 33 mihad
    `ifdef HOST
15950
        test_mem = 1'b1 ;
15951
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
15952
    `else
15953
        test_mem = !`PCI_BA1_MEM_IO ;
15954
        pci_image_base = Target_Base_Addr_R[1] ;
15955
    `endif
15956 15 mihad
 
15957
    // enable master & target operation
15958
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
15959
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
15960
    if ( ok !== 1 )
15961
    begin
15962
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
15963
        test_fail("write to PCI Device Control register failed") ;
15964
        disable main ;
15965
    end
15966
 
15967
    // prepare image control register
15968 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
15969 15 mihad
    if ( ok !== 1 )
15970
    begin
15971
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
15972
        test_fail("write to PCI Image Control register failed") ;
15973
        disable main ;
15974
    end
15975
 
15976
    // prepare base address register
15977
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
15978
    if ( ok !== 1 )
15979
    begin
15980
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
15981
        test_fail("write to PCI Base Address register failed") ;
15982
        disable main ;
15983
    end
15984
 
15985
    // write address mask register
15986
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15987
    if ( ok !== 1 )
15988
    begin
15989
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
15990
        test_fail("write to PCI Address Mask register failed") ;
15991
        disable main ;
15992
    end
15993
 
15994
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
15995
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15996
    if ( ok !== 1 )
15997
    begin
15998
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
15999
        test_fail("write to PCI Error Control and Status register failed") ;
16000
        disable main ;
16001
    end
16002
 
16003 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
16004 15 mihad
    if ( ok !== 1 )
16005
    begin
16006
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
16007
        test_fail("write to Interrupt Control register failed") ;
16008
        disable main ;
16009
    end
16010
 
16011
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
16012
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
16013
    if ( ok !== 1 )
16014
    begin
16015
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
16016
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
16017
        disable main ;
16018
    end
16019
 
16020
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
16021
 
16022
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16023 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
16024
    master1_check_received_data = 0 ;
16025 15 mihad
 
16026 33 mihad
    ok_pci = 1 ;
16027
    // start a delayed read request
16028
    fork
16029
    begin
16030
        if ( test_mem )
16031
 
16032
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16033
                          pci_image_base, 32'h1234_5678,
16034
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
16035
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
16036
        else
16037
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
16038
 
16039
        do_pause( 1 ) ;
16040
    end
16041
    begin:error_monitor1
16042 35 mihad
        error_monitor_done = 0 ;
16043 33 mihad
        @(error_event_int) ;
16044
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16045
        ok_pci = 0 ;
16046 35 mihad
        error_monitor_done = 1 ;
16047 33 mihad
    end
16048
    begin
16049
        if ( test_mem )
16050
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
16051
        else
16052
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
16053 15 mihad
 
16054 33 mihad
        if ( ok_wb !== 1 )
16055
        begin
16056
            test_fail("Bridge failed to process Target Memory read correctly") ;
16057
            disable main ;
16058
        end
16059
 
16060 35 mihad
        #1 ;
16061
        if ( !error_monitor_done )
16062 33 mihad
            disable error_monitor1 ;
16063
    end
16064
    join
16065
 
16066
    clocks_after_completion = 0 ;
16067
    // now do another - different transaction
16068
    fork
16069
    begin
16070
        if ( test_mem )
16071
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16072
                          pci_image_base + 4, 32'h1234_5678,
16073
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
16074
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
16075
        else
16076
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
16077
 
16078
        while ( clocks_after_completion < 32'h0000_FFF0 )
16079
        begin
16080
            @(posedge pci_clock) ;
16081
            clocks_after_completion = clocks_after_completion + 1 ;
16082
        end
16083
 
16084
        do_pause('hFF) ;
16085
 
16086
        if ( test_mem )
16087
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16088
                          pci_image_base + 4, 32'h1234_5678,
16089
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
16090
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
16091
        else
16092
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
16093
 
16094
        do_pause( 1 ) ;
16095
    end
16096
    begin:error_monitor2
16097 35 mihad
        error_monitor_done = 0 ;
16098 33 mihad
        @(error_event_int) ;
16099
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16100
        ok_pci = 0 ;
16101 35 mihad
        error_monitor_done = 1 ;
16102 33 mihad
    end
16103
    begin
16104
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
16105
        repeat( 'hFF )
16106
            @(posedge pci_clock) ;
16107
 
16108
        if ( test_mem )
16109
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
16110
        else
16111
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
16112
 
16113
        if ( ok_wb !== 1 )
16114
        begin
16115
            test_fail("Bridge failed to process Target Memory read correctly") ;
16116
            disable main ;
16117
        end
16118
 
16119
        repeat(4)
16120
            @(posedge pci_clock) ;
16121
 
16122
        fork
16123
        begin
16124
            if ( test_mem )
16125
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16126
                              pci_image_base + 4, 32'h1234_5678,
16127
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
16128
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16129
            else
16130
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
16131
 
16132
            do_pause(1) ;
16133
        end
16134
        begin
16135
           pci_transaction_progress_monitor( pci_image_base + 4, test_mem ? `BC_MEM_READ : `BC_IO_READ, test_mem ? 4 : 1, 0, 1'b1, 1'b0, 0, ok ) ;
16136 35 mihad
           #1 ;
16137
           if ( !error_monitor_done )
16138 33 mihad
               disable error_monitor2 ;
16139
        end
16140
        join
16141
    end
16142
    join
16143
 
16144
    if ( ok && ok_pci && ok_wb )
16145
        test_ok ;
16146
 
16147
    if ( ok !== 1 )
16148
    begin
16149
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
16150
        test_fail("write to PCI Address Mask register failed") ;
16151
        disable main ;
16152
    end
16153
 
16154
    // check statuses after this situation - none should be set
16155
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
16156
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
16157
    if ( ok !== 1 )
16158
    begin
16159
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
16160
        test_fail("read from pci device status register failed") ;
16161
        disable main ;
16162
    end
16163
 
16164
    if ( temp_val1[31] )
16165
    begin
16166
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
16167
        test_fail("detected parity error bit was set for no reason") ;
16168
    end
16169
 
16170
    if ( temp_val1[30] )
16171
    begin
16172
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
16173
        test_fail("signaled system error bit was set for no reason") ;
16174
    end
16175
 
16176
    if ( temp_val1[29] )
16177
    begin
16178
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
16179
        test_fail("received master abort bit was set for no reason") ;
16180
    end
16181
 
16182
    if ( temp_val1[28] )
16183
    begin
16184
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
16185
        test_fail("received target abort bit was set for no reason") ;
16186
    end
16187
 
16188
    if ( temp_val1[27] )
16189
    begin
16190
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
16191
        test_fail("signaled target abort bit was set for no reason") ;
16192
    end
16193
 
16194
    if ( temp_val1[24] )
16195
    begin
16196
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
16197
        test_fail("Master Data parity error bit was set for no reason") ;
16198
    end
16199
 
16200
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
16201
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16202
    if ( temp_val1[8] !== 0 )
16203
    begin
16204
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
16205
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
16206
    end
16207
    // test target retry counter expiration
16208
    // set wb slave to retry response
16209
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
16210
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
16211
    ok_pci = 1 ;
16212
 
16213
    fork
16214
    begin
16215
        if ( test_mem == 1 )
16216
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
16217
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
16218
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
16219
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16220
        else
16221
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
16222
 
16223
        do_pause(1) ;
16224
 
16225
        // do another write with same address and different data
16226
        if ( test_mem == 1 )
16227
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
16228
                        pci_image_base, 32'h8765_4321, 4'h0,
16229
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
16230
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16231
        else
16232
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
16233
 
16234
        do_pause(1) ;
16235
    end
16236
    begin
16237
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
16238
        begin
16239
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
16240
            if ( ok_wb !== 1 )
16241
            begin
16242
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16243
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16244
                disable main ;
16245
            end
16246
        end
16247
 
16248
        // set WB slave to normal completion
16249
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16250
 
16251
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
16252
        if ( ok_wb !== 1 )
16253
        begin
16254
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16255
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16256
            disable main ;
16257
        end
16258
 
16259 35 mihad
        #1 ;
16260
        if ( !error_monitor_done )
16261 33 mihad
            disable error_monitor3 ;
16262
    end
16263
    begin:error_monitor3
16264 35 mihad
        error_monitor_done = 0 ;
16265 33 mihad
        @(error_event_int) ;
16266
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16267
        ok_pci = 0 ;
16268 35 mihad
        error_monitor_done = 1 ;
16269 33 mihad
    end
16270
    join
16271
 
16272
    if ( ok_wb && ok_pci )
16273
    begin
16274
        test_ok ;
16275
    end
16276
 
16277
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
16278
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16279
    if ( temp_val1[8] !== 1'b1 )
16280
    begin
16281
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
16282
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
16283
    end
16284
 
16285
    if ( temp_val1[9] !== 1 )
16286
    begin
16287
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Error Source bit when retry counter expires during a write! Time %t", $time) ;
16288
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
16289
    end
16290
 
16291
    if ( temp_val1[10] !== 1 )
16292
    begin
16293
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Retry Expired bit when retry counter expires during a write! Time %t", $time) ;
16294
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
16295
    end
16296
 
16297
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
16298
    begin
16299
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in bus command field in error control and status register when retry counter expired during a write! Time %t", $time) ;
16300
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
16301
    end
16302
 
16303
    if ( temp_val1[31:28] !== 4'hA )
16304
    begin
16305
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in byte enable field in error control and status register when retry counter expired during a write! Time %t", $time) ;
16306
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
16307
    end
16308
 
16309
    // clear error status register
16310
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
16311
 
16312
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
16313
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
16314
    if ( temp_val1 !== pci_image_base )
16315
    begin
16316
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
16317
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
16318
    end
16319
 
16320
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
16321
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
16322
    if ( temp_val1 !== 32'hDEAD_BEAF )
16323
    begin
16324
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
16325
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
16326
    end
16327
 
16328
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
16329
    ok_pci = 1 ;
16330
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
16331
 
16332
    i = 0 ;
16333
    fork
16334
    begin
16335
        if ( test_mem )
16336
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16337
                          pci_image_base + 4, 32'h1234_5678,
16338
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
16339
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
16340
        else
16341
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
16342
 
16343
        do_pause( 1 ) ;
16344
 
16345
    end
16346
    begin
16347
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
16348
        begin
16349
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
16350
            if ( ok_wb !== 1 )
16351
            begin
16352
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16353
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16354
                disable main ;
16355
            end
16356
        end
16357
 
16358
        // set WB slave to normal completion
16359
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16360
 
16361
        fork
16362
        begin
16363
            repeat(4)
16364
                @(posedge pci_clock) ;
16365
 
16366
            if ( test_mem )
16367
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16368
                              pci_image_base, 32'h8765_4321,
16369
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
16370
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
16371
            else
16372
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
16373
 
16374
            do_pause(1) ;
16375
        end
16376
        begin
16377
 
16378
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
16379
            if ( ok_wb !== 1 )
16380
            begin
16381
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16382
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16383
                disable main ;
16384
            end
16385
        end
16386
        join
16387
 
16388
        repeat( 4 )
16389
            @(posedge pci_clock) ;
16390
 
16391
        if ( test_mem )
16392
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16393
                          pci_image_base, 32'h8765_4321,
16394
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
16395
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16396
        else
16397
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
16398
 
16399
        do_pause(1) ;
16400
 
16401 35 mihad
        #1 ;
16402
        if ( !error_monitor_done )
16403 33 mihad
            disable error_monitor4 ;
16404
    end
16405
    begin:error_monitor4
16406 35 mihad
        error_monitor_done = 0 ;
16407 33 mihad
        @(error_event_int) ;
16408
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16409
        ok_pci = 0 ;
16410 35 mihad
        error_monitor_done = 1 ;
16411 33 mihad
    end
16412
    join
16413
 
16414
    if ( ok_wb && ok_pci )
16415
        test_ok ;
16416
 
16417
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
16418
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16419
    if ( temp_val1[8] !== 1'b0 )
16420
    begin
16421
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master shouldn't signal an error when retry counter expires during a read! Time %t", $time) ;
16422
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
16423
    end
16424
 
16425
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
16426
    ok_pci = 1 ;
16427
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
16428
 
16429
    fork
16430
    begin
16431
        if ( test_mem )
16432
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16433
                          pci_image_base + 4, 32'h1234_5678,
16434
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
16435
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
16436
        else
16437
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
16438
 
16439
        do_pause( 1 ) ;
16440
 
16441
    end
16442
    begin
16443
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
16444
        if ( ok_wb !== 1 )
16445
        begin
16446
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16447
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16448
            disable main ;
16449
        end
16450
 
16451
        repeat(4)
16452
            @(posedge pci_clock) ;
16453
 
16454
        fork
16455
        begin
16456
 
16457
            if ( test_mem )
16458
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16459
                              pci_image_base + 4, 32'h8765_4321,
16460
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
16461
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
16462
            else
16463
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
16464
 
16465
            do_pause(1) ;
16466
 
16467
        end
16468
        begin
16469
 
16470
            pci_transaction_progress_monitor( pci_image_base + 4, test_mem ? `BC_MEM_READ : `BC_IO_READ, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
16471
            if ( ok !== 1 )
16472
            begin
16473
                $display("WISHBONE Master Retry Counter expiration test failed! PCI transaction progress monitor detected invalid transaction or none at all on PCI bus! Time %t", $time) ;
16474
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
16475
                disable main ;
16476
            end
16477
        end
16478
        join
16479
 
16480 35 mihad
        #1 ;
16481
        if ( !error_monitor_done )
16482 33 mihad
            disable error_monitor5 ;
16483
    end
16484
    begin:error_monitor5
16485 35 mihad
        error_monitor_done = 0 ;
16486 33 mihad
        @(error_event_int) ;
16487
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16488
        ok_pci = 0 ;
16489 35 mihad
        error_monitor_done = 1 ;
16490 33 mihad
    end
16491
    join
16492
 
16493
    if ( ok_wb && ok_pci )
16494
        test_ok ;
16495
 
16496
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
16497
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16498
    if ( temp_val1[8] !== 1'b0 )
16499
    begin
16500
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master shouldn't signal an error when retry counter expires during a read! Time %t", $time) ;
16501
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
16502
    end
16503
 
16504
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
16505
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
16506
    if ( temp_val1[25] !== 1'b1 )
16507
    begin
16508
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
16509
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
16510
    end
16511
 
16512
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
16513
 
16514
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
16515
    ok_pci = 1 ;
16516
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
16517
 
16518
    fork
16519
    begin
16520
        if ( test_mem == 1 )
16521
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
16522
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
16523
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
16524
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16525
        else
16526
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
16527
 
16528
        do_pause(1) ;
16529
 
16530
        // do another write with same address and different data
16531
        if ( test_mem == 1 )
16532
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
16533
                        pci_image_base, 32'h8765_6789, 4'h0,
16534
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
16535
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16536
        else
16537
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
16538
 
16539
        do_pause(1) ;
16540
 
16541
        $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
16542
        $fdisplay(pciu_mon_log_file_desc,
16543
        "********************************************  Monitor will complain in following section for a few times - testbench is intentionally causing no response  *********************************************") ;
16544
    end
16545
    begin
16546
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
16547
        if ( ok_wb !== 1 )
16548
        begin
16549
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16550
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16551
            disable main ;
16552
        end
16553
 
16554
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
16555
 
16556
        if ( test_mem )
16557
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
16558
        else
16559
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
16560
 
16561
        if ( ok_wb !== 1 )
16562
        begin
16563
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16564
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16565
            disable main ;
16566
        end
16567
 
16568 35 mihad
        #1 ;
16569
        if ( !error_monitor_done )
16570 33 mihad
            disable error_monitor6 ;
16571
    end
16572
    begin:error_monitor6
16573 35 mihad
        error_monitor_done = 0 ;
16574 33 mihad
        @(error_event_int) ;
16575
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16576
        ok_pci = 0 ;
16577 35 mihad
        error_monitor_done = 1 ;
16578 33 mihad
    end
16579
    join
16580
 
16581
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
16582
    $fdisplay(pciu_mon_log_file_desc,
16583
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
16584
 
16585
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
16586
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16587
    if ( temp_val1[8] !== 1'b1 )
16588
    begin
16589
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when no response counter expires during a write! Time %t", $time) ;
16590
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
16591
    end
16592
 
16593
    if ( temp_val1[9] !== 0 )
16594
    begin
16595
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should not set Error Source bit when no response counter expires during a write! Time %t", $time) ;
16596
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
16597
    end
16598
 
16599
    if ( temp_val1[10] !== 1 )
16600
    begin
16601
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Retry Expired bit when no response counter expires during a write! Time %t", $time) ;
16602
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
16603
    end
16604
 
16605
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
16606
    begin
16607
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in bus command field in error control and status register when no response counter expired during a write! Time %t", $time) ;
16608
        test_fail("bus command field in error control and status register was wrong when no response counter expired during posted write through PCI Target unit") ;
16609
    end
16610
 
16611
    if ( temp_val1[31:28] !== 4'h0 )
16612
    begin
16613
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in byte enable field in error control and status register when no response counter expired during a write! Time %t", $time) ;
16614
        test_fail("byte enable field in error control and status register was wrong when no response counter expired during posted write through PCI Target unit") ;
16615
    end
16616
 
16617
    // clear error status register
16618
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
16619
 
16620
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
16621
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
16622
    if ( temp_val1 !== pci_image_base )
16623
    begin
16624
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when no response counter expired during a write! Time %t", $time) ;
16625
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
16626
    end
16627
 
16628
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
16629
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
16630
    if ( temp_val1 !== 32'hBEAF_DEAD )
16631
    begin
16632
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when no response counter expired during a write! Time %t", $time) ;
16633
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
16634
    end
16635
 
16636
    // disable current image - write address mask register
16637
    config_write( pci_am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
16638 15 mihad
end
16639
endtask // target_completion_expired
16640
 
16641
task config_write ;
16642
    input [11:0] offset ;
16643
    input [31:0] data ;
16644
    input [3:0]  byte_enable ;
16645
    output       ok ;
16646
    `ifdef HOST
16647
    reg   `WRITE_STIM_TYPE   write_data ;
16648
    reg   `WB_TRANSFER_FLAGS write_flags ;
16649
    reg   `WRITE_RETURN_TYPE write_status ;
16650
    `else
16651
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
16652
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
16653
    `endif
16654
    reg in_use ;
16655
    reg [31:0] temp_var ;
16656
begin
16657
    if ( in_use === 1 )
16658
    begin
16659
        $display("config_read task re-entered! Time %t ", $time) ;
16660
        ok = 0 ;
16661
        #20 $stop ;
16662
    end
16663
    else
16664
    begin
16665
        ok = 1 ;
16666
        in_use = 1 ;
16667
    end
16668
    `ifdef HOST
16669
    write_flags                    = 0 ;
16670
    write_flags`INIT_WAITS         = tb_init_waits ;
16671
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
16672
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
16673
 
16674
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
16675
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
16676
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
16677
    write_data`WRITE_SEL                         = byte_enable ;
16678
    write_data`WRITE_TAG_STIM                    = 0 ;
16679
    write_data`WRITE_DATA                        = data ;
16680
 
16681
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
16682
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
16683
    begin
16684
        $display("Write to configuration space failed! Time %t ", $time) ;
16685
        ok = 0 ;
16686
    end
16687
 
16688
    @(posedge wb_clock) ;
16689
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
16690
    // here we just wait for two guest cycles for conf space bits to synchronize
16691
    repeat( 2 )
16692
        @(posedge pci_clock) ;
16693
 
16694
    `else // GUEST
16695
    byte_enables_l = ~byte_enable ;
16696
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
16697
 
16698
    fork
16699
    begin
16700
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16701
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16702
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
16703
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16704
              8'h0_0, `Test_One_Zero_Target_WS,
16705
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
16706
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16707
    do_pause( 1 ) ;
16708
    end
16709
    begin
16710
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
16711
        @(posedge pci_clock) ;
16712
    end
16713
    join
16714
 
16715
     repeat( 2 )
16716
         @(posedge wb_clock) ;
16717
 
16718
    `endif
16719
    in_use = 0 ;
16720
end
16721
endtask // config_write
16722
 
16723
task config_read ;
16724
    input [11:0] offset ;
16725
    input [3:0]  byte_enable ;
16726
    output [31:0] data ;
16727
 
16728
    reg `READ_STIM_TYPE    read_data ;
16729
    reg `WB_TRANSFER_FLAGS read_flags ;
16730
    reg `READ_RETURN_TYPE  read_status ;
16731
 
16732
    reg [31:0] pci_address ;
16733
    reg [3:0] byte_enables_l ;
16734
 
16735
    reg master_check_data_prev ;
16736
    reg in_use ;
16737
    reg [31:0] temp_var ;
16738
begin:main
16739
    if ( in_use === 1 )
16740
    begin
16741
        $display("config_read task re-entered! Time %t ", $time) ;
16742
        data = 32'hxxxx_xxxx ;
16743
        disable main ;
16744
    end
16745
 
16746
    in_use = 1 ;
16747
 
16748
`ifdef HOST
16749 26 mihad
    repeat(4)
16750
        @(posedge pci_clock) ;
16751
    repeat(4)
16752
        @(posedge wb_clock) ;
16753 15 mihad
    read_flags                    = 0 ;
16754
    read_flags`INIT_WAITS         = tb_init_waits ;
16755
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
16756
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
16757
 
16758
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
16759
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
16760
 
16761
    read_data`READ_ADDRESS  = temp_var + offset ;
16762
    read_data`READ_SEL      = byte_enable ;
16763
    read_data`READ_TAG_STIM = 0 ;
16764
 
16765
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
16766
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
16767
    begin
16768
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
16769
        #20 $stop ;
16770
    end
16771
    data = read_status`READ_DATA ;
16772
`else
16773
  `ifdef GUEST
16774 26 mihad
    repeat(4)
16775
        @(posedge wb_clock) ;
16776
    repeat(4)
16777
        @(posedge pci_clock) ;
16778 15 mihad
    master_check_data_prev = master2_check_received_data ;
16779
    master2_check_received_data = 0 ;
16780
 
16781
    byte_enables_l = ~byte_enable ;
16782
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
16783
 
16784
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16785
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16786
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
16787
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16788
             8'h4_0, `Test_One_Zero_Target_WS,
16789
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
16790
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16791
    do_pause( 1 ) ;
16792
 
16793
    @(master2_received_data_valid) ;
16794
    data = master2_received_data ;
16795
 
16796
    master2_check_received_data = master_check_data_prev ;
16797
  `endif
16798
`endif
16799
    in_use = 0 ;
16800
end
16801
endtask //config_read
16802
 
16803
task test_fail ;
16804
    input [7999:0] failure_reason ;
16805
    reg   [8007:0] display_failure ;
16806
    reg   [799:0] display_test ;
16807
begin
16808
    tests_failed = tests_failed + 1 ;
16809
 
16810
    display_failure = {failure_reason, "!"} ;
16811
    while ( display_failure[7999:7992] == 0 )
16812
        display_failure = display_failure << 8 ;
16813
 
16814
    display_test = test_name ;
16815
    while ( display_test[799:792] == 0 )
16816
       display_test = display_test << 8 ;
16817
 
16818
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16819
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
16820
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
16821
    $fdisplay( tb_log_file, " *FAILED* because") ;
16822
    $fdisplay( tb_log_file, " %s", display_failure ) ;
16823
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16824
    $fdisplay( tb_log_file, " " ) ;
16825
 
16826
    `ifdef STOP_ON_FAILURE
16827
    #20 $stop ;
16828
    `endif
16829
end
16830
endtask // test_fail
16831
 
16832
task test_ok ;
16833
    reg [799:0] display_test ;
16834
begin
16835
   tests_successfull = tests_successfull + 1 ;
16836
 
16837
   display_test = test_name ;
16838
   while ( display_test[799:792] == 0 )
16839
       display_test = display_test << 8 ;
16840
 
16841
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16842
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
16843
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
16844
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
16845
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16846
   $fdisplay( tb_log_file, " " ) ;
16847
end
16848
endtask // test_ok
16849
 
16850
task test_summary;
16851
begin
16852
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
16853
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
16854
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
16855
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
16856
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
16857
    $fclose(tb_log_file) ;
16858
end
16859
endtask
16860
 
16861
endmodule

powered by: WebSVN 2.1.0

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