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

Subversion Repositories pci

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

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

Line No. Rev Author Line
1 15 mihad
`include "pci_constants.v"
2
`include "bus_commands.v"
3
`include "pci_testbench_defines.v"
4
`include "timescale.v"
5
 
6
module SYSTEM ;
7
 
8
`include "pci_blue_constants.vh"
9
`include "pci_blue_options.vh"
10
 
11
integer tests_successfull ;
12
integer tests_failed ;
13
integer tb_log_file ;
14
reg [799:0] test_name ;
15
 
16
reg pci_clock ;
17
reg wb_clock ;
18
reg reset ;
19
 
20
wire [4:0] arb_grant_out ;
21
 
22
wire [31:0] AD ;
23
wire [3:0]  CBE ;
24
pullup(INTA) ;
25
pullup(MAS0_REQ) ;
26
pullup(MAS1_REQ) ;
27
pullup(MAS2_REQ) ;
28
pullup(MAS3_REQ) ;
29
 
30
wire MAS0_GNT = ~arb_grant_out[0];
31
wire MAS1_GNT = ~arb_grant_out[1] ;
32
wire MAS2_GNT = ~arb_grant_out[2] ;
33
wire MAS3_GNT = ~arb_grant_out[3] ;
34
 
35
pullup(FRAME) ;
36
pullup(IRDY) ;
37
wire        TAR0_IDSEL = AD[11] ;
38
`define     TAR0_IDSEL_INDEX    11
39
`define     TAR0_IDSEL_ADDR     32'h0000_0800
40
pullup(DEVSEL) ;
41
pullup(TRDY) ;
42
pullup(STOP) ;
43
wire   PAR ;
44
pullup(PERR) ;
45
pullup(SERR) ;
46
wire [3:0] MAS1_IDSEL ;
47
 
48
pullup lockpu ( LOCK ) ;
49
 
50
wire        RST_O ;
51
wire        INT_O ;
52
reg         INT_I ;
53
wire [31:0] ADR_I ;
54
wire [31:0] SDAT_I ;
55
wire [31:0] SDAT_O ;
56
wire [3:0]  SEL_I ;
57
wire        CYC_I ;
58
wire        STB_I ;
59
wire        WE_I ;
60
wire        CAB_I ;
61
wire        ACK_O ;
62
wire        RTY_O ;
63
wire        ERR_O ;
64
 
65
wire [31:0] ADR_O ;
66
wire [31:0] MDAT_I ;
67
wire [31:0] MDAT_O ;
68
wire [3:0]  SEL_O ;
69
wire        CYC_O ;
70
wire        STB_O ;
71
wire        WE_O ;
72
wire        CAB_O ;
73
wire        ACK_I ;
74
wire        RTY_I ;
75
wire        ERR_I ;
76
wire        TAR1_IDSEL = AD[12] ;
77
`define     TAR1_IDSEL_INDEX    12
78
`define     TAR1_IDSEL_ADDR     32'h0000_1000
79
wire        TAR2_IDSEL = AD[13] ;
80
`define     TAR2_IDSEL_INDEX    13
81
`define     TAR2_IDSEL_ADDR     32'h0000_2000
82
 
83
wire        reset_wb ; // reset to Wb devices
84
 
85
`ifdef GUEST
86
    wire    RST = ~reset ;
87
    assign  reset_wb = RST_O ;
88
`else
89
    pullup(RST) ;
90
    assign  reset_wb = reset ;
91
`endif
92
 
93
`define PCI_BRIDGE_INSTANCE bridge32_top
94
 
95
TOP `PCI_BRIDGE_INSTANCE
96
(
97
    .CLK    ( pci_clock),
98
    .AD     ( AD ),
99
    .CBE    ( CBE ),
100
    .RST    ( RST ),
101
    .INTA   ( INTA ),
102
    .REQ    ( MAS0_REQ ),
103
    .GNT    ( MAS0_GNT ),
104
    .FRAME  ( FRAME ),
105
    .IRDY   ( IRDY ),
106
    .IDSEL  ( TAR0_IDSEL),
107
    .DEVSEL ( DEVSEL ),
108
    .TRDY   ( TRDY ),
109
    .STOP   ( STOP ),
110
    .PAR    ( PAR ),
111
    .PERR   ( PERR ),
112
    .SERR   ( SERR ),
113
 
114
    .CLK_I  ( wb_clock ),
115
    .RST_I  ( reset ),
116
    .RST_O  ( RST_O ),
117
    .INT_I  ( INT_I ),
118
    .INT_O  ( INT_O ),
119
 
120
    // WISHBONE slave interface
121
    .ADR_I  ( ADR_I ),
122
    .SDAT_I ( SDAT_I ),
123
    .SDAT_O ( SDAT_O ),
124
    .SEL_I  ( SEL_I ),
125
    .CYC_I  ( CYC_I ),
126
    .STB_I  ( STB_I ),
127
    .WE_I   ( WE_I ),
128
    .CAB_I  ( CAB_I),
129
    .ACK_O  ( ACK_O ),
130
    .RTY_O  ( RTY_O ),
131
    .ERR_O  ( ERR_O ),
132
 
133
    // WISHBONE master interface
134
    .ADR_O  ( ADR_O ),
135
    .MDAT_I ( MDAT_I ),
136
    .MDAT_O ( MDAT_O ),
137
    .SEL_O  ( SEL_O ),
138
    .CYC_O  ( CYC_O ),
139
    .STB_O  ( STB_O ),
140
    .WE_O   ( WE_O ),
141
    .CAB_O  ( CAB_O ),
142
    .ACK_I  ( ACK_I ),
143
    .RTY_I  ( RTY_I ),
144
    .ERR_I  ( ERR_I )
145
) ;
146
 
147
WB_MASTER_BEHAVIORAL wishbone_master
148
(
149
    .CLK_I(wb_clock),
150
    .RST_I(reset_wb),
151
    .TAG_I(4'b0000),
152
    .TAG_O(),
153
    .ACK_I(ACK_O),
154
    .ADR_O(ADR_I),
155
    .CYC_O(CYC_I),
156
    .DAT_I(SDAT_O),
157
    .DAT_O(SDAT_I),
158
    .ERR_I(ERR_O),
159
    .RTY_I(RTY_O),
160
    .SEL_O(SEL_I),
161
    .STB_O(STB_I),
162
    .WE_O (WE_I),
163
    .CAB_O(CAB_I)
164
);
165
 
166
WB_SLAVE_BEHAVIORAL wishbone_slave
167
(
168
    .CLK_I              (wb_clock),
169
    .RST_I              (reset_wb),
170
    .ACK_O              (ACK_I),
171
    .ADR_I              (ADR_O),
172
    .CYC_I              (CYC_O),
173
    .DAT_O              (MDAT_I),
174
    .DAT_I              (MDAT_O),
175
    .ERR_O              (ERR_I),
176
    .RTY_O              (RTY_I),
177
    .SEL_I              (SEL_O),
178
    .STB_I              (STB_O),
179
    .WE_I               (WE_O),
180
    .CAB_I              (CAB_O)
181
);
182
 
183
integer wbu_mon_log_file_desc ;
184
integer pciu_mon_log_file_desc ;
185
WB_BUS_MON wbu_wb_mon(
186
                    .CLK_I(wb_clock),
187
                    .RST_I(reset_wb),
188
                    .ACK_I(ACK_O),
189
                    .ADDR_O(ADR_I),
190
                    .CYC_O(CYC_I),
191
                    .DAT_I(SDAT_O),
192
                    .DAT_O(SDAT_I),
193
                    .ERR_I(ERR_O),
194
                    .RTY_I(RTY_O),
195
                    .SEL_O(SEL_I),
196
                    .STB_O(STB_I),
197
                    .WE_O (WE_I),
198
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
199
                    .TAG_O(),
200
                    .CAB_O(CAB_I),
201
                    .log_file_desc ( wbu_mon_log_file_desc )
202
                  ) ;
203
 
204
WB_BUS_MON pciu_wb_mon(
205
                    .CLK_I(wb_clock),
206
                    .RST_I(reset_wb),
207
                    .ACK_I(ACK_I),
208
                    .ADDR_O(ADR_O),
209
                    .CYC_O(CYC_O),
210
                    .DAT_I(MDAT_I),
211
                    .DAT_O(MDAT_O),
212
                    .ERR_I(ERR_I),
213
                    .RTY_I(RTY_I),
214
                    .SEL_O(SEL_O),
215
                    .STB_O(STB_O),
216
                    .WE_O (WE_O),
217
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
218
                    .TAG_O(),
219
                    .CAB_O(CAB_O),
220
                    .log_file_desc( pciu_mon_log_file_desc )
221
                  ) ;
222
 
223
reg irq_respond ;
224
reg [31:0] irq_vector ;
225
PCI_BEHAVIORAL_IACK_TARGET interrupt_control
226
(
227
    .CLK              ( pci_clock),
228
    .AD               ( AD ),
229
    .CBE              ( CBE ),
230
    .RST              ( RST ),
231
    .FRAME            ( FRAME ),
232
    .IRDY             ( IRDY ),
233
    .DEVSEL           ( DEVSEL ),
234
    .TRDY             ( TRDY ),
235
    .STOP             ( STOP ),
236
    .PAR              ( PAR ),
237
    .respond          ( irq_respond ),
238
    .interrupt_vector ( irq_vector)
239
);
240
 
241
// some aditional signals are needed here because of the arbiter
242
reg [3:0] pci_ext_req_prev ;
243
always@(posedge pci_clock)
244
begin
245
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
246
end
247
reg pci_frame_prev ;
248
always@(posedge pci_clock)
249
begin
250
    pci_frame_prev <= FRAME ;
251
end
252
reg pci_irdy_prev ;
253
always@(posedge pci_clock)
254
begin
255
    pci_irdy_prev <= IRDY ;
256
end
257
 
258
pci_blue_arbiter pci_arbiter
259
(
260
  .pci_int_req_direct(1'b0),
261
  .pci_ext_req_prev(pci_ext_req_prev),
262
  .pci_int_gnt_direct_out(arb_grant_out[4]),
263
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
264
  .pci_frame_prev(~pci_frame_prev),
265
  .pci_irdy_prev(~pci_irdy_prev),
266
  .pci_irdy_now(~IRDY),
267
  .arbitration_enable(1'b1),
268
  .pci_clk(pci_clock),
269
  .pci_reset_comb(~RST)
270
);
271
 
272
reg [31:0] target_message ;
273
 
274
// define output enable signals for monitor inputs
275
// real output enable signals
276
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
277
`ifdef ACTIVE_LOW_OE
278
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
279
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
280
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
281
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
282
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
283
                        !devsel_t_s_oe,
284
                        !ad_oe,
285
                        !cbe_oe,
286
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
287
                        ;
288
`else
289
`ifdef ACTIVE_HIGH_OE
290
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
291
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
292
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
293
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
294
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
295
                        devsel_t_s_oe,
296
                        ad_oe,
297
                        cbe_oe,
298
                        `PCI_BRIDGE_INSTANCE.PERR_en}
299
                        ;
300
`endif
301
`endif
302
/*wire [5:0] oe_sigs_0 = {1'b0,
303
                        1'b0,
304
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
305
                        pci_target32.ad_enable,
306
                        1'b0,
307
                        pci_target32.err_enable | pci_target32.r_err_enable
308
                       } ;
309
*/
310
 
311
wire [5:0] oe_sigs_2 ;
312
wire [5:0] oe_sigs_1 ;
313
 
314
// signals which are used by test modules to know what to do
315
triand  test_accepted_l_int, error_event_int;
316
pullup  (test_accepted_l_int), (error_event_int);
317
 
318
wire    pci_reset_comb  = ~RST;
319
wire    pci_ext_clk     = pci_clock;
320
 
321
integer pci_mon_log_file_desc ;
322
pci_bus_monitor monitor32
323
(
324
    .pci_ext_ad                 (AD),
325
    .pci_ext_cbe_l              (CBE),
326
    .pci_ext_par                (PAR),
327
    .pci_ext_frame_l            (FRAME),
328
    .pci_ext_irdy_l             (IRDY),
329
    .pci_ext_devsel_l           (DEVSEL),
330
    .pci_ext_trdy_l             (TRDY),
331
    .pci_ext_stop_l             (STOP),
332
    .pci_ext_perr_l             (PERR),
333
    .pci_ext_serr_l             (SERR),
334
    .pci_real_req_l             (MAS0_REQ),
335
    .pci_real_gnt_l             (MAS0_GNT),
336
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
337
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
338
    .test_error_event           (error_event_int),
339
    .test_observe_r_oe_sigs     (r_oe_sigs),
340
    .test_observe_0_oe_sigs     (6'h00),
341
    .test_observe_1_oe_sigs     (oe_sigs_1),
342
    .test_observe_2_oe_sigs     (oe_sigs_2),
343
    .test_observe_3_oe_sigs     (6'h00),
344
    .pci_ext_reset_l            (RST),
345
    .pci_ext_clk                (pci_clock),
346
    .log_file_desc              (pci_mon_log_file_desc)
347
) ;
348
 
349
reg [2:0]  test_master_number ;
350
reg [31:0] test_address ;
351
reg [3:0]  test_command ;
352
reg [31:0] test_data ;
353
reg [3:0]  test_byte_enables_l ;
354
reg [9:0]  test_size ;
355
reg        test_make_addr_par_error ;
356
reg        test_make_data_par_error ;
357
reg [3:0]  test_master_initial_wait_states ;
358
reg [3:0]  test_master_subsequent_wait_states ;
359
reg [3:0]  test_target_initial_wait_states ;
360
reg [3:0]  test_target_subsequent_wait_states ;
361
reg [1:0]  test_target_devsel_speed ;
362
reg        test_fast_back_to_back ;
363
reg [2:0]  test_target_termination ;
364
reg        test_expect_master_abort ;
365
reg        test_start ;
366
reg [25:0] test_target_response ;
367
 
368
wire [31:0] master2_received_data ;
369
wire        master2_received_data_valid ;
370
reg         master2_check_received_data ;
371
pci_behaviorial_device pci_behaviorial_device2
372
(
373
    .pci_ext_ad(AD),
374
    .pci_ext_cbe_l(CBE),
375
    .pci_ext_par(PAR),
376
    .pci_ext_frame_l(FRAME),
377
    .pci_ext_irdy_l(IRDY),
378
    .pci_ext_devsel_l(DEVSEL),
379
    .pci_ext_trdy_l(TRDY),
380
    .pci_ext_stop_l(STOP),
381
    .pci_ext_perr_l(PERR),
382
    .pci_ext_serr_l(SERR),
383
    .pci_ext_idsel(TAR2_IDSEL),
384
    .pci_ext_inta_l(INTA),
385
    .pci_ext_req_l(MAS2_REQ),
386
    .pci_ext_gnt_l(MAS2_GNT),
387
    .pci_ext_reset_l(RST),
388
    .pci_ext_clk(pci_clock),
389
 
390
// Signals used by the test bench instead of using "." notation
391
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
392
    .test_master_number                 (test_master_number[2:0]),
393
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
394
    .test_command                       (test_command[3:0]),
395
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
396
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
397
    .test_size                          (test_size),
398
    .test_make_addr_par_error           (test_make_addr_par_error),
399
    .test_make_data_par_error           (test_make_data_par_error),
400
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
401
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
402
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
403
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
404
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
405
    .test_fast_back_to_back             (test_fast_back_to_back),
406
    .test_target_termination            (test_target_termination[2:0]),
407
    .test_expect_master_abort           (test_expect_master_abort),
408
    .test_start                         (test_start),
409
    .test_accepted_l                    (test_accepted_l_int),
410
    .test_error_event                   (error_event_int),
411
    .test_device_id                     (`Test_Master_2),
412
    .test_target_response               (test_target_response),
413
 
414
    .master_received_data               (master2_received_data),
415
    .master_received_data_valid         (master2_received_data_valid),
416
    .master_check_received_data         (master2_check_received_data)
417
);
418
 
419
wire [31:0] master1_received_data ;
420
wire        master1_received_data_valid ;
421
reg         master1_check_received_data ;
422
pci_behaviorial_device pci_behaviorial_device1
423
(
424
    .pci_ext_ad(AD),
425
    .pci_ext_cbe_l(CBE),
426
    .pci_ext_par(PAR),
427
    .pci_ext_frame_l(FRAME),
428
    .pci_ext_irdy_l(IRDY),
429
    .pci_ext_devsel_l(DEVSEL),
430
    .pci_ext_trdy_l(TRDY),
431
    .pci_ext_stop_l(STOP),
432
    .pci_ext_perr_l(PERR),
433
    .pci_ext_serr_l(SERR),
434
    .pci_ext_idsel(TAR1_IDSEL),
435
    .pci_ext_inta_l(INTA),
436
    .pci_ext_req_l(MAS1_REQ),
437
    .pci_ext_gnt_l(MAS1_GNT),
438
    .pci_ext_reset_l(RST),
439
    .pci_ext_clk(pci_clock),
440
 
441
// Signals used by the test bench instead of using "." notation
442
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
443
    .test_master_number                 (test_master_number[2:0]),
444
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
445
    .test_command                       (test_command[3:0]),
446
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
447
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
448
    .test_size                          (test_size),
449
    .test_make_addr_par_error           (test_make_addr_par_error),
450
    .test_make_data_par_error           (test_make_data_par_error),
451
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
452
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
453
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
454
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
455
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
456
    .test_fast_back_to_back             (test_fast_back_to_back),
457
    .test_target_termination            (test_target_termination[2:0]),
458
    .test_expect_master_abort           (test_expect_master_abort),
459
    .test_start                         (test_start),
460
    .test_accepted_l                    (test_accepted_l_int),
461
    .test_error_event                   (error_event_int),
462
    .test_device_id                     (`Test_Master_1),
463
    .test_target_response               (test_target_response),
464
 
465
    .master_received_data               (master1_received_data),
466
    .master_received_data_valid         (master1_received_data_valid),
467
    .master_check_received_data         (master1_check_received_data)
468
);
469
 
470
pci_unsupported_commands_master ipci_unsupported_commands_master
471
(
472
    .CLK    ( pci_clock),
473
    .AD     ( AD ),
474
    .CBE    ( CBE ),
475
    .RST    ( RST ),
476
    .REQ    ( MAS3_REQ ),
477
    .GNT    ( MAS3_GNT ),
478
    .FRAME  ( FRAME ),
479
    .IRDY   ( IRDY ),
480
    .DEVSEL ( DEVSEL ),
481
    .TRDY   ( TRDY ),
482
    .STOP   ( STOP ),
483
    .PAR    ( PAR )
484
) ;
485
 
486
// pci clock generator
487
always
488
`ifdef PCI33
489
    #15 pci_clock = ~pci_clock ;
490
`else
491
`ifdef PCI66
492
    #7.5 pci_clock = ~pci_clock ;
493
`endif
494
`endif
495
 
496
// WISHBONE clock generation
497
always
498
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
499
 
500
// Make test name visible when the Master starts working on it
501
reg     [79:0] present_test_name;
502
reg     [79:0] next_test_name;
503
wire    test_accepted = ~test_accepted_l_int;
504
always @(posedge test_accepted)
505
begin
506
    present_test_name <= next_test_name;
507
end
508
 
509
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
510
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
511
 
512
// basic configuration parameters for both behavioral devices
513
parameter [2:0] Master_ID_A                           = `Test_Master_1;
514
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
515
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
516
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
517
 
518
parameter [2:0] Master_ID_B                           = `Test_Master_2;
519
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
520
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
521
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
522
 
523
// basic configuration parameters for REAL device
524
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
525
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
526
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
527
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
528
 
529
// reg  [2:0]   ack_err_rty_termination ;
530
// reg          wait_cycles ;
531
// reg  [7:0]   num_of_retries ;
532
 
533
//reg [19:0] pci_config_base ;
534
reg [7:0] system_burst_size ;
535
reg [7:0] bridge_latency ;
536
integer   target_mem_image ;
537
integer   target_io_image ;
538
 
539
initial
540
begin
541
    next_test_name[79:0] <= "Nowhere___";
542
    reset = 1'b1 ;
543
    pci_clock = 1'b0 ;
544
    wb_clock  = 1'b1 ;
545
    target_message = 32'h0000_0000 ;
546
//  num_of_retries = 8'h01 ;
547
//  ack_err_rty_termination = 3'b100 ;
548
//  wait_cycles = 1'b0 ;
549
 
550
    // system paameters
551
    system_burst_size = 16 ;
552
    bridge_latency    = 8 ;
553
 
554
    // set initial values for controling the behavioral PCI master
555
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
556
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
557
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
558
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
559
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
560
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
561
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
562
 
563
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
564
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
565
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
566
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
567
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
568
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
569
 
570
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
571
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
572
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
573
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
574
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
575
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
576
 
577
    test_master_number = `Test_Master_2 ;
578
    test_address = 32'h0000_0000 ;
579
    test_command = `BC_RESERVED0 ;
580
    test_data = 32'h0000_0000 ;
581
    test_byte_enables_l   = 4'hF ;
582
    test_size = 0 ;
583
    test_make_addr_par_error = 0 ;
584
    test_make_data_par_error = 0;
585
    test_master_initial_wait_states = 0 ;
586
    test_master_subsequent_wait_states = 0 ;
587
    test_target_initial_wait_states = 0 ;
588
    test_target_subsequent_wait_states = 0;
589
    test_target_devsel_speed = `Test_Devsel_Fast ;
590
    test_fast_back_to_back = 0 ;
591
    test_target_termination = `Test_Target_Normal_Completion ;
592
    test_expect_master_abort = 0 ;
593
    test_start = 0 ;
594
    test_target_response = 0 ;
595
 
596
    master1_check_received_data = 0 ;
597
    master2_check_received_data = 0 ;
598
 
599
    irq_respond = 1 ;
600
    irq_vector  = 32'hAAAA_AAAA ;
601
 
602
    // fill memory and IO data with random values
603
    fill_memory ;
604
 
605
    INT_I = 0 ;
606
 
607
    // extract from constants which target image can be used as IO and which as memory
608
    `ifdef HOST
609
        target_mem_image = 1 ;
610
        target_io_image  = 1 ;
611
    `else
612
        target_mem_image = -1 ;
613
        target_io_image     = -1 ;
614
        if ( `PCI_BA1_MEM_IO === 0 )
615
            target_mem_image = 1 ;
616
        else
617
            target_io_image = 1 ;
618
 
619
        if ( target_mem_image === -1 )
620
        begin
621
            `ifdef PCI_IMAGE2
622
                if ( `PCI_BA2_MEM_IO === 0 )
623
                    target_mem_image = 2 ;
624
                else if ( target_io_image === -1 )
625
                    target_io_image = 2 ;
626
            `endif
627
        end
628
 
629
        if ( target_mem_image === -1 )
630
        begin
631
            `ifdef PCI_IMAGE3
632
                if ( `PCI_BA3_MEM_IO === 0 )
633
                    target_mem_image = 3 ;
634
                else if ( target_io_image === -1 )
635
                    target_io_image = 3 ;
636
            `endif
637
        end
638
 
639
        if ( target_mem_image === -1 )
640
        begin
641
            `ifdef PCI_IMAGE4
642
                if ( `PCI_BA4_MEM_IO === 0 )
643
                    target_mem_image = 4 ;
644
                else if ( target_io_image === -1 )
645
                    target_io_image = 4 ;
646
            `endif
647
        end
648
 
649
        if ( target_mem_image === -1 )
650
        begin
651
            `ifdef PCI_IMAGE5
652
                if ( `PCI_BA5_MEM_IO === 0 )
653
                    target_mem_image = 5 ;
654
                else if ( target_io_image === -1 )
655
                    target_io_image = 5 ;
656
            `endif
657
        end
658
    `endif
659
 
660
    tests_successfull = 0 ;
661
    tests_failed = 0 ;
662
 
663
    tb_log_file = $fopen("../log/pci_tb.log") ;
664
 
665
    if ( tb_log_file < 2 )
666
    begin
667
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
668
        $finish ;
669
    end
670
 
671
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
672
    $fdisplay( tb_log_file,"" ) ;
673
 
674
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
675
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
676
 
677
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
678
    begin
679
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
680
        $finish ;
681
    end
682
 
683
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
684
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
685
 
686
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
687
    if ( pci_mon_log_file_desc < 2 )
688
    begin
689
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
690
        $finish ;
691
    end
692
 
693
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
694
 
695
    run_tests ;
696
end
697
 
698
task fill_memory ;
699
    integer temp_index ;
700
begin
701
    // fill write memories with random data
702
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
703
    begin
704
        wmem_data[temp_index[9:0]] = $random ;
705 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
            $display(" ") ;
864
            $display("PCI transaction ordering tests finished!") ;
865
        end
866
    end
867
 
868
    test_summary ;
869
 
870
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
871
    $stop ;
872
end
873
endtask // run_tests
874
 
875
task do_reset;
876
begin
877
    next_test_name[79:0] <= "Reset.....";
878
 
879
    reset = 1'b1 ;
880
    #100 ;
881
    `ifdef HOST
882
        @(posedge wb_clock) ;
883
    `else
884
    `ifdef GUEST
885
        @(posedge pci_clock) ;
886
    `endif
887
    `endif
888
 
889
    reset <= 1'b0 ;
890
 
891
end
892
endtask
893
 
894
/*############################################################################
895
WB SLAVE UNIT tasks
896
===================
897
############################################################################*/
898
 
899
task configure_target ;
900
    input [1:0]  device_num ;
901
    reg   [31:0] base_address1 ;
902
    reg   [31:0] base_address2 ;
903
    reg   [2:0]  Master_ID;
904
    reg   [31:0] Target_Config_Addr;
905
begin
906
    if (device_num === 1)
907
    begin
908
        base_address1       = `BEH_TAR1_MEM_START ;
909
        base_address2       = `BEH_TAR1_IO_START  ;
910
        Master_ID           = `Test_Master_2 ;
911
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
912
    end
913
    else
914
    if (device_num === 2)
915
    begin
916
        base_address1       = `BEH_TAR2_MEM_START ;
917
        base_address2       = `BEH_TAR2_IO_START  ;
918
        Master_ID           = `Test_Master_1 ;
919
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
920
    end
921
 
922
    // write target's base addresses
923
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
924
    // type 0 cycle, byte enables, base address
925
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
926
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
927
 
928
    // enable target's response and master
929
    // enable parity errors, disable system error
930
 
931
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
932
 
933
end
934
endtask //configure_target
935
 
936
task test_wb_image ;
937
    input [2:0]  image_num ;
938
    reg   [11:0] ctrl_offset ;
939
    reg   [11:0] ba_offset ;
940
    reg   [11:0] am_offset ;
941
    reg   [11:0] ta_offset ;
942
    reg   [11:0] err_cs_offset ;
943
    reg `WRITE_STIM_TYPE write_data ;
944
    reg `READ_STIM_TYPE  read_data ;
945
    reg `READ_RETURN_TYPE read_status ;
946
 
947
    reg `WRITE_RETURN_TYPE write_status ;
948
    reg `WB_TRANSFER_FLAGS write_flags ;
949
    reg [31:0] temp_val ;
950
    reg        ok   ;
951
    reg [11:0] pci_ctrl_offset ;
952
    reg [31:0] image_base ;
953
    reg [31:0] target_address ;
954
    reg [31:0] translation_address ;
955
    integer    i ;
956
    integer    j ;
957
begin:main
958
    pci_ctrl_offset = 12'h4 ;
959
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
960
    // image 0 can only be configuration image - start with 1
961
    if (image_num === 1)
962
    begin
963
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
964
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
965
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
966
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
967
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
968
    end
969
    else if (image_num === 2)
970
    begin
971
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
972
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
973
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
974
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
975
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
976
    end
977
    else if (image_num === 3)
978
    begin
979
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
980
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
981
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
982
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
983
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
984
    end
985
    else if (image_num === 4)
986
    begin
987
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
988
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
989
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
990
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
991
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
992
    end
993
    else if (image_num === 5)
994
    begin
995
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
996
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
997
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
998
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
999
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1000
    end
1001
    else
1002
    begin
1003
        test_name   = "WB IMAGES' FEATURES TEST" ;
1004
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1005
        disable main ;
1006
    end
1007
 
1008
    target_address  = `BEH_TAR1_MEM_START ;
1009
    image_base      = 0 ;
1010
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1011
 
1012
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1013
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1014
    write_flags                      = 0 ;
1015
    write_flags`INIT_WAITS           = tb_init_waits ;
1016
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1017
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1018
 
1019
    test_name = "WB IMAGE CONFIGURATION" ;
1020
    // enable master & target operation
1021
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1022
    if ( ok !== 1 )
1023
    begin
1024
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1025
        test_fail("write to PCI Device Control register didn't succeede");
1026
        disable main ;
1027
    end
1028
 
1029
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1030
    if ( ok !== 1 )
1031
    begin
1032
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1033
        test_fail("write to WB Error Control and Status register didn't succeede");
1034
        disable main ;
1035
    end
1036
 
1037
    // prepare image control register
1038
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1039
    if ( ok !== 1 )
1040
    begin
1041
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1042
        test_fail("write to WB Image Control register didn't succeede");
1043
        disable main ;
1044
    end
1045
 
1046
    // prepare base address register
1047
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1048
    if ( ok !== 1 )
1049
    begin
1050
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1051
        test_fail("write to WB Base Address register didn't succeede");
1052
        disable main ;
1053
    end
1054
 
1055
    // write address mask register
1056
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1057
    if ( ok !== 1 )
1058
    begin
1059
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1060
        test_fail("write to WB Address Mask register didn't succeede");
1061
        disable main ;
1062
    end
1063
 
1064
    fork
1065
    begin
1066
        write_data`WRITE_ADDRESS = target_address ;
1067
        write_data`WRITE_DATA    = wmem_data[0] ;
1068
        write_data`WRITE_SEL     = 4'hF ;
1069
 
1070
        // handle retries from now on
1071
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1072
 
1073
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1074
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1075
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1076
        begin
1077
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1078
            test_fail("WB Slave state machine failed to post single memory write");
1079
            disable main ;
1080
        end
1081
 
1082
        // read written data back
1083
        read_data`READ_ADDRESS  = target_address ;
1084
        read_data`READ_SEL      = 4'hF ;
1085
        read_data`READ_TAG_STIM = 0 ;
1086
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1087
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1088
        begin
1089
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1090
            test_fail("PCI bridge didn't process the read as expected");
1091
            disable main ;
1092
        end
1093
 
1094
        if (read_status`READ_DATA !== wmem_data[0])
1095
        begin
1096
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1097
            test_fail("PCI bridge returned unexpected Read Data");
1098
        end
1099
        else
1100
            test_ok ;
1101
    end
1102
    begin
1103
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1104
        if ( ok !== 1 )
1105
        begin
1106
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1107
        end
1108
        else
1109
            test_ok ;
1110
 
1111
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1112
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1113
        if ( ok !== 1 )
1114
        begin
1115
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1116
        end
1117
    end
1118
    join
1119
 
1120
    // if address translation is implemented - try it out
1121
    translation_address = image_base ;
1122
    `ifdef ADDR_TRAN_IMPL
1123
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1124
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1125
    if ( ok !== 1 )
1126
    begin
1127
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1128
        test_fail("write to WB Image Translation Address Register failed") ;
1129
        disable main ;
1130
    end
1131
 
1132
    target_address  = `BEH_TAR2_MEM_START ;
1133
    image_base      = 0 ;
1134
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1135
 
1136
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1137
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1138
 
1139
    write_flags                      = 0 ;
1140
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1141
 
1142
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1143
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1144
    if ( ok !== 1 )
1145
    begin
1146
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1147
        test_fail("write to WB Image Base Address Register failed") ;
1148
        disable main ;
1149
    end
1150
 
1151
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1152
    // enable address translation
1153
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1154
    if ( ok !== 1 )
1155
    begin
1156
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1157
        test_fail("write to WB Image Control Register failed") ;
1158
        disable main ;
1159
    end
1160
 
1161
    `endif
1162
 
1163
    fork
1164
    begin
1165
        write_data`WRITE_ADDRESS = target_address + 4 ;
1166
        write_data`WRITE_DATA    = wmem_data[1] ;
1167
        write_data`WRITE_SEL     = 4'hF ;
1168
 
1169
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1170
 
1171
        `ifdef ADDR_TRAN_IMPL
1172
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1173
        `else
1174
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1175
        `endif
1176
 
1177
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1178
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1179
        begin
1180
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1181
            test_fail("WB Slave state machine failed to post single memory write") ;
1182
            disable main ;
1183
        end
1184
 
1185
        // read written data back
1186
        read_data`READ_ADDRESS  = target_address + 4 ;
1187
        read_data`READ_SEL      = 4'hF ;
1188
        read_data`READ_TAG_STIM = 0 ;
1189
 
1190
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1191
 
1192
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1193
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1194
        begin
1195
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1196
            test_fail("PCI bridge failed to process single delayed memory read") ;
1197
            disable main ;
1198
        end
1199
 
1200
        if (read_status`READ_DATA !== wmem_data[1])
1201
        begin
1202
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1203
            test_fail("PCI bridge returned unexpected Read Data");
1204
        end
1205
        else
1206
            test_ok ;
1207
    end
1208
    begin
1209
        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 ) ;
1210
        if ( ok !== 1 )
1211
        begin
1212
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1213
        end
1214
        else
1215
            test_ok ;
1216
 
1217
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1218
        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 ) ;
1219
        if ( ok !== 1 )
1220
        begin
1221
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1222
        end
1223
    end
1224
    join
1225
 
1226
    // 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
1227
    // prepare write data
1228
    for ( i = 0 ; i < 6 ; i = i + 1 )
1229
    begin
1230
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1231
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1232
        write_data`WRITE_SEL     = 4'hF ;
1233
        wishbone_master.blk_write_data[i] = write_data ;
1234
    end
1235
 
1236
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1237
    write_flags`WB_TRANSFER_CAB    = 1 ;
1238
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1239
 
1240
    fork
1241
    begin
1242
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1243
        wishbone_master.wb_block_write(write_flags, write_status) ;
1244
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1245
        begin
1246
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1247
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1248
            disable main ;
1249
        end
1250
    end
1251
    begin
1252
        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 ) ;
1253
        if ( ok !== 1 )
1254
        begin
1255
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1256
        end
1257
        else
1258
            test_ok ;
1259
    end
1260
    join
1261
 
1262
    // set burst size and latency timer
1263
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1264
 
1265
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1266
    write_flags`WB_TRANSFER_CAB    = 1 ;
1267
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1268
 
1269
    // prepare read data
1270
    for ( i = 0 ; i < 4 ; i = i + 1 )
1271
    begin
1272
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1273
        read_data`READ_SEL     = 4'hF ;
1274
        wishbone_master.blk_read_data_in[i] = read_data ;
1275
    end
1276
 
1277
    fork
1278
    begin
1279
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1280
        wishbone_master.wb_block_read(write_flags, read_status) ;
1281
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1282
        begin
1283
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1284
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1285
            disable main ;
1286
        end
1287
 
1288
        // check data read from target
1289
        for ( i = 0 ; i < 4 ; i = i + 1 )
1290
        begin
1291
            read_status = wishbone_master.blk_read_data_out[i] ;
1292
            if (read_status`READ_DATA !== wmem_data[2 + i])
1293
            begin
1294
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1295
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1296
            end
1297
        end
1298
    end
1299
    begin
1300
        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 ) ;
1301
        if ( ok !== 1 )
1302
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1303
        else
1304
            test_ok ;
1305
 
1306
        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 ) ;
1307
        if ( ok !== 1 )
1308
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1309
        else
1310
            test_ok ;
1311
 
1312
        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 ) ;
1313
        if ( ok !== 1 )
1314
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1315
        else
1316
            test_ok ;
1317
 
1318
        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 ) ;
1319
        if ( ok !== 1 )
1320
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1321
        else
1322
            test_ok ;
1323
 
1324
    end
1325
    join
1326
 
1327
    // now repeat this same burst read with various image features enabled or disabled
1328
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1329
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1330
    if (ok !== 1)
1331
    begin
1332
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1333
        test_fail("write to WB Image control register failed") ;
1334
        disable main ;
1335
    end
1336
 
1337
    fork
1338
    begin
1339
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1340
        wishbone_master.wb_block_read(write_flags, read_status) ;
1341
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1342
        begin
1343
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1344
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1345
            disable main ;
1346
        end
1347
 
1348
        // check data read from target
1349
        for ( i = 0 ; i < 4 ; i = i + 1 )
1350
        begin
1351
            read_status = wishbone_master.blk_read_data_out[i] ;
1352
            if (read_status`READ_DATA !== wmem_data[2 + i])
1353
            begin
1354
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1355
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1356
            end
1357
            else
1358
                test_ok ;
1359
        end
1360
    end
1361
    begin
1362
        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 ) ;
1363
        if ( ok !== 1 )
1364
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1365
    end
1366
    join
1367
 
1368
    read_data`READ_ADDRESS  = target_address ;
1369
    read_data`READ_SEL      = 4'hF ;
1370
    read_data`READ_TAG_STIM = 0 ;
1371
 
1372
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1373
    fork
1374
    begin
1375
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1376
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1377
        begin
1378
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1379
            test_fail("delayed single memory read wasn't processed as expected") ;
1380
            disable main ;
1381
        end
1382
 
1383
        if (read_status`READ_DATA !== wmem_data[0])
1384
        begin
1385
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1386
            test_fail("delayed single memory read data value returned was not as expected") ;
1387
        end
1388
        else
1389
            test_ok ;
1390
    end
1391
    begin
1392
        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 ) ;
1393
        if ( ok !== 1 )
1394
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1395
    end
1396
    join
1397
 
1398
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1399
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1400
    if (ok !== 1)
1401
    begin
1402
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1403
        test_fail("write to WB Image control register failed") ;
1404
        disable main ;
1405
    end
1406
 
1407
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1408
    fork
1409
    begin
1410
        wishbone_master.wb_block_read(write_flags, read_status) ;
1411
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1412
        begin
1413
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1414
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1415
            disable main ;
1416
        end
1417
 
1418
        // check data read from target
1419
        for ( i = 0 ; i < 4 ; i = i + 1 )
1420
        begin
1421
            read_status = wishbone_master.blk_read_data_out[i] ;
1422
            if (read_status`READ_DATA !== wmem_data[2 + i])
1423
            begin
1424
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1425
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1426
            end
1427
            else
1428
                test_ok ;
1429
        end
1430
    end
1431
    begin
1432
        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 ) ;
1433
        if ( ok !== 1 )
1434
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1435
    end
1436
    join
1437
 
1438
    read_data`READ_ADDRESS  = target_address + 4 ;
1439
    read_data`READ_SEL      = 4'hF ;
1440
    read_data`READ_TAG_STIM = 0 ;
1441
 
1442
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1443
    fork
1444
    begin
1445
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1446
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1447
        begin
1448
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1449
            test_fail("delayed single memory read wasn't processed as expected") ;
1450
            disable main ;
1451
        end
1452
 
1453
        if (read_status`READ_DATA !== wmem_data[1])
1454
        begin
1455
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1456
            test_fail("delayed single memory read data value returned was not as expected") ;
1457
        end
1458
        else
1459
            test_ok ;
1460
    end
1461
    begin
1462
        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 ) ;
1463
        if ( ok !== 1 )
1464
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1465
    end
1466
    join
1467
 
1468
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1469
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1470
    if (ok !== 1)
1471
    begin
1472
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1473
        test_fail("write to WB Image control register failed") ;
1474
        disable main ;
1475
    end
1476
 
1477
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1478
    fork
1479
    begin
1480
        wishbone_master.wb_block_read(write_flags, read_status) ;
1481
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1482
        begin
1483
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1484
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1485
            disable main ;
1486
        end
1487
 
1488
        // check data read from target
1489
        for ( i = 0 ; i < 4 ; i = i + 1 )
1490
        begin
1491
            read_status = wishbone_master.blk_read_data_out[i] ;
1492
            if (read_status`READ_DATA !== wmem_data[2 + i])
1493
            begin
1494
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1495
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1496
            end
1497
            else
1498
                test_ok ;
1499
        end
1500
    end
1501
    begin
1502
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 0, 0, ok ) ;
1503
        if ( ok !== 1 )
1504
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1505
    end
1506
    join
1507
 
1508
    read_data`READ_ADDRESS  = target_address + 8 ;
1509
    read_data`READ_SEL      = 4'hF ;
1510
    read_data`READ_TAG_STIM = 0 ;
1511
 
1512
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1513
    fork
1514
    begin
1515
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1516
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1517
        begin
1518
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1519
            test_fail("delayed single memory read wasn't processed as expected") ;
1520
            disable main ;
1521
        end
1522
 
1523
        if (read_status`READ_DATA !== wmem_data[2])
1524
        begin
1525
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1526
            test_fail("delayed single memory read data value returned was not as expected") ;
1527
        end
1528
        else
1529
            test_ok ;
1530
    end
1531
    begin
1532
        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 ) ;
1533
        if ( ok !== 1 )
1534
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1535
    end
1536
    join
1537
 
1538
    // map image to IO space
1539
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1540
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1541
    if ( ok !== 1 )
1542
    begin
1543
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1544
        test_fail("write to WB Image Base Address register failed") ;
1545
        disable main ;
1546
    end
1547
 
1548
    write_data`WRITE_ADDRESS = target_address ;
1549
    write_data`WRITE_DATA    = wmem_data[11] ;
1550
    write_data`WRITE_SEL     = 4'hF ;
1551
 
1552
    // handle retries from now on
1553
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1554
 
1555
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1556
    fork
1557
    begin
1558
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1559
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1560
        begin
1561
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1562
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1563
            disable main ;
1564
        end
1565
    end
1566
    begin
1567
        // currently IO commands not supported in behavioral models - master abort
1568
        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 ) ;
1569
        if ( ok !== 1 )
1570
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1571
        else
1572
            test_ok ;
1573
    end
1574
    join
1575
 
1576
    read_data`READ_ADDRESS  = target_address ;
1577
    read_data`READ_SEL      = 4'hF ;
1578
    read_data`READ_TAG_STIM = 0 ;
1579
 
1580
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1581
 
1582
    // currently io commands are not supported by behavioral target - transfer should not be completed
1583
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1584
    fork
1585
    begin
1586
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1587
        if (read_status`CYC_ERR !== 1)
1588
        begin
1589
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1590
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1591
            disable main ;
1592
        end
1593
        else
1594
            test_ok ;
1595
    end
1596
    begin
1597
        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 ) ;
1598
        if ( ok !== 1 )
1599
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1600
    end
1601
    join
1602
 
1603
    // test byte addressing
1604
    read_data`READ_ADDRESS = target_address + 2 ;
1605
    read_data`READ_SEL     = 4'b1100 ;
1606
 
1607
    fork
1608
    begin
1609
        // currently io commands are not supported by behavioral target - transfer should not be completed
1610
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1611
        if (read_status`CYC_ERR !== 1)
1612
        begin
1613
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1614
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1615
            disable main ;
1616
        end
1617
        else test_ok ;
1618
    end
1619
    begin
1620
        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 ) ;
1621
        if ( ok !== 1 )
1622
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1623
    end
1624
    join
1625
 
1626
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1627
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1628
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1629
    if ( ok !== 1 )
1630
    begin
1631
        test_fail("WB Base address register could not be written") ;
1632
        disable main ;
1633
    end
1634
 
1635
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1636
    if ( ok !== 1 )
1637
    begin
1638
        test_fail("WB Address Mask register could not be written") ;
1639
        disable main ;
1640
    end
1641
 
1642
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1643
    if ( ok !== 1 )
1644
    begin
1645
        test_fail("WB Image Control register could not be written") ;
1646
        disable main ;
1647
    end
1648
 
1649
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1650
    write_data`WRITE_DATA    = wmem_data[11] ;
1651
    write_data`WRITE_SEL     = 4'b1000 ;
1652
 
1653
    // handle retries from now on
1654
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1655
 
1656
    fork
1657
    begin
1658
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1659
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1660
        begin
1661
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1662
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1663
            disable main ;
1664
        end
1665
    end
1666
    begin
1667
        // currently IO commands not supported in behavioral models - master abort
1668
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1669
        if ( ok !== 1 )
1670
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1671
        else
1672
            test_ok ;
1673
    end
1674
    join
1675
 
1676
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1677
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1678
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1679
 
1680
    fork
1681
    begin
1682
        // currently io commands are not supported by behavioral target - transfer should not be completed
1683
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1684
        if (read_status`CYC_ERR !== 1)
1685
        begin
1686
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1687
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1688
            disable main ;
1689
        end
1690
        else test_ok ;
1691
    end
1692
    begin
1693
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1694
        if ( ok !== 1 )
1695
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1696
    end
1697
    join
1698
 
1699
    test_name = "DISABLING WB IMAGE" ;
1700
 
1701
    // disable current image
1702
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1703
    if ( ok !== 1 )
1704
    begin
1705
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1706
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1707
        disable main ;
1708
    end
1709
 
1710
    // clear master abort status bit
1711
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1712
    if ( ok !== 1 )
1713
    begin
1714
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1715
        test_fail("write to PCI Device Status register not accepted as expected") ;
1716
        disable main ;
1717
    end
1718
 
1719
end //main
1720
endtask //test_wb_image
1721
 
1722
task wb_slave_errors ;
1723
    reg   [11:0] ctrl_offset ;
1724
    reg   [11:0] ba_offset ;
1725
    reg   [11:0] am_offset ;
1726
    reg   [11:0] ta_offset ;
1727
    reg `WRITE_STIM_TYPE write_data ;
1728
    reg `READ_STIM_TYPE  read_data ;
1729
    reg `READ_RETURN_TYPE read_status ;
1730
 
1731
    reg `WRITE_RETURN_TYPE write_status ;
1732
    reg `WB_TRANSFER_FLAGS write_flags ;
1733
    reg [31:0] temp_val1 ;
1734
    reg [31:0] temp_val2 ;
1735
    reg        ok   ;
1736
    reg [11:0] pci_ctrl_offset ;
1737
    reg [31:0] image_base ;
1738
    reg [31:0] target_address ;
1739
    integer    i ;
1740
    reg skip ;
1741
fork
1742
begin:main
1743
 
1744
    `ifdef GUEST
1745
        skip = 1 ;
1746
    `else
1747
        skip = 0 ;
1748
    `endif
1749
 
1750
    pci_ctrl_offset = 12'h4 ;
1751
 
1752
    // image 1 is used for error testing, since it is always implemented
1753
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1754
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1755
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1756
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1757
 
1758
    target_address  = `BEH_TAR1_MEM_START ;
1759
    image_base      = 0 ;
1760
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1761
 
1762
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1763
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1764
    write_flags                    = 0 ;
1765
    write_flags`INIT_WAITS         = tb_init_waits ;
1766
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1767
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1768
 
1769
    // enable master & target operation
1770
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1771
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1772
    if ( ok !== 1 )
1773
    begin
1774
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1775
        test_fail("PCI Device Control register couldn't be written") ;
1776
        disable no_transaction ;
1777
        disable main ;
1778
    end
1779
 
1780
    // prepare image control register
1781
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1782
    if ( ok !== 1 )
1783
    begin
1784
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1785
        test_fail("WB Image Control register couldn't be written") ;
1786
        disable no_transaction ;
1787
        disable main ;
1788
    end
1789
 
1790
    // prepare base address register
1791
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1792
    if ( ok !== 1 )
1793
    begin
1794
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1795
        test_fail("WB Base Address register couldn't be written") ;
1796
        disable no_transaction ;
1797
        disable main ;
1798
    end
1799
 
1800
    // write address mask register
1801
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1802
    if ( ok !== 1 )
1803
    begin
1804
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1805
        test_fail("WB Address Mask register couldn't be written") ;
1806
        disable no_transaction ;
1807
        disable main ;
1808
    end
1809
 
1810
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1811
 
1812
    skip = 0 ;
1813
 
1814
    // memory mapped image - access is erroneous when address is not alligned
1815
    write_data`WRITE_ADDRESS = target_address + 1 ;
1816
    write_data`WRITE_DATA    = wmem_data[0] ;
1817
    write_data`WRITE_SEL     = 4'hF ;
1818
 
1819
    // handle retries from now on
1820
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1821
 
1822
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1823
 
1824
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1825
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1826
    begin
1827
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1828
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1829
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1830
        disable no_transaction ;
1831
        disable main ;
1832
    end
1833
 
1834
    write_data`WRITE_ADDRESS = target_address + 2 ;
1835
 
1836
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1837
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1838
    begin
1839
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1840
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1841
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1842
        disable no_transaction ;
1843
        disable main ;
1844
 
1845
    end
1846
 
1847
    write_data`WRITE_ADDRESS = target_address + 3 ;
1848
 
1849
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1850
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1851
    begin
1852
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1853
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1854
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1855
        disable no_transaction ;
1856
        disable main ;
1857
    end
1858
 
1859
    test_ok ;
1860
 
1861
    // perform same tests for read accesses
1862
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1863
 
1864
    read_data`READ_ADDRESS  = target_address + 2 ;
1865
    read_data`READ_SEL      = 4'hF ;
1866
    read_data`READ_TAG_STIM = 0 ;
1867
 
1868
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1869
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1870
    begin
1871
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1872
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1873
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1874
        disable no_transaction ;
1875
        disable main ;
1876
    end
1877
 
1878
    test_ok ;
1879
 
1880
    // prepare write data
1881
    for ( i = 0 ; i < 6 ; i = i + 1 )
1882
    begin
1883
        write_data`WRITE_DATA    = wmem_data[i] ;
1884
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1885
        write_data`WRITE_SEL     = 4'hF ;
1886
        wishbone_master.blk_write_data[i] = write_data ;
1887
    end
1888
 
1889
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1890
    write_flags`WB_TRANSFER_CAB    = 1 ;
1891
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1892
 
1893
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1894
    wishbone_master.wb_block_write(write_flags, write_status) ;
1895
 
1896
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1897
    begin
1898
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1899
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1900
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1901
        disable no_transaction ;
1902
        disable main ;
1903
    end
1904
 
1905
    // prepare read data
1906
    for ( i = 0 ; i < 6 ; i = i + 1 )
1907
    begin
1908
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1909
        read_data`READ_SEL     = 4'hF ;
1910
        wishbone_master.blk_read_data_in[i] = read_data ;
1911
    end
1912
 
1913
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1914
    wishbone_master.wb_block_read(write_flags, read_status) ;
1915
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1916
    begin
1917
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1918
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1919
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
1920
        disable no_transaction ;
1921
        disable main ;
1922
    end
1923
 
1924
    test_ok ;
1925
 
1926
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1927
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
1928
 
1929
    // map image to IO space
1930
    `ifdef GUEST
1931
        skip = 1 ;
1932
    `endif
1933
 
1934
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
1935
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1936
    if ( ok !== 1 )
1937
    begin
1938
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1939
        test_fail("WB Image Base Address register couldn't be written") ;
1940
        disable no_transaction ;
1941
        disable main ;
1942
    end
1943
 
1944
    skip = 0 ;
1945
 
1946
    write_data`WRITE_ADDRESS = target_address ;
1947
    write_data`WRITE_DATA    = wmem_data[0] ;
1948
    write_data`WRITE_SEL     = 4'b1010 ;
1949
 
1950
    // don't handle retries
1951
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1952
 
1953
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
1954
 
1955
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1956
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1957
    begin
1958
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1959
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1960
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1961
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1962
        disable no_transaction ;
1963
        disable main ;
1964
    end
1965
 
1966
    write_data`WRITE_ADDRESS = target_address + 1 ;
1967
    write_data`WRITE_SEL     = 4'b0011 ;
1968
 
1969
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1970
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1971
    begin
1972
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1973
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1974
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1975
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1976
        disable no_transaction ;
1977
        disable main ;
1978
    end
1979
 
1980
    write_data`WRITE_SEL     = 4'b1100 ;
1981
 
1982
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1983
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1984
    begin
1985
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1986
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1987
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1988
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1989
        disable no_transaction ;
1990
        disable main ;
1991
    end
1992
 
1993
    write_data`WRITE_ADDRESS = target_address + 2 ;
1994
    write_data`WRITE_SEL     = 4'b0101 ;
1995
 
1996
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1997
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1998
    begin
1999
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2000
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2001
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2002
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2003
        disable no_transaction ;
2004
        disable main ;
2005
    end
2006
 
2007
    write_data`WRITE_SEL     = 4'b1000 ;
2008
 
2009
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2010
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2011
    begin
2012
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2013
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2014
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2015
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2016
        disable no_transaction ;
2017
        disable main ;
2018
    end
2019
 
2020
    write_data`WRITE_ADDRESS = target_address + 3 ;
2021
    write_data`WRITE_SEL     = 4'b1010 ;
2022
 
2023
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2024
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2025
    begin
2026
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2027
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2028
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2029
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2030
        disable no_transaction ;
2031
        disable main ;
2032
    end
2033
 
2034
    write_data`WRITE_SEL     = 4'b0110 ;
2035
 
2036
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2037
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2038
    begin
2039
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2040
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2041
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2042
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2043
        disable no_transaction ;
2044
        disable main ;
2045
    end
2046
 
2047
    test_ok ;
2048
 
2049
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2050
 
2051
    read_data`READ_ADDRESS  = target_address + 3 ;
2052
    read_data`READ_SEL      = 4'hF ;
2053
    read_data`READ_TAG_STIM = 0 ;
2054
 
2055
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2056
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2057
    begin
2058
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2059
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2060
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2061
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2062
        disable no_transaction ;
2063
        disable main ;
2064
    end
2065
 
2066
    test_ok ;
2067
 
2068
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2069
    // prepare write data
2070
    for ( i = 0 ; i < 6 ; i = i + 1 )
2071
    begin
2072
        write_data`WRITE_DATA    = wmem_data[i] ;
2073
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2074
        write_data`WRITE_SEL     = 4'hF ;
2075
        wishbone_master.blk_write_data[i] = write_data ;
2076
    end
2077
 
2078
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2079
    write_flags`WB_TRANSFER_CAB    = 1 ;
2080
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2081
 
2082
    wishbone_master.wb_block_write(write_flags, write_status) ;
2083
 
2084
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2085
    begin
2086
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2087
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2088
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2089
        disable no_transaction ;
2090
        disable main ;
2091
    end
2092
 
2093
    test_ok ;
2094
 
2095
    test_name = "CAB I/O READ TO WB SLAVE" ;
2096
    // prepare read data
2097
    for ( i = 0 ; i < 6 ; i = i + 1 )
2098
    begin
2099
        read_data`READ_ADDRESS = target_address + 4*i ;
2100
        read_data`READ_SEL     = 4'hF ;
2101
        wishbone_master.blk_read_data_in[i] = read_data ;
2102
    end
2103
 
2104
    wishbone_master.wb_block_read(write_flags, read_status) ;
2105
 
2106
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2107
    begin
2108
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2109
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2110
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2111
        disable no_transaction ;
2112
        disable main ;
2113
    end
2114
 
2115
    test_ok ;
2116
 
2117
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2118
 
2119
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2120
 
2121
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2122
    write_data`WRITE_ADDRESS = target_address + 1 ;
2123
    write_data`WRITE_DATA    = wmem_data[0] ;
2124
    write_data`WRITE_SEL     = 4'hF ;
2125
 
2126
    // don't handle retries
2127
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2128
 
2129
    `ifdef HOST
2130
        `define DO_W_CONF_TEST
2131
        `define DO_R_CONF_TEST
2132
    `else
2133
        `ifdef WB_CNF_IMAGE
2134
             `define DO_R_CONF_TEST
2135
        `endif
2136
    `endif
2137
 
2138
    `ifdef DO_W_CONF_TEST
2139
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2140
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2141
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2142
    begin
2143
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2144
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2145
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2146
        disable no_transaction ;
2147
        disable main ;
2148
    end
2149
 
2150
    write_data`WRITE_ADDRESS = target_address + 2 ;
2151
 
2152
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2153
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2154
    begin
2155
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2156
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2157
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2158
        disable no_transaction ;
2159
        disable main ;
2160
    end
2161
 
2162
    write_data`WRITE_ADDRESS = target_address + 3 ;
2163
 
2164
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2165
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2166
    begin
2167
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2168
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2169
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2170
        disable no_transaction ;
2171
        disable main ;
2172
    end
2173
 
2174
    test_ok ;
2175
    `endif
2176
 
2177
    `ifdef DO_R_CONF_TEST
2178
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2179
    read_data`READ_ADDRESS  = target_address + 3 ;
2180
    read_data`READ_SEL      = 4'hF ;
2181
    read_data`READ_TAG_STIM = 0 ;
2182
 
2183
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2184
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2185
    begin
2186
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2187
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2188
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2189
        disable no_transaction ;
2190
        disable main ;
2191
    end
2192
 
2193
    test_ok ;
2194
    `endif
2195
 
2196
    `ifdef DO_W_CONF_TEST
2197
    // prepare write data
2198
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2199
    for ( i = 0 ; i < 6 ; i = i + 1 )
2200
    begin
2201
        write_data`WRITE_DATA    = wmem_data[i] ;
2202
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2203
        write_data`WRITE_SEL     = 4'hF ;
2204
        wishbone_master.blk_write_data[i] = write_data ;
2205
    end
2206
 
2207
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2208
    write_flags`WB_TRANSFER_CAB    = 1 ;
2209
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2210
 
2211
    wishbone_master.wb_block_write(write_flags, write_status) ;
2212
 
2213
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2214
    begin
2215
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2216
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2217
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2218
        disable no_transaction ;
2219
        disable main ;
2220
    end
2221
    test_ok ;
2222
    `endif
2223
 
2224
    `ifdef DO_R_CONF_TEST
2225
    // prepare read data
2226
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2227
    for ( i = 0 ; i < 6 ; i = i + 1 )
2228
    begin
2229
        read_data`READ_ADDRESS = target_address + 4*i ;
2230
        read_data`READ_SEL     = 4'hF ;
2231
        wishbone_master.blk_read_data_in[i] = read_data ;
2232
    end
2233
 
2234
    wishbone_master.wb_block_read(write_flags, read_status) ;
2235
 
2236
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2237
    begin
2238
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2239
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2240
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2241
        disable no_transaction ;
2242
        disable main ;
2243
    end
2244
    test_ok ;
2245
    `endif
2246
 
2247
    `ifdef GUEST
2248
        skip = 1 ;
2249
    `endif
2250
 
2251
    // disable image
2252
    test_name = "DISABLE IMAGE" ;
2253
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2254
    if ( ok !== 1 )
2255
    begin
2256
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2257
        test_fail("WB Address Mask register couldn't be written") ;
2258
        disable no_transaction ;
2259
        disable main ;
2260
    end
2261
 
2262
    skip = 0 ;
2263
 
2264
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2265
 
2266
    disable no_transaction ;
2267
end
2268
begin:no_transaction
2269
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2270
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2271
    forever
2272
    begin
2273
        @(posedge pci_clock) ;
2274
        if ( skip !== 1 )
2275
        begin
2276
            if ( FRAME !== 1 )
2277
            begin
2278
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2279
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2280
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2281
            end
2282
        end
2283
    end
2284
end
2285
join
2286
endtask //wb_slave_errors
2287
 
2288
task wb_to_pci_error_handling ;
2289
    reg   [11:0] ctrl_offset ;
2290
    reg   [11:0] ba_offset ;
2291
    reg   [11:0] am_offset ;
2292
    reg   [11:0] ta_offset ;
2293
    reg   [11:0] err_cs_offset ;
2294
    reg `WRITE_STIM_TYPE write_data ;
2295
    reg `READ_STIM_TYPE  read_data ;
2296
    reg `READ_RETURN_TYPE read_status ;
2297
 
2298
    reg `WRITE_RETURN_TYPE write_status ;
2299
    reg `WB_TRANSFER_FLAGS write_flags ;
2300
    reg [31:0] temp_val1 ;
2301
    reg [31:0] temp_val2 ;
2302
    reg        ok   ;
2303
    reg [11:0] pci_ctrl_offset ;
2304
    reg [31:0] image_base ;
2305
    reg [31:0] target_address ;
2306
    integer    num_of_trans ;
2307
    integer    current ;
2308
    integer    i ;
2309
begin:main
2310
 
2311
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2312
 
2313
    pci_ctrl_offset = 12'h4 ;
2314
 
2315
    // disable error interrupts and disable error reporting
2316
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2317
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2318
    if ( ok !== 1 )
2319
    begin
2320
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2321
        test_fail("PCI Device Control register couldn't be written") ;
2322
        disable main ;
2323
    end
2324
 
2325
    // image 1 is used for error testing, since it is always implemented
2326
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2327
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2328
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2329
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2330
 
2331
    // set master abort testing address to address that goes out of target's range
2332
    target_address  = `BEH_TAR1_MEM_START ;
2333
    image_base      = 0 ;
2334
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2335
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2336
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2337
 
2338
    write_flags                    = 0 ;
2339
    write_flags`INIT_WAITS         = tb_init_waits ;
2340
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2341
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2342
 
2343
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2344
 
2345
    // enable master & target operation
2346
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2347
    if ( ok !== 1 )
2348
    begin
2349
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2350
        test_fail("PCI Device Control register couldn't be written") ;
2351
        disable main ;
2352
    end
2353
 
2354
    // prepare image control register
2355
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2356
    if ( ok !== 1 )
2357
    begin
2358
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2359
        test_fail("WB Image Control register couldn't be written") ;
2360
        disable main ;
2361
    end
2362
 
2363
    // prepare base address register
2364
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2365
    if ( ok !== 1 )
2366
    begin
2367
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2368
        test_fail("WB Image Base Address register couldn't be written") ;
2369
        disable main ;
2370
    end
2371
 
2372
    // write address mask register
2373
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2374
    if ( ok !== 1 )
2375
    begin
2376
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2377
        test_fail("WB Image Address Mask register couldn't be written") ;
2378
        disable main ;
2379
    end
2380
 
2381
    // disable error reporting
2382
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2383
    if ( ~ok )
2384
    begin
2385
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2386
        test_fail("WB Error Control and Status register couldn't be written") ;
2387
        disable main ;
2388
    end
2389
 
2390
    // perform two writes - one to error address and one to OK address
2391
    // prepare write buffer
2392
 
2393
    write_data`WRITE_ADDRESS = target_address ;
2394
    write_data`WRITE_DATA    = wmem_data[100] ;
2395
    write_data`WRITE_SEL     = 4'hF ;
2396
 
2397
    wishbone_master.blk_write_data[0] = write_data ;
2398
 
2399
    write_flags`WB_TRANSFER_SIZE = 2 ;
2400
 
2401
    // don't handle retries
2402
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2403
    write_flags`WB_TRANSFER_CAB    = 0 ;
2404
 
2405
    $display("Introducing master abort error on single WB to PCI write!") ;
2406
 
2407
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2408
    // first disable target 1
2409
 
2410
    configuration_cycle_write(0,             // bus number
2411
                              1,             // device number
2412
                              0,             // function number
2413
                              1,             // register number
2414
                              0,             // type of configuration cycle
2415
                              4'b0001,       // byte enables
2416
                              32'h0000_0000  // data
2417
                             ) ;
2418
 
2419
    fork
2420
    begin
2421
        // start no response monitor in parallel with writes
2422
        musnt_respond(ok) ;
2423
        if ( ok !== 1 )
2424
        begin
2425
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2426
            $display("Testbench is configured wrong!") ;
2427
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2428
        end
2429
        else
2430
            test_ok ;
2431
    end
2432
    begin
2433
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2434
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2435
       begin
2436
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2437
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2438
           test_fail("WB Slave state machine failed to post single memory write");
2439
           disable main ;
2440
       end
2441
    end
2442
    join
2443
 
2444
    /*// read data from second write
2445
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2446
    read_data`READ_ADDRESS = target_address ;
2447
    read_data`READ_SEL     = 4'hF ;
2448
    read_data`READ_TAG_STIM = 0 ;
2449
 
2450
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2451
 
2452
    if ( read_status`READ_DATA !== wmem_data[101] )
2453
    begin
2454
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2455
    end
2456
    */
2457
 
2458
    // read error status register - no errors should be reported since reporting was disabled
2459
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2460
 
2461
    @(posedge pci_clock) ;
2462
    // wait for two WB clocks for synchronization to be finished
2463
    repeat (2)
2464
        @(posedge wb_clock) ;
2465
 
2466
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2467
    if ( temp_val1[8] !== 0 )
2468
    begin
2469
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2470
        $display("Error reporting was disabled, but error was reported anyway!") ;
2471
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2472
        disable main ;
2473
    end
2474
    test_ok ;
2475
 
2476
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2477
    // check for interrupts - there should be no interrupt requests active
2478
    `ifdef HOST
2479
        repeat(4)
2480
            @(posedge wb_clock) ;
2481
 
2482
        if ( INT_O !== 0 )
2483
        begin
2484
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2485
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2486
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2487
        end
2488
        else
2489
            test_ok ;
2490
    `else
2491
    `ifdef GUEST
2492
        repeat( 4 )
2493
            @(posedge pci_clock) ;
2494
 
2495
        if ( INTA !== 1 )
2496
        begin
2497
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2498
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2499
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2500
        end
2501
        else
2502
            test_ok ;
2503
    `endif
2504
    `endif
2505
 
2506
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2507
    // check PCI status register
2508
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2509
    if ( temp_val1[29] !== 1 )
2510
    begin
2511
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2512
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2513
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2514
    end
2515
    else
2516
        test_ok ;
2517
 
2518
    // clear
2519
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2520
 
2521
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2522
 
2523
    $display("Introducing master abort error to CAB write!") ;
2524
    // now enable error reporting mechanism
2525
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2526
    // enable error interrupts
2527
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2528
 
2529
    // configure flags for CAB transfer
2530
    write_flags`WB_TRANSFER_CAB = 1 ;
2531
    write_flags`WB_TRANSFER_SIZE = 3 ;
2532
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2533
 
2534
    // prepare data for erroneous write
2535
    for ( i = 0 ; i < 3 ; i = i + 1 )
2536
    begin
2537
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2538
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2539
        write_data`WRITE_SEL     = 4'hF ;
2540
        wishbone_master.blk_write_data[i] = write_data ;
2541
    end
2542
 
2543
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2544
    fork
2545
    begin
2546
        wishbone_master.wb_block_write(write_flags, write_status) ;
2547
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2548
        begin
2549
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2550
            $display("Complete burst write through WB slave didn't succeed!") ;
2551
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2552
            disable main ;
2553
        end
2554
    end
2555
    begin
2556
        musnt_respond(ok) ;
2557
        if ( ok !== 1 )
2558
        begin
2559
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2560
            $display("Testbench is configured wrong!") ;
2561
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2562
        end
2563
        else
2564
            test_ok ;
2565
    end
2566
    join
2567
 
2568
    // check error status address, data, byte enables and bus command
2569
    // error status bit is signalled on PCI clock and synchronized to WB clock
2570
    // wait one PCI clock cycle
2571
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2572
    ok = 1 ;
2573
    @(posedge pci_clock) ;
2574
 
2575
    // wait for two WB clocks for synchronization to be finished
2576
    repeat (2)
2577
        @(posedge wb_clock) ;
2578
 
2579
    // read registers
2580
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2581
    if ( temp_val1[8] !== 1 )
2582
    begin
2583
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2584
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2585
        ok = 0 ;
2586
    end
2587
 
2588
    if ( temp_val1[9] !== 1 )
2589
    begin
2590
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2591
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2592
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2593
        ok = 0 ;
2594
    end
2595
 
2596
    if ( temp_val1[31:28] !== 0 )
2597
    begin
2598
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2599
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2600
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2601
        ok = 0 ;
2602
    end
2603
 
2604
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2605
    begin
2606
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2607
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2608
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2609
        ok = 0 ;
2610
    end
2611
 
2612
    // read error address register
2613
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2614
    if ( temp_val1 !== target_address )
2615
    begin
2616
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2617
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2618
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2619
        ok = 0 ;
2620
    end
2621
 
2622
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2623
    if ( temp_val1 !== wmem_data[110] )
2624
    begin
2625
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2626
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2627
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2628
        ok = 0 ;
2629
    end
2630
 
2631
    // check PCI status register
2632
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2633
    if ( temp_val1[29] !== 1 )
2634
    begin
2635
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2636
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2637
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2638
        ok = 0 ;
2639
    end
2640
 
2641
    if ( temp_val1[28] !== 0 )
2642
    begin
2643
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2644
        $display("Received Target Abort bit was set for no reason!") ;
2645
        test_fail("Received Target Abort bit was set for no reason") ;
2646
        ok = 0 ;
2647
    end
2648
 
2649
    if ( ok )
2650
        test_ok ;
2651
 
2652
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2653
 
2654
    // clear error status bit
2655
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2656
 
2657
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2658
 
2659
    ok = 1 ;
2660
 
2661
    `ifdef HOST
2662
        repeat(4)
2663
        @(posedge wb_clock) ;
2664
        if ( INT_O !== 1 )
2665
        begin
2666
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2667
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2668
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2669
            ok = 0 ;
2670
        end
2671
    `else
2672
    `ifdef GUEST
2673
        repeat(4)
2674
        @(posedge pci_clock) ;
2675
        if ( INTA !== 0 )
2676
        begin
2677
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2678
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2679
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2680
            ok = 0 ;
2681
        end
2682
    `endif
2683
    `endif
2684
 
2685
    // read interrupt status register
2686
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2687
    if ( temp_val1 !== 32'h0000_0002 )
2688
    begin
2689
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2690
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2691
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2692
        test_fail("Interrupt Status register returned wrong value") ;
2693
        ok = 0 ;
2694
    end
2695
 
2696
    if ( ok )
2697
        test_ok ;
2698
    // clear interrupt status bits
2699
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2700
 
2701
    ok = 1 ;
2702
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2703
    // wait for two clock cycles before checking interrupt request deassertion
2704
    `ifdef HOST
2705
        repeat (4)
2706
            @(posedge wb_clock) ;
2707
 
2708
        if ( INT_O !== 0 )
2709
        begin
2710
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2711
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2712
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2713
            ok = 0 ;
2714
        end
2715
    `else
2716
    `ifdef GUEST
2717
        repeat (4)
2718
            @(posedge pci_clock) ;
2719
 
2720
        if ( INTA !== 1 )
2721
        begin
2722
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2723
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2724
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2725
            ok = 0 ;
2726
        end
2727
    `endif
2728
    `endif
2729
 
2730
    if ( ok )
2731
        test_ok ;
2732
 
2733
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2734
    ok = 1 ;
2735
    // enable target
2736
    configuration_cycle_write(0,             // bus number
2737
                              1,             // device number
2738
                              0,             // function number
2739
                              1,             // register number
2740
                              0,             // type of configuration cycle
2741
                              4'b0001,       // byte enables
2742
                              32'h0000_0007  // data
2743
                             ) ;
2744
    // prepare data for ok write
2745
    for ( i = 0 ; i < 3 ; i = i + 1 )
2746
    begin
2747
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2748
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2749
        write_data`WRITE_SEL     = 4'hF ;
2750
        wishbone_master.blk_write_data[i] = write_data ;
2751
    end
2752
 
2753
    wishbone_master.wb_block_write(write_flags, write_status) ;
2754
 
2755
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2756
    begin
2757
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2758
        $display("Complete burst write through WB slave didn't succeed!") ;
2759
        test_fail("WB Slave state machine failed to post CAB write") ;
2760
        disable main ;
2761
    end
2762
 
2763
    // do a read
2764
    for ( i = 0 ; i < 3 ; i = i + 1 )
2765
    begin
2766
        read_data`READ_ADDRESS = target_address + 4*i ;
2767
        read_data`READ_SEL     = 4'hF ;
2768
        wishbone_master.blk_read_data_in[i] = read_data ;
2769
    end
2770
 
2771
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2772
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2773
    write_flags`WB_TRANSFER_CAB    = 1 ;
2774
 
2775
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2776
 
2777
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2778
    begin
2779
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2780
        $display("Complete burst read through WB slave didn't succeed!") ;
2781
        test_fail("Delayed CAB write was not processed as expected") ;
2782
        disable main ;
2783
    end
2784
 
2785
    for ( i = 0 ; i < 3 ; i = i + 1 )
2786
    begin
2787
        read_status = wishbone_master.blk_read_data_out[i] ;
2788
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2789
        begin
2790
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2791
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2792
        end
2793
    end
2794
 
2795
    $display("Introducing master abort error to single read!") ;
2796
    // disable target
2797
    configuration_cycle_write(0,             // bus number
2798
                              1,             // device number
2799
                              0,             // function number
2800
                              1,             // register number
2801
                              0,             // type of configuration cycle
2802
                              4'b0001,       // byte enables
2803
                              32'h0000_0000  // data
2804
                             ) ;
2805
    // set read data
2806
    read_data`READ_ADDRESS = target_address ;
2807
    read_data`READ_SEL     = 4'hF ;
2808
 
2809
    // enable automatic retry handling
2810
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2811
    write_flags`WB_TRANSFER_CAB    = 0 ;
2812
 
2813
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2814
    fork
2815
    begin
2816
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2817
    end
2818
    begin
2819
        musnt_respond(ok) ;
2820
        if ( ok !== 1 )
2821
        begin
2822
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2823
            $display("Testbench is configured wrong!") ;
2824
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2825
        end
2826
    end
2827
    join
2828
 
2829
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2830
    begin
2831
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2832
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2833
        $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) ;
2834
        test_fail("read didn't finish on WB bus as expected") ;
2835
        disable main ;
2836
    end
2837
 
2838
    test_ok ;
2839
 
2840
 
2841
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2842
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2843
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2844
    if ( temp_val1[8] !== 0 )
2845
    begin
2846
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2847
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2848
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2849
    end
2850
    else
2851
        test_ok ;
2852
 
2853
    // now check normal read operation
2854
    configuration_cycle_write(0,             // bus number
2855
                              1,             // device number
2856
                              0,             // function number
2857
                              1,             // register number
2858
                              0,             // type of configuration cycle
2859
                              4'b0001,       // byte enables
2860
                              32'h0000_0007  // data
2861
                             ) ;
2862
 
2863
    test_name = "CHECK NORMAL READ AFTER ERROR TERMINATED READ" ;
2864
    read_data`READ_ADDRESS = target_address ;
2865
    read_data`READ_SEL     = 4'hF ;
2866
 
2867
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2868
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2869
    begin
2870
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2871
        $display("WB slave failed to process single read!") ;
2872
        $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) ;
2873
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2874
        disable main ;
2875
    end
2876
 
2877
    if ( read_status`READ_DATA !== wmem_data[113] )
2878
    begin
2879
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2880
        test_fail("when read finished on WB bus, wrong data was provided") ;
2881
    end
2882
    else
2883
        test_ok ;
2884
 
2885
    // check PCI status register
2886
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT ON DELAYED READ" ;
2887
    ok = 1 ;
2888
 
2889
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2890
    if ( temp_val1[29] !== 1 )
2891
    begin
2892
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2893
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2894
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2895
        ok = 0 ;
2896
    end
2897
 
2898
    if ( temp_val1[28] !== 0 )
2899
    begin
2900
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2901
        $display("Received Target Abort bit was set for no reason!") ;
2902
        test_fail("Received Target Abort bit was set for no reason") ;
2903
        ok = 0 ;
2904
    end
2905
    if ( ok )
2906
        test_ok ;
2907
 
2908
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2909
 
2910
    $display("Introducing master abort error to CAB read!") ;
2911
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2912
 
2913
    configuration_cycle_write(0,             // bus number
2914
                              1,             // device number
2915
                              0,             // function number
2916
                              1,             // register number
2917
                              0,             // type of configuration cycle
2918
                              4'b0001,       // byte enables
2919
                              32'h0000_0000  // data
2920
                             ) ;
2921
 
2922
    for ( i = 0 ; i < 3 ; i = i + 1 )
2923
    begin
2924
        read_data`READ_ADDRESS = target_address + 4*i ;
2925
        read_data`READ_SEL     = 4'hF ;
2926
        wishbone_master.blk_read_data_in[i] = read_data ;
2927
    end
2928
 
2929
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2930
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2931
    write_flags`WB_TRANSFER_CAB    = 1 ;
2932
 
2933
    fork
2934
    begin
2935
        wishbone_master.wb_block_read( write_flags, read_status ) ;
2936
    end
2937
    begin
2938
        musnt_respond(ok) ;
2939
        if ( ok !== 1 )
2940
        begin
2941
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2942
            $display("Testbench is configured wrong!") ;
2943
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2944
        end
2945
    end
2946
    join
2947
 
2948
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2949
    begin
2950
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2951
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2952
        $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) ;
2953
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
2954
        disable main ;
2955
    end
2956
    else
2957
        test_ok ;
2958
 
2959
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
2960
    ok = 1 ;
2961
    // check PCI status register
2962
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2963
    if ( temp_val1[29] !== 1 )
2964
    begin
2965
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2966
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2967
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2968
        ok = 0 ;
2969
    end
2970
 
2971
    if ( temp_val1[28] !== 0 )
2972
    begin
2973
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2974
        $display("Received Target Abort bit was set for no reason!") ;
2975
        test_fail("Received Target Abort bit was set for no reason") ;
2976
        ok = 0 ;
2977
    end
2978
 
2979
    if ( ok )
2980
        test_ok ;
2981
 
2982
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2983
 
2984
    $display("Introducing target abort termination to single write!") ;
2985
 
2986
    // disable error reporting and interrupts
2987
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
2988
 
2989
    configuration_cycle_write(0,             // bus number
2990
                              1,             // device number
2991
                              0,             // function number
2992
                              1,             // register number
2993
                              0,             // type of configuration cycle
2994
                              4'b0001,       // byte enables
2995
                              32'h0000_0007  // data
2996
                             ) ;
2997
 
2998
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
2999
    if ( ok !== 1 )
3000
    begin
3001
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3002
        test_fail("WB Error Control and Status register couldn't be written to") ;
3003
        disable main ;
3004
    end
3005
 
3006
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3007
    if ( ok !== 1 )
3008
    begin
3009
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3010
        test_fail("Interrupt Control register couldn't be written to") ;
3011
        disable main ;
3012
    end
3013
 
3014
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3015
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3016
 
3017
    write_data`WRITE_ADDRESS = target_address ;
3018
    write_data`WRITE_DATA    = wmem_data[0] ;
3019
    write_data`WRITE_SEL     = 4'hF ;
3020
 
3021
    wishbone_master.blk_write_data[0] = write_data ;
3022
 
3023
    write_data`WRITE_ADDRESS = target_address + 4;
3024
    write_data`WRITE_DATA    = wmem_data[1] ;
3025
    write_data`WRITE_SEL     = 4'hF ;
3026
 
3027
    wishbone_master.blk_write_data[1] = write_data ;
3028
 
3029
    write_flags`WB_TRANSFER_SIZE = 2 ;
3030
 
3031
    // don't handle retries
3032
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3033
    write_flags`WB_TRANSFER_CAB    = 0 ;
3034
 
3035
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3036
    fork
3037
    begin
3038
        wishbone_master.wb_block_write(write_flags, write_status) ;
3039
 
3040
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3041
        begin
3042
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3043
            $display("Image writes were not accepted as expected!") ;
3044
            $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) ;
3045
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3046
            disable main ;
3047
        end
3048
 
3049
        // read data back to see, if it was written OK
3050
        read_data`READ_ADDRESS         = target_address + 4;
3051
        read_data`READ_SEL             = 4'hF ;
3052
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3053
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3054
    end
3055
    begin
3056
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3057
        if ( ok !== 1 )
3058
        begin
3059
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3060
        end
3061
        else
3062
            test_ok ;
3063
 
3064
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3065
 
3066
        // when first transaction finishes - enable normal target response!
3067
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3068
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3069
 
3070
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3071
        if ( ok !== 1 )
3072
        begin
3073
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3074
        end
3075
        else
3076
            test_ok ;
3077
 
3078
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3079
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3080
        if ( ok !== 1 )
3081
        begin
3082
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3083
        end
3084
    end
3085
    join
3086
 
3087
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3088
    begin
3089
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3090
        $display("Bridge failed to process single read after target abort terminated write!") ;
3091
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3092
        disable main ;
3093
    end
3094
 
3095
    if ( read_status`READ_DATA !== wmem_data[1] )
3096
    begin
3097
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3098
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3099
    end
3100
    else
3101
        test_ok ;
3102
 
3103
    // check interrupt and error statuses!
3104
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3105
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3106
    if ( temp_val1[8] !== 0 )
3107
    begin
3108
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3109
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3110
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3111
    end
3112
    else
3113
        test_ok ;
3114
 
3115
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3116
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3117
    if ( temp_val1[1] !== 0 )
3118
    begin
3119
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3120
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3121
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3122
    end
3123
    else
3124
        test_ok ;
3125
 
3126
    // check PCI status register
3127
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3128
    ok = 1 ;
3129
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3130
    if ( temp_val1[29] !== 0 )
3131
    begin
3132
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3133
        $display("Received Master Abort bit was set with no reason!") ;
3134
        test_fail("Received Master Abort bit was set with no reason") ;
3135
        ok = 0 ;
3136
    end
3137
 
3138
    if ( temp_val1[28] !== 1 )
3139
    begin
3140
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3141
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3142
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3143
        ok = 0 ;
3144
    end
3145
 
3146
    if ( ok )
3147
        test_ok ;
3148
 
3149
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3150
 
3151
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3152
 
3153
    $display("Introducing target abort termination to CAB write!") ;
3154
    // enable error reporting mechanism
3155
 
3156
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3157
    if ( ok !== 1 )
3158
    begin
3159
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3160
        test_fail("WB Error Control and Status register could not be written to") ;
3161
        disable main ;
3162
    end
3163
 
3164
    for ( i = 0 ; i < 3 ; i = i + 1 )
3165
    begin
3166
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3167
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3168
        write_data`WRITE_SEL     = 4'b1010 ;
3169
        wishbone_master.blk_write_data[i] = write_data ;
3170
    end
3171
 
3172
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3173
    write_flags`WB_TRANSFER_CAB    = 1 ;
3174
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3175
 
3176
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3177
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3178
 
3179
    fork
3180
    begin
3181
        wishbone_master.wb_block_write(write_flags, write_status) ;
3182
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3183
        begin
3184
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3185
            $display("Bridge failed to process complete CAB write!") ;
3186
            test_fail("bridge failed to post CAB Memory Write") ;
3187
            disable main ;
3188
        end
3189
    end
3190
    begin
3191
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3192
        if ( ok !== 1 )
3193
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3194
        else
3195
            test_ok ;
3196
    end
3197
    join
3198
 
3199
    // check statuses and data from error
3200
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3201
    ok = 1 ;
3202
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3203
    if ( temp_val1[8] !== 1 )
3204
    begin
3205
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3206
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3207
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3208
        ok = 0 ;
3209
    end
3210
 
3211
    if ( temp_val1[9] !== 0 )
3212
    begin
3213
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3214
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3215
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3216
        ok = 0 ;
3217
    end
3218
 
3219
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3220
    begin
3221
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3222
        $display("Value in W_ERR_CS register was wrong!") ;
3223
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3224
        test_fail("BE Field didn't provided expected value") ;
3225
        ok = 0 ;
3226
    end
3227
 
3228
    if ( ok )
3229
        test_ok ;
3230
 
3231
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3232
    ok = 1 ;
3233
    // check erroneous address and data
3234
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3235
    if ( temp_val1 !== (target_address + 8) )
3236
    begin
3237
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3238
        $display("Value in W_ERR_ADDR register was wrong!") ;
3239
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3240
        test_fail("Value in WB Erroneous Address register was wrong") ;
3241
        ok = 0 ;
3242
    end
3243
 
3244
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3245
    if ( temp_val1 !== wmem_data[120] )
3246
    begin
3247
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3248
        $display("Value in W_ERR_DATA register was wrong!") ;
3249
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3250
        test_fail("Value in WB Erroneous Data register was wrong") ;
3251
        ok = 0 ;
3252
    end
3253
 
3254
    if ( ok )
3255
        test_ok ;
3256
 
3257
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3258
    ok = 1 ;
3259
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3260
    if ( temp_val1[29] !== 0 )
3261
    begin
3262
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3263
        $display("Received Master Abort bit was set with no reason!") ;
3264
        test_fail("Received Master Abort bit was set for no reason") ;
3265
        ok = 0 ;
3266
    end
3267
 
3268
    if ( temp_val1[28] !== 1 )
3269
    begin
3270
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3271
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3272
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3273
        ok = 0 ;
3274
    end
3275
 
3276
    if ( ok )
3277
        test_ok ;
3278
 
3279
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3280
 
3281
    // clear error status bit and enable error interrupts
3282
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3283
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3284
 
3285
    // check if error bit was cleared
3286
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3287
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3288
    if ( temp_val1[8] !== 0 )
3289
    begin
3290
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3291
        $display("Error bit was not cleared even though one was written to its location!") ;
3292
        test_fail("Error bit was not cleared even though one was written to its location") ;
3293
    end
3294
 
3295
    // repeat same write with different target configuration
3296
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3297
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3298
 
3299
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3300
    fork
3301
    begin
3302
        write_flags`WB_TRANSFER_SIZE = 2 ;
3303
        wishbone_master.wb_block_write(write_flags, write_status) ;
3304
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3305
        begin
3306
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3307
            $display("Bridge failed to process complete CAB write!") ;
3308
            test_fail("bridge failed to post CAB Memory Write") ;
3309
            disable main ;
3310
        end
3311
 
3312
        write_flags`WB_TRANSFER_SIZE = 3 ;
3313
        wishbone_master.wb_block_write(write_flags, write_status) ;
3314
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3315
        begin
3316
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3317
            $display("Bridge failed to process complete CAB write!") ;
3318
            test_fail("bridge failed to post CAB Memory Write") ;
3319
            disable main ;
3320
        end
3321
    end
3322
    begin
3323
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3324
        if ( ok !== 1 )
3325
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3326
        else
3327
        begin
3328
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3329
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3330
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3331
            if ( ok !== 1 )
3332
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3333
            else
3334
                test_ok ;
3335
        end
3336
    end
3337
    join
3338
 
3339
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3340
    ok = 1 ;
3341
    // check statuses and data from error
3342
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3343
    if ( temp_val1[8] !== 1 )
3344
    begin
3345
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3346
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3347
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3348
        ok = 0 ;
3349
    end
3350
 
3351
    if ( temp_val1[9] !== 0 )
3352
    begin
3353
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3354
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3355
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3356
        ok = 0 ;
3357
    end
3358
 
3359
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3360
    begin
3361
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3362
        $display("Value in W_ERR_CS register was wrong!") ;
3363
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3364
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3365
        ok = 0 ;
3366
    end
3367
 
3368
    if ( ok )
3369
        test_ok ;
3370
 
3371
    // check erroneous address and data
3372
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3373
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3374
    ok = 1 ;
3375
    if ( temp_val1 !== (target_address + 8 + 4) )
3376
    begin
3377
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3378
        $display("Value in W_ERR_ADDR register was wrong!") ;
3379
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3380
        test_fail("Value in WB Erroneous Address register was wrong") ;
3381
        ok = 0 ;
3382
 
3383
    end
3384
 
3385
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3386
    if ( temp_val1 !== wmem_data[121] )
3387
    begin
3388
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3389
        $display("Value in W_ERR_DATA register was wrong!") ;
3390
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3391
        test_fail("Value in WB Erroneous Data register was wrong") ;
3392
        ok = 0 ;
3393
    end
3394
 
3395
    if ( ok )
3396
        test_ok ;
3397
 
3398
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3399
    `ifdef HOST
3400
        repeat(4)
3401
            @(posedge wb_clock) ;
3402
        if ( INT_O !== 1 )
3403
        begin
3404
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3405
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3406
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3407
        end
3408
        else
3409
            test_ok ;
3410
    `else
3411
    `ifdef GUEST
3412
        repeat(4)
3413
            @(posedge pci_clock) ;
3414
        if ( INTA !== 0 )
3415
        begin
3416
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3417
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3418
            test_fail("interrupt request was not presented on PCI bus") ;
3419
        end
3420
        else
3421
            test_ok ;
3422
    `endif
3423
    `endif
3424
 
3425
    // read interrupt status register
3426
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3427
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3428
    if ( temp_val1[1] !== 1 )
3429
    begin
3430
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3431
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3432
        test_fail("Expected Interrupt status bit wasn't set") ;
3433
    end
3434
 
3435
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3436
 
3437
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3438
    ok = 1 ;
3439
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3440
    if ( temp_val1[29] !== 0 )
3441
    begin
3442
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3443
        $display("Received Master Abort bit was set with no reason!") ;
3444
        test_fail("Received Master Abort bit was set with no reason") ;
3445
        ok = 0 ;
3446
    end
3447
 
3448
    if ( temp_val1[28] !== 1 )
3449
    begin
3450
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3451
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3452
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3453
        ok = 0 ;
3454
    end
3455
 
3456
    if ( ok )
3457
        test_ok ;
3458
 
3459
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3460
 
3461
    // clear interrupts and errors
3462
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3463
    repeat( 3 )
3464
        @(posedge pci_clock) ;
3465
 
3466
    repeat( 2 )
3467
        @(posedge wb_clock) ;
3468
 
3469
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3470
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3471
    if ( temp_val1[1] !== 0 )
3472
    begin
3473
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3474
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3475
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3476
    end
3477
    else
3478
        test_ok ;
3479
 
3480
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3481
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3482
    if ( temp_val1[8] !== 0 )
3483
    begin
3484
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3485
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3486
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3487
    end
3488
 
3489
 
3490
    $display("Introducing Target Abort error to single read!") ;
3491
    // set read data
3492
    read_data`READ_ADDRESS = target_address + 8 ;
3493
    read_data`READ_SEL     = 4'hF ;
3494
 
3495
    // enable automatic retry handling
3496
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3497
    write_flags`WB_TRANSFER_CAB    = 0 ;
3498
 
3499
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3500
 
3501
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3502
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3503
 
3504
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3505
 
3506
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3507
    begin
3508
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3509
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3510
        $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) ;
3511
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3512
        disable main ;
3513
    end
3514
    else
3515
        test_ok ;
3516
 
3517
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3518
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3519
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3520
    if ( temp_val1[8] !== 0 )
3521
    begin
3522
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3523
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3524
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3525
    end
3526
    else
3527
        test_ok ;
3528
 
3529
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3530
    ok = 1 ;
3531
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3532
    if ( temp_val1[29] !== 0 )
3533
    begin
3534
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3535
        $display("Received Master Abort bit was set with no reason!") ;
3536
        test_fail("Received Master Abort bit was set with no reason") ;
3537
        ok = 0 ;
3538
    end
3539
 
3540
    if ( temp_val1[28] !== 1 )
3541
    begin
3542
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3543
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3544
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3545
        ok = 0 ;
3546
    end
3547
 
3548
    if ( ok )
3549
        test_ok ;
3550
 
3551
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3552
 
3553
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3554
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3555
    if ( temp_val1[1] !== 0 )
3556
    begin
3557
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3558
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3559
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3560
    end
3561
    else
3562
        test_ok ;
3563
 
3564
    $display("Introducing Target Abort error to CAB read!") ;
3565
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3566
 
3567
    for ( i = 0 ; i < 4 ; i = i + 1 )
3568
    begin
3569
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3570
        read_data`READ_SEL     = 4'b1010 ;
3571
        wishbone_master.blk_read_data_in[i] = read_data ;
3572
    end
3573
 
3574
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3575
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3576
    write_flags`WB_TRANSFER_CAB    = 1 ;
3577
 
3578
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3579
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3580
 
3581
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3582
 
3583
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3584
    begin
3585
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3586
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3587
        $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) ;
3588
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3589
        disable main ;
3590
    end
3591
 
3592
    read_status = wishbone_master.blk_read_data_out[0] ;
3593
    temp_val1 = read_status`READ_DATA ;
3594
    temp_val2 = wmem_data[120] ;
3595
 
3596
    // last write to this address was with only two byte enables - check only those
3597
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3598
    begin
3599
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3600
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3601
    end
3602
    else
3603
        test_ok ;
3604
 
3605
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3606
    ok = 1 ;
3607
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3608
    if ( temp_val1[29] !== 0 )
3609
    begin
3610
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3611
        $display("Received Master Abort bit was set with no reason!") ;
3612
        test_fail("Received Master Abort bit was set with no reason") ;
3613
        ok = 0 ;
3614
    end
3615
 
3616
    if ( temp_val1[28] !== 1 )
3617
    begin
3618
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3619
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3620
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3621
        ok = 0 ;
3622
    end
3623
 
3624
    if ( ok )
3625
       test_ok ;
3626
 
3627
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3628
 
3629
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3630
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3631
 
3632
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3633
    for ( i = 0 ; i < 3 ; i = i + 1 )
3634
    begin
3635
        read_data`READ_ADDRESS = target_address + 4*i ;
3636
        read_data`READ_SEL     = 4'b1111 ;
3637
        wishbone_master.blk_read_data_in[i] = read_data ;
3638
    end
3639
 
3640
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3641
 
3642
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3643
 
3644
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3645
    begin
3646
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3647
        $display("Complete burst read through WB slave didn't succeed!") ;
3648
        test_fail("bridge didn't process Burst Read in an expected way") ;
3649
        disable main ;
3650
    end
3651
    else
3652
        test_ok ;
3653
 
3654
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3655
 
3656
    for ( i = 0 ; i < 3 ; i = i + 1 )
3657
    begin
3658
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3659
        read_data`READ_SEL     = 4'b1111 ;
3660
        wishbone_master.blk_read_data_in[i] = read_data ;
3661
    end
3662
 
3663
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3664
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3665
    write_flags`WB_TRANSFER_CAB    = 1 ;
3666
 
3667
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3668
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3669
 
3670
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3671
 
3672
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3673
    begin
3674
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3675
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3676
        $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) ;
3677
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3678
        disable main ;
3679
    end
3680
 
3681
    for ( i = 0 ; i < 3 ; i = i + 1 )
3682
    begin
3683
        ok = 1 ;
3684
        read_status = wishbone_master.blk_read_data_out[i] ;
3685
        temp_val1 = read_status`READ_DATA ;
3686
        temp_val2 = wmem_data[120 + i] ;
3687
 
3688
        // last write to this address was with only two byte enables - check only those
3689
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3690
        begin
3691
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3692
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3693
            ok = 0 ;
3694
        end
3695
    end
3696
 
3697
    if ( ok )
3698
        test_ok ;
3699
 
3700
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3701
    ok = 1 ;
3702
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3703
    if ( temp_val1[29] !== 0 )
3704
    begin
3705
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3706
        $display("Received Master Abort bit was set with no reason!") ;
3707
        test_fail("Received Master Abort bit was set with no reason") ;
3708
        ok = 0 ;
3709
    end
3710
 
3711
    if ( temp_val1[28] !== 1 )
3712
    begin
3713
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3714
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3715
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3716
        ok = 0 ;
3717
    end
3718
 
3719
    if ( ok )
3720
       test_ok ;
3721
 
3722
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3723
 
3724
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3725
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3726
 
3727
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3728
    for ( i = 0 ; i < 3 ; i = i + 1 )
3729
    begin
3730
        read_data`READ_ADDRESS = target_address + 4*i ;
3731
        read_data`READ_SEL     = 4'b1111 ;
3732
        wishbone_master.blk_read_data_in[i] = read_data ;
3733
    end
3734
 
3735
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3736
 
3737
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3738
 
3739
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3740
    begin
3741
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3742
        $display("Complete burst read through WB slave didn't succeed!") ;
3743
        test_fail("bridge didn't process Burst Read in an expected way") ;
3744
        disable main ;
3745
    end
3746
    else
3747
        test_ok ;
3748
 
3749
    // test error on IO write
3750
    // change base address
3751
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3752
    write_data`WRITE_SEL     = 4'b0101 ;
3753
    write_data`WRITE_ADDRESS = target_address ;
3754
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3755
 
3756
    write_flags`WB_TRANSFER_CAB    = 0 ;
3757
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3758
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3759
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3760
    fork
3761
    begin
3762
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3763
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3764
        begin
3765
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3766
            $display("WB slave failed to accept IO write!") ;
3767
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3768
            disable main ;
3769
        end
3770
    end
3771
    begin
3772
        musnt_respond(ok) ;
3773
        if ( ok !== 1 )
3774
        begin
3775
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3776
            $display("Testbench is configured wrong!") ;
3777
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3778
        end
3779
        else
3780
            test_ok ;
3781
    end
3782
    join
3783
 
3784
    // check statuses and everything else
3785
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3786
    ok = 1 ;
3787
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3788
    if ( temp_val1[8] !== 1 )
3789
    begin
3790
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3791
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3792
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3793
        ok = 0 ;
3794
    end
3795
 
3796
    if ( temp_val1[9] !== 1 )
3797
    begin
3798
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3799
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3800
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3801
        ok = 0 ;
3802
    end
3803
 
3804
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3805
    begin
3806
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3807
        $display("Value in W_ERR_CS register was wrong!") ;
3808
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3809
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3810
        ok = 0 ;
3811
    end
3812
 
3813
    if ( ok )
3814
        test_ok ;
3815
 
3816
    // check erroneous address and data
3817
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3818
    ok = 1 ;
3819
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3820
    if ( temp_val1 !== target_address )
3821
    begin
3822
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3823
        $display("Value in W_ERR_ADDR register was wrong!") ;
3824
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3825
        test_fail("WB Erroneous Address register didn't provide right value") ;
3826
        ok = 0 ;
3827
    end
3828
 
3829
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3830
    if ( temp_val1 !== 32'hAAAA_AAAA )
3831
    begin
3832
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3833
        $display("Value in W_ERR_DATA register was wrong!") ;
3834
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3835
        test_fail("WB Erroneous Data register didn't provide right value") ;
3836
        ok = 0 ;
3837
    end
3838
 
3839
    if ( ok )
3840
        test_ok ;
3841
 
3842
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3843
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3844
    if ( temp_val1[1] !== 1 )
3845
    begin
3846
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3847
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3848
        test_fail("expected interrupt status bit was not set") ;
3849
    end
3850
    else
3851
        test_ok ;
3852
 
3853
    // clear interrupts and errors
3854
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3855
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3856
 
3857
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3858
    ok = 1 ;
3859
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3860
    if ( temp_val1[29] !== 1 )
3861
    begin
3862
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3863
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3864
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3865
        ok = 0 ;
3866
    end
3867
 
3868
    if ( temp_val1[28] !== 0 )
3869
    begin
3870
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3871
        $display("Received Target Abort bit was set for no reason!") ;
3872
        test_fail("Received Target Abort bit was set for no reason") ;
3873
        ok = 0 ;
3874
    end
3875
 
3876
    if ( ok )
3877
        test_ok ;
3878
 
3879
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3880
 
3881
    // disable image
3882
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3883
    if ( ok !== 1 )
3884
    begin
3885
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3886
        test_fail("WB Image Address Mask register couldn't be written") ;
3887
        disable main ;
3888
    end
3889
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3890
 
3891
end
3892
endtask
3893
 
3894
task parity_checking ;
3895
    reg   [11:0] ctrl_offset ;
3896
    reg   [11:0] ba_offset ;
3897
    reg   [11:0] am_offset ;
3898
    reg   [11:0] ta_offset ;
3899
    reg `WRITE_STIM_TYPE write_data ;
3900
    reg `READ_STIM_TYPE  read_data ;
3901
    reg `READ_RETURN_TYPE read_status ;
3902
 
3903
    reg `WRITE_RETURN_TYPE write_status ;
3904
    reg `WB_TRANSFER_FLAGS write_flags ;
3905
    reg [31:0] temp_val1 ;
3906
    reg [31:0] temp_val2 ;
3907
    reg        ok   ;
3908
    reg [11:0] pci_ctrl_offset ;
3909
    reg [31:0] image_base ;
3910
    reg [31:0] target_address ;
3911
    reg [11:0] icr_offset ;
3912
    reg [11:0] isr_offset ;
3913
    reg [11:0] p_ba_offset ;
3914
    reg [11:0] p_am_offset ;
3915
    reg [11:0] p_ctrl_offset ;
3916
    integer    i ;
3917
    reg        perr_asserted ;
3918
begin:main
3919
    $display("******************************* Testing Parity Checker functions ********************************") ;
3920
    $display("Testing Parity Errors during Master Transactions!") ;
3921
    $display("Introducing Parity Erros to Master Writes!") ;
3922
    $fdisplay(pci_mon_log_file_desc,
3923
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
3924
 
3925
    // image 1 is used for error testing, since it is always implemented
3926
    pci_ctrl_offset = 12'h004 ;
3927
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
3928
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
3929
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
3930
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
3931
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
3932
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
3933
 
3934
    // image 1 for PCI target
3935
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
3936
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
3937
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
3938
 
3939
    target_address  = `BEH_TAR1_MEM_START ;
3940
    image_base      = 0 ;
3941
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
3942
 
3943
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
3944
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
3945
    write_flags                    = 0 ;
3946
    write_flags`INIT_WAITS         = tb_init_waits ;
3947
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
3948
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3949
 
3950
    // enable master & target operation and disable parity functions
3951
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
3952
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
3953
    if ( ok !== 1 )
3954
    begin
3955
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
3956
        test_fail("PCI Device Control register could not be written to") ;
3957
        disable main ;
3958
    end
3959
 
3960
    // prepare image control register
3961
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
3962
    if ( ok !== 1 )
3963
    begin
3964
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
3965
        test_fail("WB Image Control register could not be written to") ;
3966
        disable main ;
3967
    end
3968
 
3969
    // prepare base address register
3970
    config_write( ba_offset, image_base, 4'hF, ok ) ;
3971
    if ( ok !== 1 )
3972
    begin
3973
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
3974
        test_fail("WB Image Base Address register could not be written to") ;
3975
        disable main ;
3976
    end
3977
 
3978
    // write address mask register
3979
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
3980
    if ( ok !== 1 )
3981
    begin
3982
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3983
        test_fail("WB Image Address Mask register could not be written to") ;
3984
        disable main ;
3985
    end
3986
 
3987
    // disable parity interrupts
3988
    config_write( icr_offset, 0, 4'hF, ok ) ;
3989
    if ( ok !== 1 )
3990
    begin
3991
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
3992
        test_fail("Interrupt Control register could not be written to") ;
3993
        disable main ;
3994
    end
3995
 
3996
    write_data`WRITE_ADDRESS = target_address ;
3997
    write_data`WRITE_DATA    = wmem_data[0] ;
3998
    write_data`WRITE_SEL     = 4'b1111 ;
3999
 
4000
    // enable target's 1 response to parity errors
4001
    configuration_cycle_write(0,             // bus number
4002
                              1,             // device number
4003
                              0,             // function number
4004
                              1,             // register number
4005
                              0,             // type of configuration cycle
4006
                              4'b0001,       // byte enables
4007
                              32'h0000_0047  // data
4008
                             ) ;
4009
 
4010
    // disable target's 2 response to parity errors
4011
    configuration_cycle_write(0,             // bus number
4012
                              2,             // device number
4013
                              0,             // function number
4014
                              1,             // register number
4015
                              0,             // type of configuration cycle
4016
                              4'b0001,       // byte enables
4017
                              32'h0000_0007  // data
4018
                             ) ;
4019
 
4020
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4021
 
4022
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4023
    fork
4024
    begin
4025
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4026
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4027
        begin
4028
            $display("Parity checker testing failed! Time %t ", $time) ;
4029
            $display("Bridge failed to process single memory write!") ;
4030
            test_fail("bridge failed to post single WB memory write") ;
4031
            disable main ;
4032
        end
4033
    end
4034
    begin:wait_perr1
4035
        perr_asserted = 0 ;
4036
        @(posedge pci_clock) ;
4037
 
4038
        while ( PERR === 1 )
4039
            @(posedge pci_clock) ;
4040
 
4041
        if ( PERR === 0 )
4042
            perr_asserted = 1 ;
4043
 
4044
    end
4045
    begin
4046
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4047
 
4048
        if ( ok !== 1 )
4049
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4050
 
4051
        repeat(3)
4052
            @(posedge pci_clock) ;
4053
 
4054
        disable wait_perr1 ;
4055
    end
4056
    join
4057
 
4058
    if ( perr_asserted && ok )
4059
    begin
4060
        test_ok ;
4061
    end
4062
    else
4063
    if ( ~perr_asserted )
4064
    begin
4065
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4066
        disable main ;
4067
    end
4068
 
4069
    // check all the statuses - if HOST is defined, wait for them to be synced
4070
    `ifdef HOST
4071
    repeat(4)
4072
        @(posedge wb_clock) ;
4073
    `endif
4074
 
4075
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4076
    ok = 1 ;
4077
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4078
    if ( temp_val1[31] !== 1 )
4079
    begin
4080
        $display("Parity checker testing failed! Time %t ", $time) ;
4081
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4082
        test_fail("Detected Parity Error bit was not set after Write Master Data Parity Error") ;
4083
        ok = 0 ;
4084
    end
4085
 
4086
    if ( temp_val1[30] !== 0 )
4087
    begin
4088
        $display("Parity checker testing failed! Time %t ", $time) ;
4089
        $display("Signalled System Error bit was set for no reason!") ;
4090
        test_fail("Signalled System Error bit was set for no reason") ;
4091
        ok = 0 ;
4092
    end
4093
 
4094
    if ( temp_val1[24] !== 0 )
4095
    begin
4096
        $display("Parity checker testing failed! Time %t ", $time) ;
4097
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4098
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4099
        ok = 0 ;
4100
    end
4101
 
4102
    if ( ok )
4103
        test_ok ;
4104
 
4105
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4106
    // clear parity bits and enable parity response
4107
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4108
    if ( ok !== 1 )
4109
    begin
4110
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4111
        test_fail("write to PCI Status Register failed") ;
4112
        disable main ;
4113
    end
4114
 
4115
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4116
    fork
4117
    begin
4118
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4119
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4120
        begin
4121
            $display("Parity checker testing failed! Time %t ", $time) ;
4122
            $display("Bridge failed to process single memory write!") ;
4123
            test_fail("bridge failed to post single memory write") ;
4124
            disable main ;
4125
        end
4126
    end
4127
    begin:wait_perr2
4128
        perr_asserted = 0 ;
4129
        @(posedge pci_clock) ;
4130
 
4131
        while ( PERR === 1 )
4132
            @(posedge pci_clock) ;
4133
 
4134
        if ( PERR === 0 )
4135
            perr_asserted = 1 ;
4136
 
4137
    end
4138
    begin
4139
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4140
 
4141
        if ( ok !== 1 )
4142
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4143
 
4144
        repeat(3)
4145
            @(posedge pci_clock) ;
4146
 
4147
        disable wait_perr2 ;
4148
    end
4149
    join
4150
 
4151
    if ( perr_asserted && ok )
4152
    begin
4153
        test_ok ;
4154
    end
4155
    else
4156
    if ( ~perr_asserted )
4157
    begin
4158
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4159
        disable main ;
4160
    end
4161
 
4162
    // check all the statuses - if HOST is defined, wait for them to be synced
4163
    `ifdef HOST
4164
    repeat(4)
4165
        @(posedge wb_clock) ;
4166
    `endif
4167
 
4168
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4169
    ok = 1 ;
4170
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4171
    if ( temp_val1[31] !== 1 )
4172
    begin
4173
        $display("Parity checker testing failed! Time %t ", $time) ;
4174
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4175
        test_fail("Detected Parity Error bit was not set after parity error on PCI bus") ;
4176
        ok = 0 ;
4177
    end
4178
 
4179
    if ( temp_val1[30] !== 0 )
4180
    begin
4181
        $display("Parity checker testing failed! Time %t ", $time) ;
4182
        $display("Signalled System Error bit was set for no reason!") ;
4183
        test_fail("Signalled System Error bit was set for no reason") ;
4184
        ok = 0 ;
4185
    end
4186
 
4187
    if ( temp_val1[24] !== 1 )
4188
    begin
4189
        $display("Parity checker testing failed! Time %t ", $time) ;
4190
        $display("Master Data Parity Error bit wasn't set even though Parity Error Response bit was set!") ;
4191
        test_fail("Master Data Parity Error bit wasn't set after Parity Error on PCI bus, even though Parity Error Response bit was set") ;
4192
        ok = 0 ;
4193
    end
4194
 
4195
    if ( ok )
4196
        test_ok ;
4197
 
4198
    // clear status bits and disable parity error response
4199
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4200
 
4201
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4202
 
4203
    // disable perr generation and perform a write - no bits should be set
4204
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4205
    fork
4206
    begin
4207
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4208
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4209
        begin
4210
            $display("Parity checker testing failed! Time %t ", $time) ;
4211
            $display("Bridge failed to process single memory write!") ;
4212
            test_fail("bridge failed to post single memory write") ;
4213
            disable main ;
4214
        end
4215
    end
4216
    begin
4217
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4218
 
4219
        if ( ok !== 1 )
4220
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4221
        else
4222
            test_ok ;
4223
 
4224
        repeat(3)
4225
            @(posedge pci_clock) ;
4226
    end
4227
    join
4228
 
4229
    `ifdef HOST
4230
    repeat(4)
4231
        @(posedge wb_clock) ;
4232
    `endif
4233
 
4234
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4235
    ok = 1 ;
4236
 
4237
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4238
    if ( temp_val1[31] !== 0 )
4239
    begin
4240
        $display("Parity checker testing failed! Time %t ", $time) ;
4241
        $display("Detected Parity Error bit was set for no reason!") ;
4242
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4243
        ok = 0 ;
4244
    end
4245
 
4246
    if ( temp_val1[30] !== 0 )
4247
    begin
4248
        $display("Parity checker testing failed! Time %t ", $time) ;
4249
        $display("Signalled System Error bit was set for no reason!") ;
4250
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4251
        ok = 0 ;
4252
    end
4253
 
4254
    if ( temp_val1[24] !== 0 )
4255
    begin
4256
        $display("Parity checker testing failed! Time %t ", $time) ;
4257
        $display("Master Data Parity Error bit was set for no reason!") ;
4258
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4259
        ok = 0 ;
4260
    end
4261
 
4262
    if ( ok )
4263
        test_ok ;
4264
 
4265
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4266
 
4267
    read_data = 0 ;
4268
    read_data`READ_ADDRESS  = target_address ;
4269
    read_data`READ_SEL      = 4'hF ;
4270
    read_data`READ_TAG_STIM = 0 ;
4271
 
4272
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4273
 
4274
    // enable parity and system error interrupts
4275
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4276
 
4277
    // enable parity error response
4278
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4279
 
4280
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4281
 
4282
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4283
    fork
4284
    begin
4285
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4286
    end
4287
    begin:wait_perr4
4288
        perr_asserted = 0 ;
4289
        @(posedge pci_clock) ;
4290
        while ( PERR === 1 )
4291
            @(posedge pci_clock) ;
4292
 
4293
        if ( PERR === 0 )
4294
            perr_asserted = 1 ;
4295
 
4296
    end
4297
    begin
4298
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4299
 
4300
        if ( ok !== 1 )
4301
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4302
 
4303
        repeat(2)
4304
            @(posedge pci_clock) ;
4305
 
4306
        disable wait_perr4 ;
4307
    end
4308
    join
4309
 
4310
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4311
    begin
4312
        $display("Parity checker testing failed! Time %t ", $time) ;
4313
        $display("Bridge failed to process single memory read!") ;
4314
        test_fail("bridge didn't process single memory read correctly") ;
4315
        ok = 0 ;
4316
    end
4317
 
4318
    if ( perr_asserted && ok )
4319
    begin
4320
        test_ok ;
4321
    end
4322
    else
4323
    if ( ~perr_asserted )
4324
    begin
4325
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4326
        disable main ;
4327
    end
4328
 
4329
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4330
    // interrupt should also be present
4331
    `ifdef HOST
4332
        repeat(4)
4333 26 mihad
            @(posedge pci_clock) ;
4334
        repeat(4)
4335 15 mihad
            @(posedge wb_clock) ;
4336
 
4337
        if ( INT_O !== 1 )
4338
        begin
4339
            $display("Parity checker testing failed! Time %t ", $time) ;
4340
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4341
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4342
        end
4343
        else
4344
            test_ok ;
4345
    `else
4346
    `ifdef GUEST
4347 26 mihad
        repeat(4)
4348
            @(posedge wb_clock) ;
4349
        repeat(4)
4350 15 mihad
            @(posedge pci_clock) ;
4351
 
4352
        if ( INTA !== 1 )
4353
        begin
4354
            $display("Parity checker testing failed! Time %t ", $time) ;
4355
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4356
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4357
        end
4358
        else
4359
            test_ok ;
4360
    `endif
4361
    `endif
4362
 
4363
    // check statuses!
4364
 
4365
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4366
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4367
    ok = 1 ;
4368
 
4369
    if ( temp_val1[31] !== 1 )
4370
    begin
4371
        $display("Parity checker testing failed! Time %t ", $time) ;
4372
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4373
        test_fail("Detected Parity Error bit was not set when parity error was presented on Read transaction") ;
4374
        ok = 0 ;
4375
    end
4376
 
4377
    if ( temp_val1[30] !== 0 )
4378
    begin
4379
        $display("Parity checker testing failed! Time %t ", $time) ;
4380
        $display("Signalled System Error bit was set for no reason!") ;
4381
        test_fail("Signalled System Error bit was set for no reason") ;
4382
        ok = 0 ;
4383
    end
4384
 
4385
    if ( temp_val1[24] !== 1 )
4386
    begin
4387
        $display("Parity checker testing failed! Time %t ", $time) ;
4388
        $display("Master Data Parity Error bit was not set when parity error was presented during read transaction!") ;
4389
        test_fail("Master Data Parity Error bit was not set when parity error was presented during read transaction and Parity Error Response was enabled") ;
4390
        ok = 0 ;
4391
    end
4392
 
4393
    if ( ok )
4394
        test_ok ;
4395
 
4396
    // clear statuses and disable parity error response
4397
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4398
 
4399
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4400
    ok = 1 ;
4401
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4402
 
4403
    if ( temp_val1[4] !== 0 )
4404
    begin
4405
        $display("Parity checker testing failed! Time %t ", $time) ;
4406
        $display("System error interrupt status bit set for no reason!") ;
4407
        test_fail("System error interrupt status bit set for no reason") ;
4408
        ok = 0 ;
4409
    end
4410
 
4411
    `ifdef HOST
4412
    if ( temp_val1[3] !== 1 )
4413
    begin
4414
        $display("Parity checker testing failed! Time %t ", $time) ;
4415
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4416
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4417
        ok = 0 ;
4418
    end
4419
    `else
4420
    if ( temp_val1[3] !== 0 )
4421
    begin
4422
        $display("Parity checker testing failed! Time %t ", $time) ;
4423
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4424
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4425
        ok = 0 ;
4426
    end
4427
    `endif
4428
 
4429
    if ( ok )
4430
        test_ok ;
4431
 
4432
    // clear int statuses
4433
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4434
 
4435
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4436
 
4437
    `ifdef HOST
4438
        repeat(4)
4439 26 mihad
            @(posedge pci_clock) ;
4440
        repeat(4)
4441 15 mihad
            @(posedge wb_clock) ;
4442
 
4443
        if ( INT_O !== 0 )
4444
        begin
4445
            $display("Parity checker testing failed! Time %t ", $time) ;
4446
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4447
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4448
        end
4449
        else
4450
            test_ok ;
4451
    `else
4452
    `ifdef GUEST
4453 26 mihad
        repeat(4)
4454
            @(posedge wb_clock) ;
4455
        repeat(4)
4456 15 mihad
            @(posedge pci_clock) ;
4457
 
4458
        if ( INTA !== 1 )
4459
        begin
4460
            $display("Parity checker testing failed! Time %t ", $time) ;
4461
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4462
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4463
        end
4464
        else
4465
            test_ok ;
4466
    `endif
4467
    `endif
4468
 
4469
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4470
 
4471
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4472
    fork
4473
    begin
4474
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4475
    end
4476
    begin:wait_perr5
4477
        perr_asserted = 0 ;
4478
        @(posedge pci_clock) ;
4479
        while ( PERR === 1 )
4480
            @(posedge pci_clock) ;
4481
 
4482
        perr_asserted = 1 ;
4483
        $display("Parity checker testing failed! Time %t ", $time) ;
4484
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4485
        test_fail("Bridge asserted PERR during read transaction when Parity Error response was disabled") ;
4486
    end
4487
    begin
4488
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4489
        if ( ok !== 1 )
4490
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4491
 
4492
        // perr can be asserted on idle or next PCI address phase
4493
        repeat(2)
4494
            @(posedge pci_clock) ;
4495
 
4496
        disable wait_perr5 ;
4497
    end
4498
    join
4499
 
4500
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4501
    begin
4502
        $display("Parity checker testing failed! Time %t ", $time) ;
4503
        $display("Bridge failed to process single memory read!") ;
4504
        test_fail("bridge failed to process single memory read correctly") ;
4505
        ok = 0 ;
4506
    end
4507
 
4508
    if ( ok && !perr_asserted)
4509
        test_ok ;
4510
 
4511
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4512
 
4513
    // interrupts should not be present
4514
    `ifdef HOST
4515
        repeat( 4 )
4516 26 mihad
            @(posedge pci_clock) ;
4517
        repeat( 4 )
4518 15 mihad
            @(posedge wb_clock) ;
4519
        if ( INT_O !== 0 )
4520
        begin
4521
            $display("Parity checker testing failed! Time %t ", $time) ;
4522
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4523
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4524
        end
4525
        else
4526
            test_ok ;
4527
    `else
4528
    `ifdef GUEST
4529
        repeat( 4 )
4530 26 mihad
            @(posedge wb_clock) ;
4531
        repeat( 4 )
4532 15 mihad
            @(posedge pci_clock) ;
4533
        if ( INTA !== 1 )
4534
        begin
4535
            $display("Parity checker testing failed! Time %t ", $time) ;
4536
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4537
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4538
        end
4539
        else
4540
            test_ok ;
4541
    `endif
4542
    `endif
4543
 
4544
    // check statuses!
4545
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4546
    ok = 1 ;
4547
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4548
    if ( temp_val1[31] !== 1 )
4549
    begin
4550
        $display("Parity checker testing failed! Time %t ", $time) ;
4551
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4552
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4553
        ok = 0 ;
4554
    end
4555
 
4556
    if ( temp_val1[30] !== 0 )
4557
    begin
4558
        $display("Parity checker testing failed! Time %t ", $time) ;
4559
        $display("Signalled System Error bit was set for no reason!") ;
4560
        test_fail("Signalled System Error bit was set for no reason") ;
4561
        ok = 0 ;
4562
    end
4563
 
4564
    if ( temp_val1[24] !== 0 )
4565
    begin
4566
        $display("Parity checker testing failed! Time %t ", $time) ;
4567
        $display("Master Data Parity Error bit was set when parity error was presented during read transaction, but Parity Response was disabled!") ;
4568
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4569
        ok = 0 ;
4570
    end
4571
 
4572
    if ( ok )
4573
        test_ok ;
4574
 
4575
    // clear statuses
4576
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4577
 
4578
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4579
    ok = 1 ;
4580
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4581
 
4582
    if ( temp_val1[4] !== 0 )
4583
    begin
4584
        $display("Parity checker testing failed! Time %t ", $time) ;
4585
        $display("System error interrupt status bit set for no reason!") ;
4586
        test_fail("System error interrupt status bit set for no reason") ;
4587
        ok = 0 ;
4588
    end
4589
 
4590
    if ( temp_val1[3] !== 0 )
4591
    begin
4592
        $display("Parity checker testing failed! Time %t ", $time) ;
4593
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4594
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4595
        ok = 0 ;
4596
    end
4597
 
4598
    if ( ok )
4599
        test_ok ;
4600
 
4601
    // enable all responses to parity errors!
4602
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4603
 
4604
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4605
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4606
 
4607
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4608
 
4609
    // repeat a read
4610
    fork
4611
    begin
4612
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4613
    end
4614
    begin:wait_perr6
4615
        perr_asserted = 0 ;
4616
        @(posedge pci_clock) ;
4617
        while ( PERR === 1 )
4618
            @(posedge pci_clock) ;
4619
 
4620
        perr_asserted = 1 ;
4621
        $display("Parity checker testing failed! Time %t ", $time) ;
4622
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4623
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4624
    end
4625
    begin
4626
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4627
        if ( ok !== 1 )
4628
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4629
 
4630
        repeat(2)
4631
            @(posedge pci_clock) ;
4632
 
4633
        disable wait_perr6 ;
4634
    end
4635
    join
4636
 
4637
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4638
    begin
4639
        $display("Parity checker testing failed! Time %t ", $time) ;
4640
        $display("Bridge failed to process single memory read!") ;
4641
        test_fail("bridge didn't process single memory read as expected") ;
4642
        ok = 0 ;
4643
    end
4644
 
4645
    if ( ok && !perr_asserted)
4646
        test_ok ;
4647
 
4648
    // check statuses!
4649
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4650
    ok = 1 ;
4651
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4652
    if ( temp_val1[31] !== 0 )
4653
    begin
4654
        $display("Parity checker testing failed! Time %t ", $time) ;
4655
        $display("Detected Parity Error bit was set for no reason!") ;
4656
        test_fail("Detected Parity Error bit was set for no reason") ;
4657
        ok = 0 ;
4658
    end
4659
 
4660
    if ( temp_val1[30] !== 0 )
4661
    begin
4662
        $display("Parity checker testing failed! Time %t ", $time) ;
4663
        $display("Signalled System Error bit was set for no reason!") ;
4664
        test_fail("Signalled System Error bit was set for no reason") ;
4665
        ok = 0 ;
4666
    end
4667
 
4668
    if ( temp_val1[24] !== 0 )
4669
    begin
4670
        $display("Parity checker testing failed! Time %t ", $time) ;
4671
        $display("Master Data Parity Error bit was set for no reason!") ;
4672
        test_fail("Master Data Parity Error bit was set for no reason") ;
4673
        ok = 0 ;
4674
    end
4675
 
4676
    if ( ok )
4677
        test_ok ;
4678
 
4679
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4680
    ok = 1 ;
4681
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4682
 
4683
    if ( temp_val1[4] !== 0 )
4684
    begin
4685
        $display("Parity checker testing failed! Time %t ", $time) ;
4686
        $display("System error interrupt status bit set for no reason!") ;
4687
        test_fail("System error interrupt status bit set for no reason") ;
4688
        ok = 0 ;
4689
    end
4690
 
4691
    if ( temp_val1[3] !== 0 )
4692
    begin
4693
        $display("Parity checker testing failed! Time %t ", $time) ;
4694
        $display("Parity error interrupt status bit set for no reason!") ;
4695
        test_fail("Parity error interrupt status bit set for no reason") ;
4696
        ok = 0 ;
4697
    end
4698
 
4699
    if ( ok )
4700
        test_ok ;
4701
 
4702
    $display("Presenting address parity error on PCI bus!") ;
4703
    // enable parity errors - this should not affect system errors
4704
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4705
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4706
 
4707
    // perform PCI write
4708
    // check transaction progress
4709
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4710
    fork
4711
    begin
4712
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4713
               target_address, 32'h1234_5678,
4714
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4715
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4716
        do_pause( 1 ) ;
4717
    end
4718
    begin:wait_serr7
4719
        perr_asserted = 0 ;
4720
        @(posedge pci_clock) ;
4721
        while( SERR === 1 )
4722
            @(posedge pci_clock) ;
4723
 
4724
        perr_asserted = 1 ;
4725
        $display("Parity checker testing failed! Time %t ", $time) ;
4726
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4727
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4728
    end
4729
    begin
4730
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4731
        if ( ok !== 1 )
4732
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4733
 
4734
        disable wait_serr7 ;
4735
    end
4736
    join
4737
 
4738
    if ( ok && !perr_asserted)
4739
        test_ok ;
4740
 
4741
    // check statuses!
4742
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4743
    ok = 1 ;
4744
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4745
    if ( temp_val1[31] !== 1 )
4746
    begin
4747
        $display("Parity checker testing failed! Time %t ", $time) ;
4748
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4749
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4750
        ok = 0 ;
4751
    end
4752
 
4753
    if ( temp_val1[30] !== 0 )
4754
    begin
4755
        $display("Parity checker testing failed! Time %t ", $time) ;
4756
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4757
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4758
        ok = 0 ;
4759
    end
4760
 
4761
    if ( temp_val1[24] !== 0 )
4762
    begin
4763
        $display("Parity checker testing failed! Time %t ", $time) ;
4764
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4765
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4766
        ok = 0 ;
4767
    end
4768
 
4769
    if ( ok )
4770
        test_ok ;
4771
 
4772
    // clear statuses
4773
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4774
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4775
    fork
4776
    begin
4777
        ipci_unsupported_commands_master.master_reference
4778
        (
4779
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4780
            32'h5555_5555,      // second part of address in dual address cycle
4781
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4782
            `BC_MEM_WRITE,      // normal command
4783
            4'h0,               // byte enables
4784
            32'h1234_5678,      // data
4785
            1'b1,               // make address parity error on first phase of dual address
4786
            1'b0,               // make address parity error on second phase of dual address
4787
            ok                  // result of operation
4788
        ) ;
4789
        disable wait_serr8 ;
4790
    end
4791
    begin:wait_serr8
4792
        perr_asserted = 0 ;
4793
        @(posedge pci_clock) ;
4794
        while( SERR === 1 )
4795
            @(posedge pci_clock) ;
4796
 
4797
        perr_asserted = 1 ;
4798
        $display("Parity checker testing failed! Time %t ", $time) ;
4799
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4800
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4801
    end
4802
    join
4803
 
4804
    if ( ok && !perr_asserted)
4805
        test_ok ;
4806
 
4807
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4808
    fork
4809
    begin
4810
        ipci_unsupported_commands_master.master_reference
4811
        (
4812
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4813
            32'h5555_5555,      // second part of address in dual address cycle
4814
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4815
            `BC_MEM_WRITE,      // normal command
4816
            4'h0,               // byte enables
4817
            32'h1234_5678,      // data
4818
            1'b0,               // make address parity error on first phase of dual address
4819
            1'b1,               // make address parity error on second phase of dual address
4820
            ok                  // result of operation
4821
        ) ;
4822
        disable wait_serr9 ;
4823
    end
4824
    begin:wait_serr9
4825
        perr_asserted = 0 ;
4826
        @(posedge pci_clock) ;
4827
        while( SERR === 1 )
4828
            @(posedge pci_clock) ;
4829
 
4830
        perr_asserted = 1 ;
4831
        $display("Parity checker testing failed! Time %t ", $time) ;
4832
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4833
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4834
    end
4835
    join
4836
 
4837
    if ( ok && !perr_asserted)
4838
        test_ok ;
4839
 
4840
    // check statuses!
4841
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4842
    ok = 1 ;
4843
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4844
    if ( temp_val1[31] !== 1 )
4845
    begin
4846
        $display("Parity checker testing failed! Time %t ", $time) ;
4847
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4848
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4849
        ok = 0 ;
4850
    end
4851
 
4852
    if ( temp_val1[30] !== 0 )
4853
    begin
4854
        $display("Parity checker testing failed! Time %t ", $time) ;
4855
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4856
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4857
        ok = 0 ;
4858
    end
4859
 
4860
    if ( temp_val1[24] !== 0 )
4861
    begin
4862
        $display("Parity checker testing failed! Time %t ", $time) ;
4863
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4864
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4865
        ok = 0 ;
4866
    end
4867
 
4868
    if ( ok )
4869
        test_ok ;
4870
 
4871
    // clear statuses
4872
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4873
 
4874
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4875
    fork
4876
    begin
4877
        ipci_unsupported_commands_master.master_reference
4878
        (
4879
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4880
            32'h5555_5555,      // second part of address in dual address cycle
4881
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4882
            `BC_MEM_WRITE,      // normal command
4883
            4'h0,               // byte enables
4884
            32'h1234_5678,      // data
4885
            1'b1,               // make address parity error on first phase of dual address
4886
            1'b1,               // make address parity error on second phase of dual address
4887
            ok                  // result of operation
4888
        ) ;
4889
        disable wait_serr10 ;
4890
    end
4891
    begin:wait_serr10
4892
        perr_asserted = 0 ;
4893
        @(posedge pci_clock) ;
4894
        while( SERR === 1 )
4895
            @(posedge pci_clock) ;
4896
 
4897
        perr_asserted = 1 ;
4898
        $display("Parity checker testing failed! Time %t ", $time) ;
4899
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4900
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4901
    end
4902
    join
4903
 
4904
    if ( ok && !perr_asserted)
4905
        test_ok ;
4906
 
4907
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
4908
 
4909
    `ifdef HOST
4910
        repeat(4)
4911 26 mihad
            @(posedge pci_clock) ;
4912
        repeat(4)
4913 15 mihad
            @(posedge wb_clock) ;
4914
        if ( INT_O !== 0 )
4915
        begin
4916
            $display("Parity checker testing failed! Time %t ", $time) ;
4917
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
4918
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
4919
        end
4920
        else
4921
            test_ok ;
4922
    `else
4923
    `ifdef GUEST
4924 26 mihad
        repeat(4)
4925
            @(posedge wb_clock) ;
4926
        repeat(4)
4927 15 mihad
            @(posedge pci_clock) ;
4928
 
4929
        if ( INTA !== 1 )
4930
        begin
4931
            $display("Parity checker testing failed! Time %t ", $time) ;
4932
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
4933
            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") ;
4934
        end
4935
        else
4936
            test_ok ;
4937
    `endif
4938
    `endif
4939
 
4940
    // check statuses!
4941
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4942
    ok = 1 ;
4943
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4944
    if ( temp_val1[31] !== 1 )
4945
    begin
4946
        $display("Parity checker testing failed! Time %t ", $time) ;
4947
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4948
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4949
        ok = 0 ;
4950
    end
4951
 
4952
    if ( temp_val1[30] !== 0 )
4953
    begin
4954
        $display("Parity checker testing failed! Time %t ", $time) ;
4955
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4956
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4957
        ok = 0 ;
4958
    end
4959
 
4960
    if ( temp_val1[24] !== 0 )
4961
    begin
4962
        $display("Parity checker testing failed! Time %t ", $time) ;
4963
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4964
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4965
        ok = 0 ;
4966
    end
4967
 
4968
    if ( ok )
4969
        test_ok ;
4970
 
4971
    // clear statuses
4972
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4973
 
4974
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4975
    ok = 1 ;
4976
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4977
 
4978
    if ( temp_val1[4] !== 0 )
4979
    begin
4980
        $display("Parity checker testing failed! Time %t ", $time) ;
4981
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
4982
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
4983
        ok = 0 ;
4984
    end
4985
 
4986
    if ( temp_val1[3] !== 0 )
4987
    begin
4988
        $display("Parity checker testing failed! Time %t ", $time) ;
4989
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
4990
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
4991
        ok = 0 ;
4992
    end
4993
 
4994
    if ( ok )
4995
        test_ok ;
4996
 
4997
    // now enable system error signaling and test response
4998
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
4999
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5000
 
5001
    fork
5002
    begin
5003
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5004
               target_address, 32'h1234_5678,
5005
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5006
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5007
        do_pause( 1 ) ;
5008
    end
5009
    begin:wait_serr11
5010
        perr_asserted = 0 ;
5011
        @(posedge pci_clock) ;
5012
        while( SERR === 1 )
5013
            @(posedge pci_clock) ;
5014
 
5015
        if ( SERR === 0 )
5016
            perr_asserted = 1 ;
5017
    end
5018
    begin
5019
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5020
        if ( ok !== 1 )
5021
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5022
 
5023
        @(posedge pci_clock) ;
5024
        #2 ;
5025
        disable wait_serr11 ;
5026
    end
5027
    join
5028
 
5029
    if ( ok && perr_asserted)
5030
        test_ok ;
5031
    else
5032
    if ( !perr_asserted )
5033
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5034
 
5035
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5036
 
5037
    `ifdef HOST
5038
        repeat(4)
5039 26 mihad
            @(posedge pci_clock) ;
5040
        repeat(4)
5041 15 mihad
            @(posedge wb_clock) ;
5042
        if ( INT_O !== 1 )
5043
        begin
5044
            $display("Parity checker testing failed! Time %t ", $time) ;
5045
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5046
            test_fail("Interrupt Request was not triggered as expected") ;
5047
        end
5048
        else
5049
            test_ok ;
5050
    `else
5051
    `ifdef GUEST
5052 26 mihad
        repeat(4)
5053
            @(posedge wb_clock) ;
5054
        repeat(4)
5055 15 mihad
            @(posedge pci_clock) ;
5056
 
5057
        if ( INTA !== 1 )
5058
        begin
5059
            $display("Parity checker testing failed! Time %t ", $time) ;
5060
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5061
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5062
        end
5063
        else
5064
            test_ok ;
5065
    `endif
5066
    `endif
5067
 
5068
    // check statuses!
5069
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5070
    ok = 1 ;
5071
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5072
    if ( temp_val1[31] !== 1 )
5073
    begin
5074
        $display("Parity checker testing failed! Time %t ", $time) ;
5075
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5076
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5077
        ok = 0 ;
5078
    end
5079
 
5080
    if ( temp_val1[30] !== 1 )
5081
    begin
5082
        $display("Parity checker testing failed! Time %t ", $time) ;
5083
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5084
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5085
        ok = 0 ;
5086
    end
5087
 
5088
    if ( temp_val1[24] !== 0 )
5089
    begin
5090
        $display("Parity checker testing failed! Time %t ", $time) ;
5091
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5092
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5093
        ok = 0 ;
5094
    end
5095
 
5096
    if ( ok )
5097
        test_ok ;
5098
 
5099
    // clear statuses
5100
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5101
 
5102
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5103
 
5104
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5105
    ok = 1 ;
5106
 
5107
    `ifdef HOST
5108
    if ( temp_val1[4] !== 1 )
5109
    begin
5110
        $display("Parity checker testing failed! Time %t ", $time) ;
5111
        $display("System error interrupt status bit not set when expected!") ;
5112
        test_fail("System error interrupt status bit not set when expected") ;
5113
        ok = 0 ;
5114
    end
5115
    `else
5116
    if ( temp_val1[4] !== 0 )
5117
    begin
5118
        $display("Parity checker testing failed! Time %t ", $time) ;
5119
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5120
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5121
        ok = 0 ;
5122
    end
5123
    `endif
5124
 
5125
    if ( temp_val1[3] !== 0 )
5126
    begin
5127
        $display("Parity checker testing failed! Time %t ", $time) ;
5128
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5129
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5130
        ok = 0 ;
5131
    end
5132
 
5133
    if ( ok )
5134
        test_ok ;
5135
 
5136
    // clear statuses
5137
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5138
 
5139
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5140
    fork
5141
    begin
5142
        ipci_unsupported_commands_master.master_reference
5143
        (
5144
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5145
            32'h5555_5555,      // second part of address in dual address cycle
5146
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5147
            `BC_MEM_WRITE,      // normal command
5148
            4'h0,               // byte enables
5149
            32'h1234_5678,      // data
5150
            1'b1,               // make address parity error on first phase of dual address
5151
            1'b0,               // make address parity error on second phase of dual address
5152
            ok                  // result of operation
5153
        ) ;
5154
        disable wait_serr14 ;
5155
    end
5156
    begin:wait_serr14
5157
        perr_asserted = 0 ;
5158
        @(posedge pci_clock) ;
5159
        while( SERR === 1 )
5160
            @(posedge pci_clock) ;
5161
 
5162
        if ( SERR === 0 )
5163
            perr_asserted = 1 ;
5164
    end
5165
    join
5166
 
5167
    if ( ok && perr_asserted)
5168
        test_ok ;
5169
    else
5170
    if ( !perr_asserted )
5171
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5172
 
5173
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5174
 
5175
    `ifdef HOST
5176
        repeat(4)
5177 26 mihad
            @(posedge pci_clock) ;
5178
        repeat(4)
5179 15 mihad
            @(posedge wb_clock) ;
5180
        if ( INT_O !== 1 )
5181
        begin
5182
            $display("Parity checker testing failed! Time %t ", $time) ;
5183
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5184
            test_fail("Interrupt Request was not triggered as expected") ;
5185
        end
5186
        else
5187
            test_ok ;
5188
    `else
5189
    `ifdef GUEST
5190 26 mihad
        repeat(4)
5191
            @(posedge wb_clock) ;
5192
        repeat(4)
5193 15 mihad
            @(posedge pci_clock) ;
5194
 
5195
        if ( INTA !== 1 )
5196
        begin
5197
            $display("Parity checker testing failed! Time %t ", $time) ;
5198
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5199
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5200
        end
5201
        else
5202
            test_ok ;
5203
    `endif
5204
    `endif
5205
 
5206
    // check statuses!
5207
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5208
    ok = 1 ;
5209
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5210
    if ( temp_val1[31] !== 1 )
5211
    begin
5212
        $display("Parity checker testing failed! Time %t ", $time) ;
5213
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5214
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5215
        ok = 0 ;
5216
    end
5217
 
5218
    if ( temp_val1[30] !== 1 )
5219
    begin
5220
        $display("Parity checker testing failed! Time %t ", $time) ;
5221
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5222
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5223
        ok = 0 ;
5224
    end
5225
 
5226
    if ( temp_val1[24] !== 0 )
5227
    begin
5228
        $display("Parity checker testing failed! Time %t ", $time) ;
5229
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5230
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5231
        ok = 0 ;
5232
    end
5233
 
5234
    if ( ok )
5235
        test_ok ;
5236
 
5237
    // clear statuses
5238
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5239
 
5240
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5241
 
5242
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5243
    ok = 1 ;
5244
 
5245
    `ifdef HOST
5246
    if ( temp_val1[4] !== 1 )
5247
    begin
5248
        $display("Parity checker testing failed! Time %t ", $time) ;
5249
        $display("System error interrupt status bit not set when expected!") ;
5250
        test_fail("System error interrupt status bit not set when expected") ;
5251
        ok = 0 ;
5252
    end
5253
    `else
5254
    if ( temp_val1[4] !== 0 )
5255
    begin
5256
        $display("Parity checker testing failed! Time %t ", $time) ;
5257
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5258
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5259
        ok = 0 ;
5260
    end
5261
    `endif
5262
 
5263
    if ( temp_val1[3] !== 0 )
5264
    begin
5265
        $display("Parity checker testing failed! Time %t ", $time) ;
5266
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5267
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5268
        ok = 0 ;
5269
    end
5270
 
5271
    if ( ok )
5272
        test_ok ;
5273
 
5274
    // clear statuses
5275
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5276
 
5277
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5278
    fork
5279
    begin
5280
        ipci_unsupported_commands_master.master_reference
5281
        (
5282
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5283
            32'h5555_5555,      // second part of address in dual address cycle
5284
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5285
            `BC_MEM_WRITE,      // normal command
5286
            4'h0,               // byte enables
5287
            32'h1234_5678,      // data
5288
            1'b0,               // make address parity error on first phase of dual address
5289
            1'b1,               // make address parity error on second phase of dual address
5290
            ok                  // result of operation
5291
        ) ;
5292
        disable wait_serr15 ;
5293
    end
5294
    begin:wait_serr15
5295
        perr_asserted = 0 ;
5296
        @(posedge pci_clock) ;
5297
        while( SERR === 1 )
5298
            @(posedge pci_clock) ;
5299
 
5300
        if ( SERR === 0 )
5301
            perr_asserted = 1 ;
5302
    end
5303
    join
5304
 
5305
    if ( ok && perr_asserted)
5306
        test_ok ;
5307
    else
5308
    if ( !perr_asserted )
5309
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5310
 
5311
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5312
 
5313
    `ifdef HOST
5314
        repeat(4)
5315 26 mihad
            @(posedge pci_clock) ;
5316
        repeat(4)
5317 15 mihad
            @(posedge wb_clock) ;
5318
        if ( INT_O !== 1 )
5319
        begin
5320
            $display("Parity checker testing failed! Time %t ", $time) ;
5321
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5322
            test_fail("Interrupt Request was not triggered as expected") ;
5323
        end
5324
        else
5325
            test_ok ;
5326
    `else
5327
    `ifdef GUEST
5328 26 mihad
        repeat(4)
5329
            @(posedge wb_clock) ;
5330
        repeat(4)
5331 15 mihad
            @(posedge pci_clock) ;
5332
 
5333
        if ( INTA !== 1 )
5334
        begin
5335
            $display("Parity checker testing failed! Time %t ", $time) ;
5336
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5337
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5338
        end
5339
        else
5340
            test_ok ;
5341
    `endif
5342
    `endif
5343
 
5344
    // check statuses!
5345
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5346
    ok = 1 ;
5347
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5348
    if ( temp_val1[31] !== 1 )
5349
    begin
5350
        $display("Parity checker testing failed! Time %t ", $time) ;
5351
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5352
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5353
        ok = 0 ;
5354
    end
5355
 
5356
    if ( temp_val1[30] !== 1 )
5357
    begin
5358
        $display("Parity checker testing failed! Time %t ", $time) ;
5359
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5360
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5361
        ok = 0 ;
5362
    end
5363
 
5364
    if ( temp_val1[24] !== 0 )
5365
    begin
5366
        $display("Parity checker testing failed! Time %t ", $time) ;
5367
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5368
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5369
        ok = 0 ;
5370
    end
5371
 
5372
    if ( ok )
5373
        test_ok ;
5374
 
5375
    // clear statuses
5376
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5377
 
5378
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5379
 
5380
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5381
    ok = 1 ;
5382
 
5383
    `ifdef HOST
5384
    if ( temp_val1[4] !== 1 )
5385
    begin
5386
        $display("Parity checker testing failed! Time %t ", $time) ;
5387
        $display("System error interrupt status bit not set when expected!") ;
5388
        test_fail("System error interrupt status bit not set when expected") ;
5389
        ok = 0 ;
5390
    end
5391
    `else
5392
    if ( temp_val1[4] !== 0 )
5393
    begin
5394
        $display("Parity checker testing failed! Time %t ", $time) ;
5395
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5396
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5397
        ok = 0 ;
5398
    end
5399
    `endif
5400
 
5401
    if ( temp_val1[3] !== 0 )
5402
    begin
5403
        $display("Parity checker testing failed! Time %t ", $time) ;
5404
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5405
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5406
        ok = 0 ;
5407
    end
5408
 
5409
    if ( ok )
5410
        test_ok ;
5411
 
5412
    // clear statuses
5413
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5414
 
5415
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5416
    fork
5417
    begin
5418
        ipci_unsupported_commands_master.master_reference
5419
        (
5420
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5421
            32'h5555_5555,      // second part of address in dual address cycle
5422
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5423
            `BC_MEM_WRITE,      // normal command
5424
            4'h0,               // byte enables
5425
            32'h1234_5678,      // data
5426
            1'b1,               // make address parity error on first phase of dual address
5427
            1'b1,               // make address parity error on second phase of dual address
5428
            ok                  // result of operation
5429
        ) ;
5430
        disable wait_serr16 ;
5431
    end
5432
    begin:wait_serr16
5433
        perr_asserted = 0 ;
5434
        @(posedge pci_clock) ;
5435
        while( SERR === 1 )
5436
            @(posedge pci_clock) ;
5437
 
5438
        if ( SERR === 0 )
5439
            perr_asserted = 1 ;
5440
    end
5441
    join
5442
 
5443
    if ( ok && perr_asserted)
5444
        test_ok ;
5445
    else
5446
    if ( !perr_asserted )
5447
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5448
 
5449
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5450
 
5451
    `ifdef HOST
5452
        repeat(4)
5453 26 mihad
            @(posedge pci_clock) ;
5454
        repeat(4)
5455 15 mihad
            @(posedge wb_clock) ;
5456
        if ( INT_O !== 1 )
5457
        begin
5458
            $display("Parity checker testing failed! Time %t ", $time) ;
5459
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5460
            test_fail("Interrupt Request was not triggered as expected") ;
5461
        end
5462
        else
5463
            test_ok ;
5464
    `else
5465
    `ifdef GUEST
5466 26 mihad
        repeat(4)
5467
            @(posedge wb_clock) ;
5468
        repeat(4)
5469 15 mihad
            @(posedge pci_clock) ;
5470
 
5471
        if ( INTA !== 1 )
5472
        begin
5473
            $display("Parity checker testing failed! Time %t ", $time) ;
5474
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5475
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5476
        end
5477
        else
5478
            test_ok ;
5479
    `endif
5480
    `endif
5481
 
5482
    // check statuses!
5483
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5484
    ok = 1 ;
5485
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5486
    if ( temp_val1[31] !== 1 )
5487
    begin
5488
        $display("Parity checker testing failed! Time %t ", $time) ;
5489
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5490
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5491
        ok = 0 ;
5492
    end
5493
 
5494
    if ( temp_val1[30] !== 1 )
5495
    begin
5496
        $display("Parity checker testing failed! Time %t ", $time) ;
5497
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5498
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5499
        ok = 0 ;
5500
    end
5501
 
5502
    if ( temp_val1[24] !== 0 )
5503
    begin
5504
        $display("Parity checker testing failed! Time %t ", $time) ;
5505
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5506
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5507
        ok = 0 ;
5508
    end
5509
 
5510
    if ( ok )
5511
        test_ok ;
5512
 
5513
    // clear statuses
5514
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5515
 
5516
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5517
 
5518
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5519
    ok = 1 ;
5520
 
5521
    `ifdef HOST
5522
    if ( temp_val1[4] !== 1 )
5523
    begin
5524
        $display("Parity checker testing failed! Time %t ", $time) ;
5525
        $display("System error interrupt status bit not set when expected!") ;
5526
        test_fail("System error interrupt status bit not set when expected") ;
5527
        ok = 0 ;
5528
    end
5529
    `else
5530
    if ( temp_val1[4] !== 0 )
5531
    begin
5532
        $display("Parity checker testing failed! Time %t ", $time) ;
5533
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5534
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5535
        ok = 0 ;
5536
    end
5537
    `endif
5538
 
5539
    if ( temp_val1[3] !== 0 )
5540
    begin
5541
        $display("Parity checker testing failed! Time %t ", $time) ;
5542
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5543
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5544
        ok = 0 ;
5545
    end
5546
 
5547
    if ( ok )
5548
        test_ok ;
5549
 
5550
    // clear statuses
5551
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5552
 
5553
    // now just disable Parity Error response - on Address par errors nothing should happen
5554
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5555
 
5556
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5557
    fork
5558
    begin
5559
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5560
               target_address, 32'h1234_5678,
5561
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5562
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5563
        do_pause( 1 ) ;
5564
    end
5565
    begin:wait_serr12
5566
        perr_asserted = 0 ;
5567
        @(posedge pci_clock) ;
5568
        while( SERR === 1 )
5569
            @(posedge pci_clock) ;
5570
 
5571
        perr_asserted = 1 ;
5572
        $display("Parity checker testing failed! Time %t ", $time) ;
5573
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5574
        test_fail("SERR asserted when parity error response was disabled") ;
5575
    end
5576
    begin
5577
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5578
        if ( ok !== 1 )
5579
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5580
 
5581
        disable wait_serr12 ;
5582
    end
5583
    join
5584
 
5585
    if ( ok && !perr_asserted )
5586
        test_ok ;
5587
 
5588
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5589
    `ifdef HOST
5590 26 mihad
        repeat (4)
5591
            @(posedge pci_clock) ;
5592 15 mihad
        repeat(4)
5593
            @(posedge wb_clock) ;
5594
        if ( INT_O !== 0 )
5595
        begin
5596
            $display("Parity checker testing failed! Time %t ", $time) ;
5597
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5598
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5599
        end
5600
        else
5601
            test_ok ;
5602
    `else
5603
    `ifdef GUEST
5604 26 mihad
        repeat(4)
5605
            @(posedge wb_clock) ;
5606
        repeat (4)
5607 15 mihad
            @(posedge pci_clock) ;
5608
 
5609
        if ( INTA !== 1 )
5610
        begin
5611
            $display("Parity checker testing failed! Time %t ", $time) ;
5612
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5613
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5614
        end
5615
        else
5616
            test_ok ;
5617
    `endif
5618
    `endif
5619
 
5620
    // check statuses!
5621
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5622
    ok = 1 ;
5623
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5624
    if ( temp_val1[31] !== 1 )
5625
    begin
5626
        $display("Parity checker testing failed! Time %t ", $time) ;
5627
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5628
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5629
        ok = 0 ;
5630
    end
5631
 
5632
    if ( temp_val1[30] !== 0 )
5633
    begin
5634
        $display("Parity checker testing failed! Time %t ", $time) ;
5635
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5636
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5637
        ok = 0 ;
5638
    end
5639
 
5640
    if ( temp_val1[24] !== 0 )
5641
    begin
5642
        $display("Parity checker testing failed! Time %t ", $time) ;
5643
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5644
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5645
        ok = 0 ;
5646
    end
5647
 
5648
    if ( ok )
5649
        test_ok ;
5650
 
5651
    // clear statuses
5652
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5653
 
5654
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5655
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5656
    ok = 1 ;
5657
    if ( temp_val1[4] !== 0 )
5658
    begin
5659
        $display("Parity checker testing failed! Time %t ", $time) ;
5660
        $display("System error interrupt status bit set when not expected!") ;
5661
        test_fail("System error interrupt status bit set when not expected") ;
5662
        ok = 0 ;
5663
    end
5664
 
5665
    if ( temp_val1[3] !== 0 )
5666
    begin
5667
        $display("Parity checker testing failed! Time %t ", $time) ;
5668
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5669
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5670
        ok = 0 ;
5671
    end
5672
 
5673
    if ( ok )
5674
        test_ok ;
5675
 
5676
    // clear statuses
5677
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5678
 
5679
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5680
    fork
5681
    begin
5682
        ipci_unsupported_commands_master.master_reference
5683
        (
5684
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5685
            32'h5555_5555,      // second part of address in dual address cycle
5686
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5687
            `BC_MEM_WRITE,      // normal command
5688
            4'h0,               // byte enables
5689
            32'h1234_5678,      // data
5690
            1'b1,               // make address parity error on first phase of dual address
5691
            1'b0,               // make address parity error on second phase of dual address
5692
            ok                  // result of operation
5693
        ) ;
5694
        disable wait_serr17 ;
5695
    end
5696
    begin:wait_serr17
5697
        perr_asserted = 0 ;
5698
        @(posedge pci_clock) ;
5699
        while( SERR === 1 )
5700
            @(posedge pci_clock) ;
5701
 
5702
        perr_asserted = 1 ;
5703
        $display("Parity checker testing failed! Time %t ", $time) ;
5704
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5705
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5706
    end
5707
    join
5708
 
5709
    if ( ok && !perr_asserted)
5710
        test_ok ;
5711
 
5712
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5713
    fork
5714
    begin
5715
        ipci_unsupported_commands_master.master_reference
5716
        (
5717
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5718
            32'h5555_5555,      // second part of address in dual address cycle
5719
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5720
            `BC_MEM_WRITE,      // normal command
5721
            4'h0,               // byte enables
5722
            32'h1234_5678,      // data
5723
            1'b0,               // make address parity error on first phase of dual address
5724
            1'b1,               // make address parity error on second phase of dual address
5725
            ok                  // result of operation
5726
        ) ;
5727
        disable wait_serr18 ;
5728
    end
5729
    begin:wait_serr18
5730
        perr_asserted = 0 ;
5731
        @(posedge pci_clock) ;
5732
        while( SERR === 1 )
5733
            @(posedge pci_clock) ;
5734
 
5735
        perr_asserted = 1 ;
5736
        $display("Parity checker testing failed! Time %t ", $time) ;
5737
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5738
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5739
    end
5740
    join
5741
 
5742
    if ( ok && !perr_asserted)
5743
        test_ok ;
5744
 
5745
    // check statuses!
5746
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5747
    ok = 1 ;
5748
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5749
    if ( temp_val1[31] !== 1 )
5750
    begin
5751
        $display("Parity checker testing failed! Time %t ", $time) ;
5752
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5753
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5754
        ok = 0 ;
5755
    end
5756
 
5757
    if ( temp_val1[30] !== 0 )
5758
    begin
5759
        $display("Parity checker testing failed! Time %t ", $time) ;
5760
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5761
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5762
        ok = 0 ;
5763
    end
5764
 
5765
    if ( temp_val1[24] !== 0 )
5766
    begin
5767
        $display("Parity checker testing failed! Time %t ", $time) ;
5768
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5769
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5770
        ok = 0 ;
5771
    end
5772
 
5773
    if ( ok )
5774
        test_ok ;
5775
 
5776
    // clear statuses
5777
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5778
 
5779
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5780
    fork
5781
    begin
5782
        ipci_unsupported_commands_master.master_reference
5783
        (
5784
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5785
            32'h5555_5555,      // second part of address in dual address cycle
5786
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5787
            `BC_MEM_WRITE,      // normal command
5788
            4'h0,               // byte enables
5789
            32'h1234_5678,      // data
5790
            1'b1,               // make address parity error on first phase of dual address
5791
            1'b1,               // make address parity error on second phase of dual address
5792
            ok                  // result of operation
5793
        ) ;
5794
        disable wait_serr19 ;
5795
    end
5796
    begin:wait_serr19
5797
        perr_asserted = 0 ;
5798
        @(posedge pci_clock) ;
5799
        while( SERR === 1 )
5800
            @(posedge pci_clock) ;
5801
 
5802
        perr_asserted = 1 ;
5803
        $display("Parity checker testing failed! Time %t ", $time) ;
5804
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5805
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5806
    end
5807
    join
5808
 
5809
    if ( ok && !perr_asserted)
5810
        test_ok ;
5811
 
5812
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5813
 
5814
    `ifdef HOST
5815
        repeat(4)
5816 26 mihad
            @(posedge pci_clock) ;
5817
        repeat(4)
5818 15 mihad
            @(posedge wb_clock) ;
5819
        if ( INT_O !== 0 )
5820
        begin
5821
            $display("Parity checker testing failed! Time %t ", $time) ;
5822
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5823
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5824
        end
5825
        else
5826
            test_ok ;
5827
    `else
5828
    `ifdef GUEST
5829 26 mihad
        repeat(4)
5830
            @(posedge wb_clock) ;
5831
        repeat(4)
5832 15 mihad
            @(posedge pci_clock) ;
5833
 
5834
        if ( INTA !== 1 )
5835
        begin
5836
            $display("Parity checker testing failed! Time %t ", $time) ;
5837
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5838
            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") ;
5839
        end
5840
        else
5841
            test_ok ;
5842
    `endif
5843
    `endif
5844
 
5845
    // check statuses!
5846
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5847
    ok = 1 ;
5848
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5849
    if ( temp_val1[31] !== 1 )
5850
    begin
5851
        $display("Parity checker testing failed! Time %t ", $time) ;
5852
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5853
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5854
        ok = 0 ;
5855
    end
5856
 
5857
    if ( temp_val1[30] !== 0 )
5858
    begin
5859
        $display("Parity checker testing failed! Time %t ", $time) ;
5860
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5861
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5862
        ok = 0 ;
5863
    end
5864
 
5865
    if ( temp_val1[24] !== 0 )
5866
    begin
5867
        $display("Parity checker testing failed! Time %t ", $time) ;
5868
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5869
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5870
        ok = 0 ;
5871
    end
5872
 
5873
    if ( ok )
5874
        test_ok ;
5875
 
5876
    // clear statuses
5877
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5878
 
5879
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5880
 
5881
    // do normal write
5882
    fork
5883
    begin
5884
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5885
               target_address, 32'h1234_5678, `Test_All_Bytes,
5886
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5887
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5888
        do_pause( 1 ) ;
5889
    end
5890
    begin:wait_serr13
5891
        perr_asserted = 0 ;
5892
        @(posedge pci_clock) ;
5893
        while( SERR === 1 )
5894
            @(posedge pci_clock) ;
5895
 
5896
        perr_asserted = 1 ;
5897
        $display("Parity checker testing failed! Time %t ", $time) ;
5898
        $display("SERR asserted for no reason!") ;
5899
        test_fail("SERR was asserted for no reason") ;
5900
    end
5901
    begin
5902
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5903
        if ( ok !== 1 )
5904
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5905
 
5906
        disable wait_serr13 ;
5907
    end
5908
    join
5909
 
5910
    if ( ok && !perr_asserted )
5911
        test_ok ;
5912
 
5913
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
5914
    `ifdef HOST
5915 26 mihad
        repeat( 4 )
5916
            @(posedge pci_clock) ;
5917 15 mihad
        repeat(4)
5918
            @(posedge wb_clock) ;
5919
        if ( INT_O !== 0 )
5920
        begin
5921
            $display("Parity checker testing failed! Time %t ", $time) ;
5922
            $display("Interrupt request asserted for no reason!") ;
5923
            test_fail("Interrupt request was asserted for no reason") ;
5924
        end
5925
        else
5926
            test_ok ;
5927
    `else
5928
    `ifdef GUEST
5929 26 mihad
        repeat(4)
5930
            @(posedge wb_clock) ;
5931
        repeat(4)
5932 15 mihad
            @(posedge pci_clock) ;
5933
 
5934
        if ( INTA !== 1 )
5935
        begin
5936
            $display("Parity checker testing failed! Time %t ", $time) ;
5937
            $display("Interrupt request asserted for no reason!") ;
5938
            test_fail("Interrupt request was asserted for no reason") ;
5939
        end
5940
        else
5941
            test_ok ;
5942
    `endif
5943
    `endif
5944
 
5945
    // check statuses!
5946
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5947
    ok = 1 ;
5948
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5949
    if ( temp_val1[31] !== 0 )
5950
    begin
5951
        $display("Parity checker testing failed! Time %t ", $time) ;
5952
        $display("Detected Parity Error bit was set for no reason!") ;
5953
        test_fail("Detected Parity Error bit was set for no reason") ;
5954
        ok = 0 ;
5955
    end
5956
 
5957
    if ( temp_val1[30] !== 0 )
5958
    begin
5959
        $display("Parity checker testing failed! Time %t ", $time) ;
5960
        $display("Signalled System Error bit was set for no reason!") ;
5961
        test_fail("Signalled System Error bit was set for no reason") ;
5962
        ok = 0 ;
5963
    end
5964
 
5965
    if ( temp_val1[24] !== 0 )
5966
    begin
5967
        $display("Parity checker testing failed! Time %t ", $time) ;
5968
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5969
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5970
        ok = 0 ;
5971
    end
5972
 
5973
    if ( ok )
5974
        test_ok ;
5975
 
5976
    // clear statuses
5977
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5978
 
5979
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5980
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5981
    ok = 1 ;
5982
 
5983
    if ( temp_val1[4] !== 0 )
5984
    begin
5985
        $display("Parity checker testing failed! Time %t ", $time) ;
5986
        $display("System error interrupt status bit set when not expected!") ;
5987
        test_fail("System error interrupt status bit set when not expected") ;
5988
        ok = 0 ;
5989
    end
5990
 
5991
    if ( temp_val1[3] !== 0 )
5992
    begin
5993
        $display("Parity checker testing failed! Time %t ", $time) ;
5994
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5995
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5996
        ok = 0 ;
5997
    end
5998
 
5999
    if ( ok )
6000
        test_ok ;
6001
 
6002
    // clear statuses
6003
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6004
 
6005
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6006
 
6007
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6008
 
6009
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6010
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6011
 
6012
    // setup target's image!
6013
    target_address  = Target_Base_Addr_R[1] ;
6014
 
6015
    // base address
6016
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6017
 
6018
    // address mask
6019
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6020
 
6021
    // image control
6022
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6023
 
6024
    // enable everything possible for parity checking
6025
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6026
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6027
 
6028
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6029
 
6030
    fork
6031
    begin
6032
        if ( target_mem_image === 1 )
6033
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6034
                   target_address, 32'h1234_5678,
6035
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6036
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6037
        else
6038
            PCIU_IO_WRITE_MAKE_PERR (
6039
                                    `Test_Master_1,
6040
                                    target_address,
6041
                                    32'h1234_5678,
6042
                                    4'h0,
6043
                                    1,
6044
                                    `Test_Target_Normal_Completion
6045
                                    );
6046
 
6047
        do_pause( 1 ) ;
6048
    end
6049
    begin:wait_perr11
6050
        perr_asserted = 0 ;
6051
        @(posedge pci_clock) ;
6052
        while ( PERR === 1 )
6053
            @(posedge pci_clock) ;
6054
 
6055
        if ( PERR === 0 )
6056
            perr_asserted = 1 ;
6057
 
6058
    end
6059
    begin
6060
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6061
 
6062
        if ( ok !== 1 )
6063
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6064
 
6065
        repeat(2)
6066
            @(posedge pci_clock) ;
6067
 
6068
        disable wait_perr11 ;
6069
    end
6070
    join
6071
 
6072
    if ( ok && perr_asserted )
6073
        test_ok ;
6074
    else
6075
    if ( !perr_asserted )
6076
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6077
 
6078
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6079
    `ifdef HOST
6080 26 mihad
        repeat (4)
6081
            @(posedge pci_clock) ;
6082 15 mihad
        repeat(4)
6083
            @(posedge wb_clock) ;
6084
        if ( INT_O !== 0 )
6085
        begin
6086
            $display("Parity checker testing failed! Time %t ", $time) ;
6087
            $display("Interrupt request asserted for no reason!") ;
6088
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6089
        end
6090
        else
6091
            test_ok ;
6092
    `else
6093
    `ifdef GUEST
6094 26 mihad
        repeat(4)
6095
            @(posedge wb_clock) ;
6096
        repeat (4)
6097 15 mihad
            @(posedge pci_clock) ;
6098
 
6099
        if ( INTA !== 1 )
6100
        begin
6101
            $display("Parity checker testing failed! Time %t ", $time) ;
6102
            $display("Interrupt request asserted for no reason!") ;
6103
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6104
        end
6105
        else
6106
            test_ok ;
6107
 
6108
    `endif
6109
    `endif
6110
 
6111
    // check statuses!
6112
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6113
    ok = 1 ;
6114
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6115
    if ( temp_val1[31] !== 1 )
6116
    begin
6117
        $display("Parity checker testing failed! Time %t ", $time) ;
6118
        $display("Detected Parity Error bit was not set after Target detected parity error!") ;
6119
        test_fail("Detected Parity Error bit was not set after Target detected parity error") ;
6120
        ok = 0 ;
6121
    end
6122
 
6123
    if ( temp_val1[30] !== 0 )
6124
    begin
6125
        $display("Parity checker testing failed! Time %t ", $time) ;
6126
        $display("Signalled System Error bit was set for no reason!") ;
6127
        test_fail("Signalled System Error bit was set for no reason") ;
6128
        ok = 0 ;
6129
    end
6130
 
6131
    if ( temp_val1[24] !== 0 )
6132
    begin
6133
        $display("Parity checker testing failed! Time %t ", $time) ;
6134
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6135
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6136
        ok = 0 ;
6137
    end
6138
 
6139
    if ( ok )
6140
        test_ok ;
6141
 
6142
    // clear statuses
6143
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6144
 
6145
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6146
 
6147
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6148
    ok = 1 ;
6149
    if ( temp_val1[4] !== 0 )
6150
    begin
6151
        $display("Parity checker testing failed! Time %t ", $time) ;
6152
        $display("System error interrupt status bit set when not expected!") ;
6153
        test_fail("System error interrupt status bit set when not expected") ;
6154
        ok = 0 ;
6155
    end
6156
 
6157
    if ( temp_val1[3] !== 0 )
6158
    begin
6159
        $display("Parity checker testing failed! Time %t ", $time) ;
6160
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6161
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6162
        ok = 0 ;
6163
    end
6164
 
6165
    if ( ok )
6166
        test_ok ;
6167
 
6168
    // clear statuses
6169
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6170
 
6171
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6172
 
6173
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6174
    fork
6175
    begin
6176
        if ( target_mem_image === 1 )
6177
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6178
                          target_address, 32'h1234_5678,
6179
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6180
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6181
        else
6182
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6183
 
6184
        do_pause( 1 ) ;
6185
    end
6186
    begin:wait_perr12
6187
        perr_asserted = 0 ;
6188
        @(posedge pci_clock) ;
6189
        while ( PERR === 1 )
6190
            @(posedge pci_clock) ;
6191
 
6192
        if ( PERR === 0 )
6193
            perr_asserted = 1 ;
6194
    end
6195
    begin
6196
 
6197
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6198
        if ( ok !== 1 )
6199
        begin
6200
            test_fail("Bridge failed to process Target Memory read correctly") ;
6201
            disable main ;
6202
        end
6203
 
6204
        repeat(3)
6205
            @(posedge pci_clock) ;
6206
 
6207
        if ( target_mem_image === 1 )
6208
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6209
                    target_address, 32'h1234_5678,
6210
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6211
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6212
        else
6213
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6214
 
6215
        do_pause( 1 ) ;
6216
 
6217
    end
6218
    begin
6219
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6220
        if ( ok !== 1 )
6221
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6222
        else
6223
        begin
6224
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6225
            if ( ok !== 1 )
6226
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6227
        end
6228
 
6229
        repeat(3)
6230
            @(posedge pci_clock) ;
6231
 
6232
        disable wait_perr12 ;
6233
    end
6234
    join
6235
 
6236
    if ( ok && perr_asserted )
6237
        test_ok ;
6238
    else
6239
    if ( !perr_asserted )
6240
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6241
 
6242
 
6243
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6244
    `ifdef HOST
6245
        repeat(4)
6246 26 mihad
            @(posedge pci_clock) ;
6247
        repeat(4)
6248 15 mihad
            @(posedge wb_clock) ;
6249
        if ( INT_O !== 0 )
6250
        begin
6251
            $display("Parity checker testing failed! Time %t ", $time) ;
6252
            $display("Interrupt request asserted for no reason!") ;
6253
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6254
        end
6255
        else
6256
            test_ok ;
6257
    `else
6258
    `ifdef GUEST
6259 26 mihad
        repeat(4)
6260
            @(posedge wb_clock) ;
6261
        repeat(4)
6262 15 mihad
            @(posedge pci_clock) ;
6263
 
6264
        if ( INTA !== 1 )
6265
        begin
6266
            $display("Parity checker testing failed! Time %t ", $time) ;
6267
            $display("Interrupt request asserted for no reason!") ;
6268
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6269
        end
6270
        else
6271
            test_ok ;
6272
    `endif
6273
    `endif
6274
 
6275
    // check statuses!
6276
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6277
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6278
    ok = 1 ;
6279
    if ( temp_val1[31] !== 1 )
6280
    begin
6281
        $display("Parity checker testing failed! Time %t ", $time) ;
6282
        $display("Detected Parity Error bit was not set after Target receive PERR asserted!") ;
6283
        test_fail("Detected Parity Error bit was not set after Target received PERR asserted on read reference") ;
6284
        ok = 0 ;
6285
    end
6286
 
6287
    if ( temp_val1[30] !== 0 )
6288
    begin
6289
        $display("Parity checker testing failed! Time %t ", $time) ;
6290
        $display("Signalled System Error bit was set for no reason!") ;
6291
        test_fail("Signalled System Error bit was set for no reason") ;
6292
        ok = 0 ;
6293
    end
6294
 
6295
    if ( temp_val1[24] !== 0 )
6296
    begin
6297
        $display("Parity checker testing failed! Time %t ", $time) ;
6298
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6299
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6300
        ok = 0 ;
6301
    end
6302
 
6303
    if ( ok )
6304
        test_ok ;
6305
 
6306
    // clear statuses
6307
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6308
 
6309
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6310
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6311
    ok = 1 ;
6312
    if ( temp_val1[4] !== 0 )
6313
    begin
6314
        $display("Parity checker testing failed! Time %t ", $time) ;
6315
        $display("System error interrupt status bit set when not expected!") ;
6316
        test_fail("System error interrupt status bit set when not expected") ;
6317
        ok = 0 ;
6318
    end
6319
 
6320
    if ( temp_val1[3] !== 0 )
6321
    begin
6322
        $display("Parity checker testing failed! Time %t ", $time) ;
6323
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6324
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6325
        ok = 0 ;
6326
    end
6327
 
6328
    if ( ok )
6329
        test_ok ;
6330
    // clear statuses
6331
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6332
 
6333
    $fdisplay(pci_mon_log_file_desc,
6334
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6335
    test_name = "DISABLE USED IMAGES" ;
6336
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6337
    if ( ok !== 1 )
6338
    begin
6339
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6340
        test_fail("WB Image Address Mask register could not be written to") ;
6341
        disable main ;
6342
    end
6343
 
6344
    config_write( p_am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6345
    if ( ok !== 1 )
6346
    begin
6347
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6348
        test_fail("PCI Image Address Mask register could not be written to") ;
6349
        disable main ;
6350
    end
6351
 
6352
    // disable target's 1 response to parity errors
6353
    configuration_cycle_write(0,             // bus number
6354
                              1,             // device number
6355
                              0,             // function number
6356
                              1,             // register number
6357
                              0,             // type of configuration cycle
6358
                              4'b0001,       // byte enables
6359
                              32'h0000_0007  // data
6360
                             ) ;
6361
 
6362
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6363
end
6364
endtask // parity_checking
6365
 
6366
task wb_to_pci_transactions ;
6367
    reg   [11:0] ctrl_offset ;
6368
    reg   [11:0] ba_offset ;
6369
    reg   [11:0] am_offset ;
6370
    reg   [11:0] pci_ctrl_offset ;
6371
    reg   [11:0] err_cs_offset ;
6372
    reg   [11:0] icr_offset ;
6373
    reg   [11:0] isr_offset ;
6374
    reg   [11:0] lat_tim_cls_offset ;
6375
 
6376
    reg `WRITE_STIM_TYPE  write_data ;
6377
    reg `READ_STIM_TYPE   read_data ;
6378
    reg `READ_RETURN_TYPE read_status ;
6379
 
6380
    reg `WRITE_RETURN_TYPE write_status ;
6381
    reg `WB_TRANSFER_FLAGS write_flags ;
6382
    reg [31:0] temp_val1 ;
6383
    reg [31:0] temp_val2 ;
6384
    reg        ok   ;
6385
 
6386
    reg [31:0] image_base ;
6387
    reg [31:0] target_address ;
6388
    integer i ;
6389
    integer required_reads ;
6390
    integer writes_left ;
6391
 
6392
begin:main
6393
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6394
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6395
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6396
    pci_ctrl_offset    = 12'h4 ;
6397
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6398
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6399
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6400
    lat_tim_cls_offset = 12'hC ;
6401
 
6402
    $display("Checking WB to PCI transaction lengths!") ;
6403
    target_address  = `BEH_TAR1_MEM_START ;
6404
    image_base      = 0 ;
6405
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6406
 
6407
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6408
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6409
    write_flags                    = 0 ;
6410
    write_flags`INIT_WAITS         = tb_init_waits ;
6411
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6412
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6413
 
6414
    // enable master & target operation
6415
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6416
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6417
    if ( ok !== 1 )
6418
    begin
6419
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6420
        test_fail("write to PCI Device Control register failed") ;
6421
        disable main ;
6422
    end
6423
 
6424
    // prepare image control register
6425
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6426
    if ( ok !== 1 )
6427
    begin
6428
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6429
        test_fail("write to WB Image Control register failed") ;
6430
        disable main ;
6431
    end
6432
 
6433
    // prepare base address register
6434
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6435
    if ( ok !== 1 )
6436
    begin
6437
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6438
        test_fail("write to WB Base Address register failed") ;
6439
        disable main ;
6440
    end
6441
 
6442
    // write address mask register
6443
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6444
    if ( ok !== 1 )
6445
    begin
6446
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6447
        test_fail("write to WB Address Mask register failed") ;
6448
        disable main ;
6449
    end
6450
 
6451
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6452
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6453
    if ( ok !== 1 )
6454
    begin
6455
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6456
        test_fail("write to WB Error Control and Status register failed") ;
6457
        disable main ;
6458
    end
6459
 
6460
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6461
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6462
    if ( ok !== 1 )
6463
    begin
6464
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6465
        test_fail("write to Interrupt Control register failed") ;
6466
        disable main ;
6467
    end
6468
 
6469
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6470
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6471
    if ( ok !== 1 )
6472
    begin
6473
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6474
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6475
        disable main ;
6476
    end
6477
 
6478
    $display("Testing single write transaction progress from WB to PCI!") ;
6479
    write_data`WRITE_ADDRESS = target_address ;
6480
    write_data`WRITE_DATA    = wmem_data[0] ;
6481
    write_data`WRITE_SEL     = 4'hF ;
6482
 
6483
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6484
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6485
 
6486
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6487
    fork
6488
    begin
6489
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6490
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6491
        begin
6492
            $display("Transaction progress testing failed! Time %t ", $time) ;
6493
            $display("Bridge failed to process single memory write!") ;
6494
            test_fail("bridge failed to post single memory write") ;
6495
            disable main ;
6496
        end
6497
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6498
    end
6499
    begin
6500
        // wait two retries, then enable target response
6501
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6502
        if ( ok !== 1 )
6503
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6504
        else
6505
            test_ok ;
6506
 
6507
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6508
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6509
        if ( ok !== 1 )
6510
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6511
        else
6512
            test_ok ;
6513
 
6514
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6515
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6516
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6517
 
6518
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6519
        if ( ok !== 1 )
6520
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6521
        else
6522
            test_ok ;
6523
    end
6524
    join
6525
 
6526
    $display("Testing burst write transaction progress from WB to PCI!") ;
6527
    write_data`WRITE_ADDRESS = target_address ;
6528
    write_data`WRITE_DATA    = wmem_data[0] ;
6529
    write_data`WRITE_SEL     = 4'hF ;
6530
 
6531
    wishbone_master.blk_write_data[0] = write_data ;
6532
 
6533
    write_data`WRITE_ADDRESS = target_address + 4 ;
6534
    write_data`WRITE_DATA    = wmem_data[1] ;
6535
    write_data`WRITE_SEL     = 4'hF ;
6536
 
6537
    wishbone_master.blk_write_data[1] = write_data ;
6538
 
6539
    write_flags`WB_TRANSFER_SIZE = 2 ;
6540
    write_flags`WB_TRANSFER_CAB  = 1 ;
6541
 
6542
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6543
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6544
 
6545
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6546
 
6547
    fork
6548
    begin
6549
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6550
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6551
        begin
6552
            $display("Transaction progress testing failed! Time %t ", $time) ;
6553
            $display("Bridge failed to process whole CAB memory write!") ;
6554
            test_fail("bridge failed to post whole CAB memory write") ;
6555
            disable main ;
6556
        end
6557
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6558
    end
6559
    begin
6560
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6561
        if ( ok !== 1 )
6562
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6563
        else
6564
            test_ok ;
6565
 
6566
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6567
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6568
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6569
 
6570
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6571
        if ( ok !== 1 )
6572
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6573
        else
6574
            test_ok ;
6575
 
6576
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6577
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6578
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6579
 
6580
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6581
        if ( ok !== 1 )
6582
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6583
        else
6584
            test_ok ;
6585
    end
6586
    join
6587
 
6588
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6589
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6590
 
6591
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6592
    // try same write with other terminations
6593
    fork
6594
    begin
6595
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6596
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6597
        begin
6598
            $display("Transaction progress testing failed! Time %t ", $time) ;
6599
            $display("Bridge failed to process whole CAB memory write!") ;
6600
            test_fail("bridge failed to post whole CAB memory write") ;
6601
            disable main ;
6602
        end
6603
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6604
    end
6605
    begin
6606
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6607
        if ( ok !== 1 )
6608
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6609
        else
6610
            test_ok ;
6611
 
6612
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6613
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6614
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6615
 
6616
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6617
        if ( ok !== 1 )
6618
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6619
        else
6620
            test_ok ;
6621
    end
6622
    join
6623
 
6624
    // repeat the write with normal completion
6625
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6626
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6627
 
6628
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6629
    fork
6630
    begin
6631
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6632
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6633
        begin
6634
            $display("Transaction progress testing failed! Time %t ", $time) ;
6635
            $display("Bridge failed to process whole CAB memory write!") ;
6636
            test_fail("bridge failed to post whole CAB memory write") ;
6637
            disable main ;
6638
        end
6639
    end
6640
    begin
6641
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6642
        if ( ok !== 1 )
6643
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6644
        else
6645
            test_ok ;
6646
    end
6647
    join
6648
 
6649
    // do the same thing with burst length of 3
6650
    write_data`WRITE_ADDRESS = target_address + 8 ;
6651
    write_data`WRITE_DATA    = wmem_data[2] ;
6652
    write_data`WRITE_SEL     = 4'hF ;
6653
 
6654
    wishbone_master.blk_write_data[2] = write_data ;
6655
 
6656
    write_flags`WB_TRANSFER_SIZE = 3 ;
6657
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6658
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6659
 
6660
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6661
 
6662
    fork
6663
    begin
6664
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6665
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6666
        begin
6667
            $display("Transaction progress testing failed! Time %t ", $time) ;
6668
            $display("Bridge failed to process whole CAB memory write!") ;
6669
            test_fail("bridge failed to post whole CAB memory write") ;
6670
            disable main ;
6671
        end
6672
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6673
    end
6674
    begin
6675
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6676
        if ( ok !== 1 )
6677
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6678
        else
6679
            test_ok ;
6680
 
6681
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6682
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6683
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6684
 
6685
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6686
        if ( ok !== 1 )
6687
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6688
        else
6689
            test_ok ;
6690
    end
6691
    join
6692
 
6693
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6694
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6695
 
6696
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6697
    fork
6698
    begin
6699
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6700
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6701
        begin
6702
            $display("Transaction progress testing failed! Time %t ", $time) ;
6703
            $display("Bridge failed to process whole CAB memory write!") ;
6704
            test_fail("bridge failed to post whole CAB memory write") ;
6705
            disable main ;
6706
        end
6707
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6708
    end
6709
    begin
6710
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6711
        if ( ok !== 1 )
6712
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6713
        else
6714
            test_ok ;
6715
 
6716
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6717
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6718
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6719
 
6720
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6721
        if ( ok !== 1 )
6722
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6723
        else
6724
            test_ok ;
6725
 
6726
    end
6727
    join
6728
 
6729
    // repeat with normal completion
6730
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6731
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6732
 
6733
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6734
    fork
6735
    begin
6736
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6737
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6738
        begin
6739
            $display("Transaction progress testing failed! Time %t ", $time) ;
6740
            $display("Bridge failed to process whole CAB memory write!") ;
6741
            test_fail("bridge failed to post whole CAB memory write") ;
6742
            disable main ;
6743
        end
6744
    end
6745
    begin
6746
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6747
        if ( ok !== 1 )
6748
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6749
        else
6750
            test_ok ;
6751
 
6752
    end
6753
    join
6754
 
6755
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6756
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6757
    begin
6758
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6759
        write_data`WRITE_DATA    = wmem_data[i] ;
6760
        write_data`WRITE_SEL     = 4'hF ;
6761
 
6762
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6763
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6764
 
6765
        wishbone_master.blk_write_data[i]   = write_data ;
6766
        wishbone_master.blk_read_data_in[i] = read_data ;
6767
    end
6768
 
6769
    write_flags`WB_TRANSFER_CAB      = 1 ;
6770
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6771
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6772
 
6773
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6774
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6775
 
6776
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6777
    fork
6778
    begin
6779
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6780
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6781
        begin
6782
            $display("Transaction progress testing failed! Time %t ", $time) ;
6783
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6784
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6785
            test_fail("bridge failed to post whole CAB memory write") ;
6786
            disable main ;
6787
        end
6788
 
6789
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6790
 
6791
        // read here just checks if data was transfered OK
6792
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6793
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6794
 
6795
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6796
 
6797
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6798
        begin
6799
            $display("Transaction progress testing failed! Time %t ", $time) ;
6800
            $display("Bridge processed CAB read wrong!") ;
6801
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6802
        end
6803
 
6804
    end
6805
    begin
6806
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6807
        if ( ok !== 1 )
6808
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6809
        else
6810
            test_ok ;
6811
 
6812
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6813
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6814
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6815
 
6816
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6817
        if ( ok !== 1 )
6818
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6819
        else
6820
            test_ok ;
6821
 
6822
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6823
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6824
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6825
 
6826
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6827
        if ( ok !== 1 )
6828
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6829
        else
6830
            test_ok ;
6831
 
6832
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6833
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6834
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6835
 
6836
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6837
        if ( ok !== 1 )
6838
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6839
        else
6840
            test_ok ;
6841
 
6842
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6843
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6844
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6845
 
6846
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6847
        if ( ok !== 1 )
6848
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6849
        else
6850
            test_ok ;
6851
 
6852
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6853
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6854
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6855
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6856
        begin
6857
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6858
            if ( ok !== 1 )
6859
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6860
        end
6861
    end
6862
    join
6863
 
6864
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6865
    begin
6866
        read_status = wishbone_master.blk_read_data_out[i] ;
6867
        if (read_status`READ_DATA !== wmem_data[i])
6868
        begin
6869
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6870
            test_fail("data read from target wasn't the same as data written to it") ;
6871
            ok = 0 ;
6872
        end
6873
    end
6874
 
6875
    if ( ok )
6876
        test_ok ;
6877
 
6878
    $display("Testing single read transaction progress from WB to PCI!") ;
6879
    read_data`READ_ADDRESS = target_address + 8 ;
6880
    read_data`READ_SEL     = 4'hF ;
6881
 
6882
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6883
 
6884
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6885
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6886
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6887
 
6888
    fork
6889
    begin
6890
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6891
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6892
        begin
6893
            $display("Transaction progress testing failed! Time %t ", $time) ;
6894
            $display("Bridge processed single read wrong!") ;
6895
            test_fail("bridge processed single read wrong") ;
6896
            disable main ;
6897
        end
6898
 
6899
        if (read_status`READ_DATA !== wmem_data[2])
6900
        begin
6901
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6902
            test_fail("data returned from single read was not as expected") ;
6903
        end
6904
        else
6905
        if ( ok )
6906
            test_ok ;
6907
    end
6908
    begin
6909
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
6910
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6911
 
6912
        if ( ok !== 1 )
6913
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6914
 
6915
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
6916
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6917
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6918
 
6919
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6920
        if ( ok !== 1 )
6921
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6922
    end
6923
    join
6924
 
6925
    $display("Testing CAB read transaction progress from WB to PCI!") ;
6926
 
6927
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6928
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6929
 
6930
    test_name = "FILL TARGET MEMORY WITH DATA" ;
6931
    // first fill target's memory with enough data to fill WBR_FIFO
6932
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
6933
    begin
6934
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6935
        write_data`WRITE_DATA    = wmem_data[i] ;
6936
        write_data`WRITE_SEL     = 4'hF ;
6937
 
6938
        wishbone_master.blk_write_data[i] = write_data ;
6939
    end
6940
 
6941
    write_flags`WB_TRANSFER_CAB = 1 ;
6942
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6943
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
6944
 
6945
    wishbone_master.wb_block_write( write_flags, write_status ) ;
6946
 
6947
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
6948
    begin
6949
        $display("Transaction progress testing failed! Time %t ", $time) ;
6950
        $display("Bridge processed CAB write wrong!") ;
6951
        test_fail("bridge didn't process all the writes as it was supposed too") ;
6952
        disable main ;
6953
    end
6954
 
6955
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
6956
    // perform single read to force write data to pci
6957
    read_data`READ_ADDRESS = target_address + 8;
6958
    read_data`READ_SEL     = 4'hF ;
6959
 
6960
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6961
 
6962
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6963
    begin
6964
        $display("Transaction progress testing failed! Time %t ", $time) ;
6965
        $display("Bridge processed single read wrong!") ;
6966
        test_fail("bridge didn't process single memory read as expected") ;
6967
        disable main ;
6968
    end
6969
 
6970
    wishbone_master.blk_read_data_in[0] = read_data ;
6971
 
6972
    read_data`READ_ADDRESS = target_address + 12 ;
6973
    read_data`READ_SEL     = 4'hF ;
6974
 
6975
    wishbone_master.blk_read_data_in[1] = read_data ;
6976
 
6977
    read_data`READ_ADDRESS = target_address + 16 ;
6978
    read_data`READ_SEL     = 4'hF ;
6979
 
6980
    wishbone_master.blk_read_data_in[2] = read_data ;
6981
 
6982
    write_flags`WB_TRANSFER_CAB  = 1 ;
6983
    write_flags`WB_TRANSFER_SIZE = 2 ;
6984
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6985
    read_status = 0 ;
6986
 
6987
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6988
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6989
 
6990
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
6991
 
6992
    ok = 1 ;
6993
    fork
6994
    begin
6995
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
6996
            wishbone_master.wb_block_read( write_flags, read_status ) ;
6997
 
6998
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6999
        begin
7000
            $display("Transaction progress testing failed! Time %t ", $time) ;
7001
            $display("Bridge processed CAB read wrong!") ;
7002
            test_fail("bridge didn't process disconnected burst read as expected") ;
7003
        end
7004
        else
7005
        begin
7006
 
7007
            read_status = wishbone_master.blk_read_data_out[0] ;
7008
 
7009
            if (read_status`READ_DATA !== wmem_data[2])
7010
            begin
7011
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7012
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7013
            end
7014
            else
7015
                test_ok ;
7016
        end
7017
 
7018
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7019
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7020
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7021
 
7022
        read_status = 0 ;
7023
 
7024
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7025
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7026
 
7027
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7028
        begin
7029
            $display("Transaction progress testing failed! Time %t ", $time) ;
7030
            $display("Bridge processed CAB read wrong!") ;
7031
            test_fail("bridge didn't process disconnected burst read as expected") ;
7032
        end
7033
        else
7034
        begin
7035
 
7036
            read_status = wishbone_master.blk_read_data_out[0] ;
7037
 
7038
            if (read_status`READ_DATA !== wmem_data[3])
7039
            begin
7040
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7041
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7042
            end
7043
            else
7044
                test_ok ;
7045
        end
7046
 
7047
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7048
        // complete delayed read which was requested
7049
        read_data = wishbone_master.blk_read_data_in[2] ;
7050
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7051
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7052
 
7053
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7054
        begin
7055
            $display("Transaction progress testing failed! Time %t ", $time) ;
7056
            $display("Bridge processed single out of burst read wrong!") ;
7057
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7058
        end
7059
        else
7060
        begin
7061
 
7062
            if (read_status`READ_DATA !== wmem_data[4])
7063
            begin
7064
                display_warning(target_address + 16, wmem_data[4], 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
    end
7072
    begin
7073
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7074
 
7075
        if ( ok !== 1 )
7076
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7077
 
7078
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7079
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7080
 
7081
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7082
        if ( ok !== 1 )
7083
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7084
 
7085
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7086
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7087
 
7088
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7089
        if ( ok !== 1 )
7090
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7091
    end
7092
    join
7093
 
7094
    // now try burst read with normal termination
7095
    read_data`READ_ADDRESS = target_address + 12 ;
7096
    read_data`READ_SEL     = 4'hF ;
7097
 
7098
    wishbone_master.blk_read_data_in[0] = read_data ;
7099
 
7100
    read_data`READ_ADDRESS = target_address + 16 ;
7101
    read_data`READ_SEL     = 4'hF ;
7102
 
7103
    wishbone_master.blk_read_data_in[1] = read_data ;
7104
 
7105
    write_flags`WB_TRANSFER_SIZE = 2 ;
7106
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7107
    write_flags`WB_TRANSFER_CAB = 1 ;
7108
 
7109
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7110
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7111
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7112
 
7113
    fork
7114
    begin
7115
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7116
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7117
        begin
7118
            $display("Transaction progress testing failed! Time %t ", $time) ;
7119
            $display("Bridge processed CAB read wrong!") ;
7120
            test_fail("bridge didn't process burst read as expected") ;
7121
            ok = 0 ;
7122
        end
7123
    end
7124
    begin
7125
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7126
        if ( ok !== 1 )
7127
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7128
    end
7129
    join
7130
 
7131
    if ( ok )
7132
    begin
7133
        read_status = wishbone_master.blk_read_data_out[0] ;
7134
        if ( read_status`READ_DATA !== wmem_data[3] )
7135
        begin
7136
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7137
            test_fail("data provided from normaly terminated read was wrong") ;
7138
            ok = 0 ;
7139
        end
7140
 
7141
        read_status = wishbone_master.blk_read_data_out[1] ;
7142
        if ( read_status`READ_DATA !== wmem_data[4] )
7143
        begin
7144
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7145
            test_fail("data provided from normaly terminated read was wrong") ;
7146
            ok = 0 ;
7147
        end
7148
    end
7149
 
7150
    if ( ok )
7151
        test_ok ;
7152
 
7153
    // disable memory read line command and enable prefetch
7154
    // prepare image control register
7155
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7156
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7157
    if ( ok !== 1 )
7158
    begin
7159
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7160
        test_fail("WB Image Control register couldn't be written to") ;
7161
        disable main ;
7162
    end
7163
 
7164
    write_flags`WB_TRANSFER_SIZE = 4 ;
7165
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7166
    write_flags`WB_TRANSFER_CAB = 1 ;
7167
 
7168
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7169
 
7170
    for ( i = 0 ; i < 4 ; i = i + 1 )
7171
    begin
7172
        read_data`READ_ADDRESS = target_address + i*4 ;
7173
        read_data`READ_SEL     = 4'b1010 ;
7174
 
7175
        wishbone_master.blk_read_data_in[i] = read_data ;
7176
    end
7177
 
7178
    fork
7179
    begin
7180
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7181
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7182
        begin
7183
            $display("Transaction progress testing failed! Time %t ", $time) ;
7184
            $display("Bridge processed CAB read wrong!") ;
7185
            test_fail("bridge didn't process prefetched burst read as expected") ;
7186
            ok = 0 ;
7187
        end
7188
    end
7189
    begin
7190
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7191
        if ( ok !== 1 )
7192
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7193
    end
7194
    join
7195
 
7196
    if ( ok )
7197
    begin
7198
        for ( i = 0 ; i < 4 ; i = i + 1 )
7199
        begin
7200
            read_status = wishbone_master.blk_read_data_out[i] ;
7201
            if ( read_status`READ_DATA !== wmem_data[i] )
7202
            begin
7203
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7204
                test_fail("burst read returned unexpected data") ;
7205
                ok = 0 ;
7206
            end
7207
        end
7208
    end
7209
 
7210
    if ( ok )
7211
        test_ok ;
7212
 
7213
    // do one single read with different byte enables
7214
    read_data`READ_ADDRESS = target_address + 4 ;
7215
    read_data`READ_SEL     = 4'b1010 ;
7216
 
7217
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7218
    fork
7219
    begin
7220
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7221
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7222
        begin
7223
            $display("Transaction progress testing failed! Time %t ", $time) ;
7224
            $display("Bridge processed single read wrong!") ;
7225
            test_fail("bridge didn't process single memory read as expected") ;
7226
            ok = 0 ;
7227
        end
7228
    end
7229
    begin
7230
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7231
        if ( ok !== 1 )
7232
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7233
    end
7234
    join
7235
 
7236
    // check read data
7237
    if ( ok )
7238
    begin
7239
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7240
        begin
7241
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7242
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7243
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7244
            ok = 0 ;
7245
            test_fail("unexpected data received from single read") ;
7246
        end
7247
    end
7248
 
7249
    if ( ok )
7250
         test_ok ;
7251
 
7252
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7253
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7254
 
7255
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7256
    if ( ok !== 1 )
7257
    begin
7258
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7259
        test_fail("WB Image Control register could not be written") ;
7260
        disable main ;
7261
    end
7262
 
7263
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7264
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7265
    begin
7266
        read_data`READ_ADDRESS = target_address + i*4 ;
7267
        read_data`READ_SEL     = 4'b1111 ;
7268
 
7269
        wishbone_master.blk_read_data_in[i] = read_data ;
7270
    end
7271
 
7272
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7273
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7274
    write_flags`WB_TRANSFER_CAB = 1 ;
7275
 
7276
    fork
7277
    begin
7278
        read_status         = 0 ;
7279
        read_status`CYC_RTY = 1 ;
7280
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7281
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7282
 
7283
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7284
        begin
7285
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7286
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7287
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7288
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7289
            ok = 0 ;
7290
        end
7291
    end
7292
    begin
7293
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7294
        if ( ok !== 1 )
7295
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7296
    end
7297
    join
7298
 
7299
    // now repeat single read to flush redundant read initiated
7300
    write_flags`WB_TRANSFER_SIZE = 1 ;
7301
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7302
    write_flags`WB_TRANSFER_CAB = 1 ;
7303
 
7304
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7305
    read_data`READ_SEL     = 4'hF ;
7306
 
7307
    wishbone_master.blk_read_data_in[0] = read_data ;
7308
 
7309
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7310
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7311
 
7312
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7313
    begin
7314
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7315
        $display(" PCI bridge failed to process single CAB read!") ;
7316
        test_fail("single CAB write was not processed as expected") ;
7317
    end
7318
 
7319
    // because last read could be very long on PCI - delete target abort status
7320
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7321
 
7322
    // write unsupported value to cache line size register
7323
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7324
 
7325
    read_data`READ_ADDRESS = target_address ;
7326
    read_data`READ_SEL     = 4'hF ;
7327
    wishbone_master.blk_read_data_in[0] = read_data ;
7328
 
7329
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7330
    // perform a read
7331
    fork
7332
    begin
7333
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7334
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7335
        begin
7336
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7337
            $display(" PCI bridge failed to process single CAB read!") ;
7338
            test_fail("burst read was not processed as expected") ;
7339
            ok = 0 ;
7340
        end
7341
    end
7342
    begin
7343
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7344
        if ( ok !== 1 )
7345
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7346
    end
7347
    join
7348
 
7349
    if ( ok )
7350
        test_ok ;
7351
 
7352
    // write 2 to cache line size register
7353
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7354
 
7355
    // perform a read
7356
    fork
7357
    begin
7358
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7359
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7360
        begin
7361
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7362
            $display(" PCI bridge failed to process single CAB read!") ;
7363
            test_fail("burst read was not processed as expected") ;
7364
            ok = 0 ;
7365
        end
7366
    end
7367
    begin
7368
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7369
        if ( ok !== 1 )
7370
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7371
    end
7372
    join
7373
 
7374
    if ( ok )
7375
        test_ok ;
7376
 
7377
    // write 0 to cache line size
7378
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7379
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7380
 
7381
    // perform a read
7382
    fork
7383
    begin
7384
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7385
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7386
        begin
7387
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7388
            $display(" PCI bridge failed to process single CAB read!") ;
7389
            test_fail("burst read was not processed as expected") ;
7390
            ok = 0 ;
7391
        end
7392
    end
7393
    begin
7394
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7395
        if ( ok !== 1 )
7396
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7397
    end
7398
    join
7399
 
7400
    if ( ok )
7401
        test_ok ;
7402
 
7403
    // write normal value to cls register
7404
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7405
 
7406
    $display("Testing Master's latency timer operation!") ;
7407
    $display("Testing Latency timer during Master Writes!") ;
7408
 
7409
    for ( i = 0 ; i < 6 ; i = i + 1 )
7410
    begin
7411
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7412
        write_data`WRITE_SEL     = 4'b1111 ;
7413
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7414
 
7415
        wishbone_master.blk_write_data[i] = write_data ;
7416
    end
7417
 
7418
    write_flags`WB_TRANSFER_SIZE = 6 ;
7419
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7420
    write_flags`WB_TRANSFER_CAB = 1 ;
7421
 
7422
    // start wb write, pci write and monitor in parallel
7423
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7424
    fork
7425
    begin
7426
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7427
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7428
        begin
7429
            $display("Transaction progress testing failed! Time %t ", $time) ;
7430
            $display("Bridge failed to process CAB write!") ;
7431
            test_fail("bridge didn't post whole burst memory write") ;
7432
            disable main ;
7433
        end
7434
    end
7435
    begin
7436
        // wait for bridge's master to start transaction
7437
        @(posedge pci_clock) ;
7438
        while ( FRAME === 1 )
7439
            @(posedge pci_clock) ;
7440
 
7441
        // start behavioral master request
7442
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7443
               target_address, wmem_data[1023], `Test_All_Bytes,
7444
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7445
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7446
 
7447
        do_pause ( 1 ) ;
7448
    end
7449
    begin
7450
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7451
        if ( ok !== 1 )
7452
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7453
        else
7454
            test_ok ;
7455
    end
7456
    join
7457
 
7458
    // perform a read to check data
7459
    for ( i = 0 ; i < 6 ; i = i + 1 )
7460
    begin
7461
        read_data`READ_ADDRESS = target_address + i*4 ;
7462
        read_data`READ_SEL     = 4'b1111 ;
7463
 
7464
        wishbone_master.blk_read_data_in[i] = read_data ;
7465
    end
7466
 
7467
    write_flags`WB_TRANSFER_SIZE = 6 ;
7468
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7469
    write_flags`WB_TRANSFER_CAB = 1 ;
7470
 
7471
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7472
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7473
 
7474
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7475
    begin
7476
        $display("Transaction progress testing failed! Time %t ", $time) ;
7477
        $display("Bridge failed to process CAB read!") ;
7478
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7479
        disable main ;
7480
    end
7481
 
7482
    ok = 1 ;
7483
    for ( i = 0 ; i < 6 ; i = i + 1 )
7484
    begin
7485
        read_status = wishbone_master.blk_read_data_out[i] ;
7486
 
7487
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7488
        begin
7489
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7490
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7491
            test_fail("unexpected data read back from PCI") ;
7492
            ok = 0 ;
7493
        end
7494
    end
7495
 
7496
    if ( ok )
7497
        test_ok ;
7498
 
7499
    $display("Testing Latency timer during Master Reads!") ;
7500
 
7501
    // at least 2 words are transfered during Master Reads terminated with timeout
7502
    write_flags`WB_TRANSFER_SIZE = 2 ;
7503
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7504
    fork
7505
    begin
7506
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7507
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7508
        begin
7509
            $display("Transaction progress testing failed! Time %t ", $time) ;
7510
            $display("Bridge failed to process CAB read!") ;
7511
            test_fail("bridge didn't process burst read as expected") ;
7512
            ok = 0 ;
7513
        end
7514
    end
7515
    begin
7516
        // wait for bridge's master to start transaction
7517
        @(posedge pci_clock) ;
7518
        while ( FRAME === 1 )
7519
            @(posedge pci_clock) ;
7520
 
7521
        // start behavioral master request
7522
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7523
               target_address, wmem_data[0], `Test_All_Bytes,
7524
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7525
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7526
 
7527
        do_pause ( 1 ) ;
7528
    end
7529
    begin
7530
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7531
        if ( ok !== 1 )
7532
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7533
    end
7534
    join
7535
 
7536
    // check data provided by target
7537
    if ( ok )
7538
    begin
7539
        for ( i = 0 ; i < 2 ; i = i + 1 )
7540
        begin
7541
            read_status = wishbone_master.blk_read_data_out[i] ;
7542
 
7543
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7544
            begin
7545
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7546
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7547
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7548
                ok = 0 ;
7549
            end
7550
        end
7551
    end
7552
    if ( ok )
7553
        test_ok ;
7554
 
7555
    test_name = "DISABLE_IMAGE" ;
7556
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7557
    if ( ok !== 1 )
7558
    begin
7559
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7560
        test_fail("write to WB Address Mask register failed") ;
7561
        disable main ;
7562
    end
7563
 
7564
end
7565
endtask //wb_to_pci_transactions
7566
 
7567
task iack_cycle ;
7568
    reg `READ_STIM_TYPE   read_data ;
7569
    reg `READ_RETURN_TYPE read_status ;
7570
    reg `WB_TRANSFER_FLAGS flags ;
7571
 
7572
    reg [31:0] temp_var ;
7573
    reg ok ;
7574
begin
7575
 
7576
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7577
 
7578
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7579
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7580
 
7581
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7582
    read_data`READ_SEL     = 4'hF ;
7583
 
7584
    flags = 0 ;
7585
 
7586
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7587
 
7588
    irq_respond = 0 ;
7589
    irq_vector  = 32'hAAAA_AAAA ;
7590
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7591
 
7592
    fork
7593
    begin
7594
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7595
    end
7596
    begin
7597
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok) ;
7598
        if ( ok !== 1 )
7599
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7600
    end
7601
    join
7602
 
7603
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7604
    begin
7605
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7606
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7607
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7608
    end
7609
    else
7610
    if ( ok )
7611
        test_ok ;
7612
        // clearing the status bits
7613
        config_write(12'h4, 32'hFFFF_0000, 4'hC, ok);
7614
 
7615
    irq_respond = 1 ;
7616
    irq_vector  = 32'h5555_5555 ;
7617
 
7618
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7619
    fork
7620
    begin
7621
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7622
    end
7623
    begin
7624
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7625
        if ( ok !== 1 )
7626
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7627
    end
7628
    join
7629
 
7630
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7631
    begin
7632
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7633
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7634
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7635
        ok = 0 ;
7636
    end
7637
 
7638
    if ( read_status`READ_DATA !== irq_vector )
7639
    begin
7640
        $display(" Time %t ", $time ) ;
7641
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7642
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7643
        ok = 0 ;
7644
    end
7645
 
7646
    if ( ok )
7647
        test_ok ;
7648
 
7649
    read_data`READ_SEL = 4'b0101 ;
7650
    irq_vector  = 32'hAAAA_AAAA ;
7651
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7652
    fork
7653
    begin
7654
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7655
    end
7656
    begin
7657
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7658
        if ( ok !== 1 )
7659
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7660
    end
7661
    join
7662
 
7663
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7664
    begin
7665
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7666
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7667
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7668
        ok = 0 ;
7669
    end
7670
 
7671
    if ( read_status`READ_DATA !== 32'h00AA_00AA )
7672
    begin
7673
        $display(" Time %t ", $time ) ;
7674
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h00AA_00AA, read_status`READ_DATA ) ;
7675
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7676
        ok = 0 ;
7677
    end
7678
 
7679
    if ( ok )
7680
        test_ok ;
7681
 
7682
 
7683
end
7684
endtask //iack_cycle
7685
 
7686
task transaction_ordering ;
7687
    reg   [11:0] wb_ctrl_offset ;
7688
    reg   [11:0] wb_ba_offset ;
7689
    reg   [11:0] wb_am_offset ;
7690
    reg   [11:0] pci_ctrl_offset ;
7691
    reg   [11:0] pci_ba_offset ;
7692
    reg   [11:0] pci_am_offset ;
7693
    reg   [11:0] pci_device_ctrl_offset ;
7694
    reg   [11:0] wb_err_cs_offset ;
7695
    reg   [11:0] pci_err_cs_offset ;
7696
    reg   [11:0] icr_offset ;
7697
    reg   [11:0] isr_offset ;
7698
    reg   [11:0] lat_tim_cls_offset ;
7699
 
7700
    reg `WRITE_STIM_TYPE  write_data ;
7701
    reg `READ_STIM_TYPE   read_data ;
7702
    reg `READ_RETURN_TYPE read_status ;
7703
 
7704
    reg `WRITE_RETURN_TYPE write_status ;
7705
    reg `WB_TRANSFER_FLAGS write_flags ;
7706
    reg [31:0] temp_val1 ;
7707
    reg [31:0] temp_val2 ;
7708
    reg        ok   ;
7709
 
7710
    reg [31:0] wb_image_base ;
7711
    reg [31:0] wb_target_address ;
7712
    reg [31:0] pci_image_base ;
7713
    integer i ;
7714
 
7715
    reg     error_monitor_done ;
7716
begin:main
7717
    write_flags`INIT_WAITS = tb_init_waits ;
7718
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7719
 
7720
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7721
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7722
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7723
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7724
 
7725
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7726
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7727
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7728
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7729
 
7730
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7731
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7732
    lat_tim_cls_offset = 12'hC ;
7733
    pci_device_ctrl_offset    = 12'h4 ;
7734
 
7735
    wb_target_address  = `BEH_TAR1_MEM_START ;
7736
    wb_image_base      = 0 ;
7737
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7738
 
7739
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7740
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7741
    write_flags                    = 0 ;
7742
    write_flags`INIT_WAITS         = 0 ;
7743
    write_flags`SUBSEQ_WAITS       = 0 ;
7744
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7745
 
7746
    pci_image_base = Target_Base_Addr_R[1] ;
7747
 
7748
    // enable master & target operation
7749
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7750
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7751
    if ( ok !== 1 )
7752
    begin
7753
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7754
        test_fail("write to PCI Device Control register failed") ;
7755
        disable main ;
7756
    end
7757
 
7758
    // prepare image control register
7759
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7760
    if ( ok !== 1 )
7761
    begin
7762
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7763
        test_fail("write to WB Image Control register failed") ;
7764
        disable main ;
7765
    end
7766
 
7767
    // prepare base address register
7768
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7769
    if ( ok !== 1 )
7770
    begin
7771
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7772
        test_fail("write to WB Base Address register failed") ;
7773
        disable main ;
7774
    end
7775
 
7776
    // write address mask register
7777
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7778
    if ( ok !== 1 )
7779
    begin
7780
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7781
        test_fail("write to WB Address Mask register failed") ;
7782
        disable main ;
7783
    end
7784
 
7785
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7786
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7787
    if ( ok !== 1 )
7788
    begin
7789
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
7790
        test_fail("write to WB Error Control and Status register failed") ;
7791
        disable main ;
7792
    end
7793
 
7794
    // prepare image control register
7795
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7796
    if ( ok !== 1 )
7797
    begin
7798
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
7799
        test_fail("write to PCI Image Control register failed") ;
7800
        disable main ;
7801
    end
7802
 
7803
    // prepare base address register
7804
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
7805
    if ( ok !== 1 )
7806
    begin
7807
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
7808
        test_fail("write to PCI Base Address register failed") ;
7809
        disable main ;
7810
    end
7811
 
7812
    // write address mask register
7813
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7814
    if ( ok !== 1 )
7815
    begin
7816
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
7817
        test_fail("write to PCI Address Mask register failed") ;
7818
        disable main ;
7819
    end
7820
 
7821
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7822
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7823
    if ( ok !== 1 )
7824
    begin
7825
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
7826
        test_fail("write to PCI Error Control and Status register failed") ;
7827
        disable main ;
7828
    end
7829
 
7830
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
7831
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7832
    if ( ok !== 1 )
7833
    begin
7834
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
7835
        test_fail("write to Interrupt Control register failed") ;
7836
        disable main ;
7837
    end
7838
 
7839
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
7840
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
7841
    if ( ok !== 1 )
7842
    begin
7843
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
7844
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
7845
        disable main ;
7846
    end
7847
 
7848
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
7849
 
7850
    // prepare wb_master write and read data
7851
    for ( i = 0 ; i < 4 ; i = i + 1 )
7852
    begin
7853
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
7854
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
7855
        write_data`WRITE_SEL     = 4'hF ;
7856
 
7857
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
7858
        read_data`READ_SEL       = write_data`WRITE_SEL ;
7859
 
7860
        wishbone_master.blk_write_data[i]   = write_data ;
7861
        wishbone_master.blk_read_data_in[i] = read_data ;
7862
    end
7863
 
7864
    // put wishbone slave in acknowledge and pci target in retry mode
7865
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
7866
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7867
 
7868
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7869
 
7870
    fork
7871
    begin
7872
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7873
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7874
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7875
        begin
7876
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7877
            test_fail("Bridge didn't post single memory write as expected") ;
7878
        end
7879
 
7880
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7881
        if ( ok !== 1 )
7882
        begin
7883
            $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) ;
7884
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7885
            ok = 0 ;
7886
        end
7887
 
7888
        // now post single write to target - normal progress
7889
        if ( target_mem_image == 1 )
7890
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7891
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7892
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7893
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7894
        else
7895
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7896
 
7897
        do_pause( 1 ) ;
7898
 
7899
    end
7900
    begin:error_monitor_1
7901
        @(error_event_int) ;
7902
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7903
        ok = 0 ;
7904
    end
7905
    begin
7906
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7907
        if ( ok !== 1 )
7908
        begin
7909
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7910
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7911
        end
7912
        else
7913
        begin
7914 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7915
//            while ( FRAME === 0 || IRDY === 0 )
7916
//                @(posedge pci_clock) ;
7917 15 mihad
 
7918
            // enable response in PCI target
7919
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
7920
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7921
 
7922
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7923
            if ( ok !== 1 )
7924
            begin
7925
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
7926
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
7927
            end
7928
        end
7929
 
7930
        disable error_monitor_1 ;
7931
    end
7932
    join
7933
 
7934
    if ( ok )
7935
        test_ok ;
7936
 
7937
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
7938
 
7939
    // put WISHBONE slave in retry mode
7940
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
7941
 
7942
    fork
7943
    begin
7944
        // now post single write to target - normal progress
7945
        if ( target_mem_image == 1 )
7946
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7947
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7948
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7949
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7950
        else
7951
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7952
 
7953
        do_pause( 1 ) ;
7954
 
7955
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
7956
        if ( ok !== 1 )
7957
        begin
7958
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
7959
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
7960
        end
7961
 
7962
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7963
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7964
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7965
        begin
7966
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7967
            test_fail("Bridge didn't post single memory write as expected") ;
7968
        end
7969
 
7970
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7971
        if ( ok !== 1 )
7972
        begin
7973
            $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) ;
7974
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7975
            ok = 0 ;
7976
        end
7977
 
7978
        wait ( CYC_O === 0 ) ;
7979
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7980
 
7981
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7982
        if ( ok !== 1 )
7983
        begin
7984
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7985
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7986
        end
7987
 
7988
        disable error_monitor_2 ;
7989
    end
7990
    begin:error_monitor_2
7991
        @(error_event_int) ;
7992
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7993
        ok = 0 ;
7994
    end
7995
    join
7996
 
7997
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
7998
 
7999
    // put wishbone slave in acknowledge and pci target in retry mode
8000
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8001
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8002
 
8003
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8004
 
8005
    fork
8006
    begin
8007
        write_flags`WB_TRANSFER_SIZE = 3 ;
8008
        write_flags`WB_TRANSFER_CAB  = 1 ;
8009
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8010
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8011
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8012
        begin
8013
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8014
            test_fail("Bridge didn't post burst memory write as expected") ;
8015
        end
8016
 
8017
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8018
        if ( ok !== 1 )
8019
        begin
8020
            $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) ;
8021
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8022
            ok = 0 ;
8023
        end
8024
 
8025
        // now post single write to target - normal progress
8026
        if ( target_mem_image == 1 )
8027
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8028
                        pci_image_base, 32'h5555_5555, 4'h0,
8029
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8030
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8031
        else
8032
        begin
8033
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8034
            do_pause( 1 ) ;
8035
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8036
        end
8037
 
8038
        do_pause( 1 ) ;
8039
 
8040
    end
8041
    begin:error_monitor_3
8042
        @(error_event_int) ;
8043
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8044
        ok = 0 ;
8045
    end
8046
    begin
8047
        if ( target_mem_image == 1 )
8048
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8049
        else
8050
        begin
8051
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8052
            if ( ok )
8053
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8054
        end
8055
 
8056
        if ( ok !== 1 )
8057
        begin
8058
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8059
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8060
        end
8061
        else
8062
        begin
8063 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8064
//            while ( FRAME === 0 || IRDY === 0 )
8065
//                @(posedge pci_clock) ;
8066 15 mihad
 
8067
            // enable response in PCI target
8068
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8069
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8070
 
8071
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8072
            if ( ok !== 1 )
8073
            begin
8074
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8075
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8076
            end
8077
        end
8078
 
8079
        disable error_monitor_3 ;
8080
    end
8081
    join
8082
 
8083
    if ( ok )
8084
        test_ok ;
8085
 
8086
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8087
 
8088
    // put WISHBONE slave in retry mode
8089
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8090
 
8091
    fork
8092
    begin
8093
        // now post single write to target - normal progress
8094
        if ( target_mem_image == 1 )
8095
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8096
                        pci_image_base, 32'h5555_5555, 4'h0,
8097
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8098
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8099
        else
8100
        begin
8101
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8102
            do_pause( 1 ) ;
8103
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8104
        end
8105
 
8106
        do_pause( 1 ) ;
8107
 
8108
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8109
 
8110
        if ( ok !== 1 )
8111
        begin
8112
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8113
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8114
        end
8115
 
8116
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8117
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8118
        write_flags`WB_TRANSFER_CAB      = 1 ;
8119
 
8120
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8121
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8122
        begin
8123
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8124
            test_fail("Bridge didn't post burst memory write as expected") ;
8125
        end
8126
 
8127
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8128
        if ( ok !== 1 )
8129
        begin
8130
            $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) ;
8131
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8132
            ok = 0 ;
8133
        end
8134
 
8135
        @(posedge wb_clock) ;
8136
        while ( CYC_O === 1 )
8137
            @(posedge wb_clock) ;
8138
 
8139
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8140
 
8141
        if ( target_mem_image == 1 )
8142
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8143
        else
8144
        begin
8145
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8146
            if ( ok )
8147
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8148
        end
8149
 
8150
 
8151
        disable error_monitor_4 ;
8152
    end
8153
    begin:error_monitor_4
8154
        @(error_event_int) ;
8155
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8156
        ok = 0 ;
8157
    end
8158
    join
8159
 
8160
    if ( ok )
8161
        test_ok ;
8162
 
8163
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8164
 
8165
    // put wishbone slave in acknowledge and pci target in retry mode
8166
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8167
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8168
 
8169
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8170
 
8171
    master1_check_received_data = 1 ;
8172
 
8173
    error_monitor_done = 0 ;
8174
    fork
8175
    begin:error_monitor_5
8176
        @(error_event_int or error_monitor_done) ;
8177
        if ( !error_monitor_done )
8178
        begin
8179
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8180
            ok = 0 ;
8181
        end
8182
    end
8183
    begin
8184
 
8185
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8186
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8187
        begin
8188
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8189
            test_fail("Bridge didn't post single memory write as expected") ;
8190
        end
8191
 
8192
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8193
        if ( ok !== 1 )
8194
        begin
8195
            $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) ;
8196
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8197
            ok = 0 ;
8198
        end
8199
 
8200
        // start Read Through pci target
8201
        if ( target_mem_image == 1 )
8202
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8203
                          pci_image_base, 32'h5555_5555,
8204
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8205
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8206
        else
8207
            PCIU_IO_READ
8208
             (
8209
                `Test_Master_1,
8210
                pci_image_base,
8211
                32'h5555_5555,
8212
                4'h0,
8213
                1,
8214
                `Test_Target_Retry_On
8215
             );
8216
 
8217
         do_pause( 1 ) ;
8218
 
8219
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8220
         if ( ok !== 1 )
8221
         begin
8222
            $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) ;
8223
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8224
         end
8225
 
8226
         // repeat the read 4 times - it should be retried all the time by pci target
8227
        for ( i = 0 ; i < 4 ; i = i + 1 )
8228
        begin
8229
            if ( target_mem_image == 1 )
8230
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8231
                            pci_image_base, 32'h5555_5555,
8232
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8233
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8234
            else
8235
                PCIU_IO_READ
8236
                (
8237
                    `Test_Master_1,
8238
                    pci_image_base,
8239
                    32'h5555_5555,
8240
                    4'h0,
8241
                    1,
8242
                    `Test_Target_Retry_On
8243
                );
8244
 
8245
            do_pause( 1 ) ;
8246
        end
8247
 
8248
        // now do posted write through target - it must go through OK
8249
        if ( target_mem_image == 1 )
8250
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8251
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8252
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8253
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8254
        else
8255
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8256
 
8257
        do_pause( 1 ) ;
8258
 
8259
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8260
        if ( ok !== 1 )
8261
        begin
8262
           $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) ;
8263
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8264
        end
8265
 
8266
        // start a read through wb_slave
8267
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8268
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8269
        begin
8270
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8271
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8272
            ok = 0 ;
8273
        end
8274
 
8275 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8276
//        while ( FRAME === 0 || IRDY === 0 )
8277
//            @(posedge pci_clock) ;
8278 15 mihad
 
8279
        // set the target to normal completion
8280
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8281
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8282
 
8283
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8284
        if ( ok !== 1 )
8285
        begin
8286
            $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) ;
8287
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8288
            ok = 0 ;
8289
        end
8290
 
8291
        // now wait for delayed read to finish
8292
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8293
        if ( ok !== 1 )
8294
        begin
8295
            $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) ;
8296
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8297
            ok = 0 ;
8298
        end
8299
 
8300
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8301
        fork
8302
        begin
8303
                if ( target_mem_image == 1 )
8304
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8305
                                pci_image_base, 32'h5555_5555, 4'h0,
8306
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8307
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8308
                else
8309
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8310
 
8311
                do_pause( 1 ) ;
8312
                end
8313
                begin
8314
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8315
                end
8316
                join
8317
 
8318
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8319
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8320
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8321
        begin
8322
            $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) ;
8323
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8324
            ok = 0 ;
8325
        end
8326
 
8327
        fork
8328
        begin
8329
        // now complete a read from PCI Target
8330
            if ( target_mem_image == 1 )
8331
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8332
                            pci_image_base, 32'h5555_5555,
8333
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8334
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8335
            else
8336
                PCIU_IO_READ
8337
                (
8338
                    `Test_Master_1,
8339
                    pci_image_base,
8340
                    32'h5555_5555,
8341
                    4'h0,
8342
                    1,
8343
                    `Test_Target_Normal_Completion
8344
                );
8345
 
8346
            do_pause( 1 ) ;
8347
        end
8348
        begin
8349
            if ( target_mem_image == 1 )
8350
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8351
            else
8352
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8353
        end
8354
        join
8355
 
8356
        @(posedge pci_clock) ;
8357
        repeat( 4 )
8358
            @(posedge wb_clock) ;
8359
 
8360
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8361
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8362
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8363
        begin
8364
            $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) ;
8365
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8366
            ok = 0 ;
8367
        end
8368
 
8369
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8370
        if ( ok !== 1 )
8371
        begin
8372
            $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) ;
8373
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8374
            ok = 0 ;
8375
        end
8376
 
8377
        // finish a read on WISHBONE also
8378
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8379
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8380
        begin
8381
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8382
            test_fail("WB Slave didn't process single delayed read as expected") ;
8383
        end
8384
 
8385
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8386
        begin
8387
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8388
            ok = 0 ;
8389
        end
8390
 
8391
 
8392
        error_monitor_done = 1 ;
8393
    end
8394
    join
8395
 
8396
    if ( ok )
8397
        test_ok ;
8398
 
8399
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8400
 
8401
    // put wishbone slave in retry and pci target in completion mode
8402
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8403
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8404
 
8405
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8406
 
8407
    master1_check_received_data = 1 ;
8408
 
8409
    error_monitor_done = 0 ;
8410
    fork
8411
    begin:error_monitor_6
8412
        @(error_event_int or error_monitor_done) ;
8413
        if ( !error_monitor_done )
8414
        begin
8415
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8416
            ok = 0 ;
8417
        end
8418
    end
8419
    begin
8420
 
8421
        // do a write through Target
8422
        fork
8423
        begin
8424
            if ( target_mem_image == 1 )
8425
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8426
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8427
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8428
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8429
            else
8430
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8431
 
8432
            do_pause( 1 ) ;
8433
        end
8434
        begin
8435
            if ( target_mem_image == 1 )
8436
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8437
            else
8438
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8439
        end
8440
        join
8441
 
8442
        // start a read through WB slave
8443
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8444
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8445
        begin
8446
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8447
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8448
            ok = 0 ;
8449
        end
8450
 
8451
        // now wait for this read to finish on pci
8452
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8453
        if ( ok !== 1 )
8454
        begin
8455
            $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) ;
8456
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8457
            ok = 0 ;
8458
        end
8459
 
8460
        // repeat the read four times - it should be retried
8461
        for ( i = 0 ; i < 4 ; i = i + 1 )
8462
        begin
8463
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8464
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8465
            begin
8466
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8467
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8468
                ok = 0 ;
8469
            end
8470
        end
8471
 
8472
        // posted write through WB Slave - must go through
8473
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8474
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8475
        begin
8476
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8477
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8478
            ok = 0 ;
8479
        end
8480
 
8481
        // write must come through
8482
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8483
        if ( ok !== 1 )
8484
        begin
8485
            $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) ;
8486
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8487
            ok = 0 ;
8488
        end
8489
 
8490
        // do a read through pci target
8491
        if ( target_mem_image == 1 )
8492
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8493
                          pci_image_base + 12, 32'hDEAD_BEAF,
8494
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8495
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8496
        else
8497
            PCIU_IO_READ
8498
             (
8499
                `Test_Master_1,
8500
                pci_image_base + 12,
8501
                32'hDEAD_BEAF,
8502
                4'h0,
8503
                1,
8504
                `Test_Target_Retry_On
8505
             );
8506
 
8507
         do_pause( 1 ) ;
8508
 
8509
        // wait for current cycle to finish on WB
8510 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8511
//        @(posedge wb_clock) ;
8512
//        while( CYC_O === 1 )
8513
//            @(posedge wb_clock) ;
8514 15 mihad
 
8515
        // set slave response to acknowledge
8516
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8517
 
8518
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8519
        if ( ok !== 1 )
8520
        begin
8521
            $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) ;
8522
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8523
        end
8524
 
8525
        // check the read to finish on wb
8526
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8527
        if ( ok !== 1 )
8528
        begin
8529
            $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) ;
8530
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8531
        end
8532
 
8533
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8534
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8535
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8536
        begin
8537
            $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) ;
8538
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8539
            ok = 0 ;
8540
        end
8541
 
8542
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8543
        fork
8544
        begin
8545
            if ( target_mem_image == 1 )
8546
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8547
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8548
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8549
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8550
            else
8551
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8552
        end
8553
        begin
8554
            if ( target_mem_image == 1 )
8555
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8556
            else
8557
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8558
        end
8559
        join
8560
 
8561
        do_pause( 1 ) ;
8562
 
8563
        // complete a read in WB Slave Unit
8564
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8565
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8566
        begin
8567
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8568
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8569
            ok = 0 ;
8570
        end
8571
 
8572
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8573
        begin
8574
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8575
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8576
            ok = 0 ;
8577
        end
8578
 
8579
        // wait for statuses to be propagated from one side of bridge to another
8580
        repeat( 4 )
8581
            @(posedge pci_clock) ;
8582
 
8583
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8584
        fork
8585
        begin
8586
            if ( target_mem_image == 1 )
8587
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8588
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8589
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8590
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8591
            else
8592
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8593
 
8594
            do_pause( 1 ) ;
8595
        end
8596
        begin
8597
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8598
            if ( ok !== 1 )
8599
            begin
8600
                $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) ;
8601
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8602
            end
8603
        end
8604
        join
8605
 
8606
        // finish the last read in PCI Target Unit
8607
        if ( target_mem_image == 1 )
8608
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8609
                          pci_image_base + 12, 32'hDEAD_BEAF,
8610
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8611
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8612
        else
8613
            PCIU_IO_READ
8614
             (
8615
                `Test_Master_1,
8616
                pci_image_base + 12,
8617
                32'hDEAD_BEAF,
8618
                4'h0,
8619
                1,
8620
                `Test_Target_Normal_Completion
8621
             );
8622
 
8623
         do_pause( 1 ) ;
8624
 
8625
         error_monitor_done = 1 ;
8626
    end
8627
    join
8628
 
8629
    if ( ok )
8630
        test_ok ;
8631
 
8632
end
8633
endtask // transaction_ordering
8634
 
8635
task pci_transaction_progress_monitor ;
8636
    input [31:0] address ;
8637
    input [3:0]  bus_command ;
8638
    input [31:0] num_of_transfers ;
8639
    input [31:0] num_of_cycles ;
8640
    input check_transfers ;
8641
    input check_cycles ;
8642
    input doing_fast_back_to_back ;
8643
    output ok ;
8644
    reg in_use ;
8645
    integer deadlock_counter ;
8646
    integer transfer_counter ;
8647
    integer cycle_counter ;
8648
    integer deadlock_max_val ;
8649
begin:main
8650
 
8651
    if ( in_use === 1 )
8652
    begin
8653
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8654
        ok = 0 ;
8655
        disable main ;
8656
    end
8657
 
8658
    // approximate number of cycles on WB bus for maximum transaction length
8659
    deadlock_max_val = tb_init_waits + 100 +
8660
                       `WBW_DEPTH *
8661
                       (tb_subseq_waits + 1 +
8662
                       `ifdef REGISTER_WBS_OUTPUTS
8663
                       1) ;
8664
                       `else
8665
                       0) ;
8666
                       `endif
8667
 
8668
    // time used for maximum transaction length on WB
8669
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8670
 
8671
    // maximum pci clock cycles
8672
    `ifdef PCI33
8673
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8674
    `else
8675
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8676
    `endif
8677
 
8678
    in_use = 1 ;
8679
    ok     = 1 ;
8680
 
8681
    fork
8682
    begin:wait_start
8683
 
8684
        deadlock_counter = 0 ;
8685
 
8686
        @(posedge pci_clock) ;
8687
 
8688
        if ( doing_fast_back_to_back !== 1 )
8689
        begin
8690
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8691
            begin
8692 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8693
                    deadlock_counter = 0 ;
8694
                else
8695
                    deadlock_counter = deadlock_counter + 1 ;
8696 15 mihad
                @(posedge pci_clock) ;
8697
            end
8698
            if ( FRAME !== 1 )
8699
            begin
8700
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8701
                in_use = 0 ;
8702
                ok     = 0 ;
8703
                disable main ;
8704
            end
8705
        end
8706
 
8707
        deadlock_counter = 0 ;
8708
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8709
        begin
8710
            deadlock_counter = deadlock_counter + 1 ;
8711
            @(posedge pci_clock) ;
8712
        end
8713
 
8714
        if ( FRAME !== 0 )
8715
        begin
8716
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8717
            in_use = 0 ;
8718
            ok     = 0 ;
8719
            disable main ;
8720
        end
8721
    end //wait_start
8722
 
8723
    begin:addr_bc_monitor
8724
 
8725
        @(posedge pci_clock) ;
8726
 
8727
        if ( doing_fast_back_to_back !== 1 )
8728
        begin
8729
            while ( FRAME !== 1 )
8730
                @(posedge pci_clock) ;
8731
        end
8732
 
8733
        while( FRAME !== 0 )
8734
            @(posedge pci_clock) ;
8735
 
8736
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8737
        if ( bus_command !== `BC_IACK )
8738
        begin
8739
            if ( AD !== address )
8740
            begin
8741
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8742
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8743
                ok = 0 ;
8744
            end
8745
        end
8746
 
8747
        if ( CBE !== bus_command )
8748
        begin
8749
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8750
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8751
            ok = 0 ;
8752
        end
8753
    end //addr_bc_monitor
8754
 
8755
    begin:transfer_checker
8756
        transfer_counter = 0 ;
8757
 
8758
        @(posedge pci_clock) ;
8759
 
8760
        if ( doing_fast_back_to_back !== 1 )
8761
        begin
8762
            while ( FRAME !== 1 )
8763
                @(posedge pci_clock) ;
8764
        end
8765
 
8766
        while( FRAME !== 0 )
8767
            @(posedge pci_clock) ;
8768
 
8769
        while( FRAME === 0 )
8770
        begin
8771
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
8772
                transfer_counter = transfer_counter + 1 ;
8773
            @(posedge pci_clock) ;
8774
        end
8775
 
8776
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
8777
        begin
8778
            @(posedge pci_clock) ;
8779
        end
8780
 
8781
        if ( (TRDY === 0) && (DEVSEL === 0) )
8782
                transfer_counter = transfer_counter + 1 ;
8783
 
8784
        if ( check_transfers === 1 )
8785
        begin
8786
            if ( transfer_counter !== num_of_transfers )
8787
            begin
8788
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8789
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8790
                ok = 0 ;
8791
            end
8792
        end
8793
    end //transfer_checker
8794
    begin:cycle_checker
8795
        if ( check_cycles )
8796
        begin
8797
            cycle_counter = 0 ;
8798
            @(posedge pci_clock) ;
8799
 
8800
            if ( doing_fast_back_to_back !== 1)
8801
            begin
8802
                while ( FRAME !== 1 )
8803
                    @(posedge pci_clock) ;
8804
            end
8805
 
8806
            while( FRAME !== 0 )
8807
                @(posedge pci_clock) ;
8808
 
8809
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
8810
            begin
8811
                cycle_counter = cycle_counter + 1 ;
8812
                @(posedge pci_clock) ;
8813
            end
8814
 
8815
            if ( FRAME !== 1 )
8816
            begin
8817
                while ((FRAME === 0) && (MAS0_GNT === 0))
8818
                    @(posedge pci_clock) ;
8819
 
8820
                if ( FRAME !== 1 )
8821
                begin
8822
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
8823
                        @(posedge pci_clock) ;
8824
 
8825
                    @(posedge pci_clock) ;
8826
 
8827
                    if ( FRAME !== 1 )
8828
                    begin
8829
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
8830
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
8831
                        ok = 0 ;
8832
                    end
8833
                end
8834
            end
8835
        end
8836
    end // cycle_checker
8837
    join
8838
 
8839
    in_use = 0 ;
8840
end
8841
endtask //pci_transaction_progress_monitor
8842
 
8843
reg CYC_O_previous ;
8844
always@(posedge wb_clock or posedge reset)
8845
begin
8846
    if ( reset )
8847
        CYC_O_previous <= #1 1'b0 ;
8848
    else
8849
        CYC_O_previous <= #1 CYC_O ;
8850
end
8851
 
8852
task wb_transaction_progress_monitor ;
8853
    input [31:0] address ;
8854
    input        write ;
8855
    input [31:0] num_of_transfers ;
8856
    input check_transfers ;
8857
    output ok ;
8858
    reg in_use ;
8859
    integer deadlock_counter ;
8860
    integer transfer_counter ;
8861
    integer deadlock_max_val ;
8862
begin:main
8863
    if ( in_use === 1 )
8864
    begin
8865
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8866
        ok = 0 ;
8867
        disable main ;
8868
    end
8869
 
8870
    // number of cycles on WB bus for maximum transaction length
8871
    deadlock_max_val = 4 - tb_init_waits + 100 +
8872
                       `PCIW_DEPTH *
8873
                       (4 - tb_subseq_waits + 1) ;
8874
 
8875
    // time used for maximum transaction length on PCI
8876
    `ifdef PCI33
8877
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
8878
    `else
8879
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
8880
    `endif
8881
 
8882
    // maximum wb clock cycles
8883
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
8884
 
8885
    in_use = 1 ;
8886
    ok     = 1 ;
8887
 
8888
    fork
8889
    begin:wait_start
8890
        deadlock_counter = 0 ;
8891
        @(posedge wb_clock) ;
8892
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
8893
        begin
8894 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
8895
                deadlock_counter = deadlock_counter + 1 ;
8896
            else
8897
                deadlock_counter = 0;
8898 15 mihad
            @(posedge wb_clock) ;
8899
        end
8900
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
8901
        begin
8902
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8903
            in_use = 0 ;
8904
            ok     = 0 ;
8905
            disable main ;
8906
        end
8907
 
8908
        deadlock_counter = 0 ;
8909
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
8910
        begin
8911
            deadlock_counter = deadlock_counter + 1 ;
8912
            @(posedge wb_clock) ;
8913
        end
8914
 
8915
        if ( CYC_O !== 1 )
8916
        begin
8917
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8918
            in_use = 0 ;
8919
            ok     = 0 ;
8920
            disable main ;
8921
        end
8922
    end //wait_start
8923
    begin:addr_monitor
8924
        @(posedge wb_clock) ;
8925
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8926
            @(posedge wb_clock) ;
8927
 
8928
        while( CYC_O !== 1 )
8929
            @(posedge wb_clock) ;
8930
 
8931
        while (STB_O !== 1 )
8932
            @(posedge wb_clock) ;
8933
 
8934
        if ( WE_O !== write )
8935
        begin
8936
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
8937
            if ( write !== 1 )
8938
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
8939
            else
8940
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
8941
        end
8942
 
8943
        if ( ADR_O !== address )
8944
        begin
8945
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
8946
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
8947
            ok = 0 ;
8948
        end
8949
    end
8950
    begin:transfer_checker
8951
        transfer_counter = 0 ;
8952
        @(posedge wb_clock) ;
8953
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8954
            @(posedge wb_clock) ;
8955
 
8956
        while( CYC_O !== 1 )
8957
            @(posedge wb_clock) ;
8958
 
8959
        while( CYC_O === 1 )
8960
        begin
8961
            if ( (STB_O === 1) && (ACK_I === 1) )
8962
                transfer_counter = transfer_counter + 1 ;
8963
            @(posedge wb_clock) ;
8964
        end
8965
 
8966
        if ( check_transfers === 1 )
8967
        begin
8968
            if ( transfer_counter !== num_of_transfers )
8969
            begin
8970
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8971
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8972
                ok = 0 ;
8973
            end
8974
        end
8975
    end //transfer_checker
8976
    join
8977
 
8978
    in_use = 0 ;
8979
end
8980
endtask // wb_transaction_progress_monitor
8981
 
8982
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
8983
// so they are not re-entered
8984
task wb_transaction_progress_monitor_backup ;
8985
    input [31:0] address ;
8986
    input        write ;
8987
    input [31:0] num_of_transfers ;
8988
    input check_transfers ;
8989
    output ok ;
8990
    reg in_use ;
8991
    integer deadlock_counter ;
8992
    integer transfer_counter ;
8993
    integer deadlock_max_val ;
8994
begin:main
8995
    if ( in_use === 1 )
8996
    begin
8997
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8998
        ok = 0 ;
8999
        disable main ;
9000
    end
9001
 
9002
    // number of cycles on WB bus for maximum transaction length
9003
    deadlock_max_val = 4 - tb_init_waits + 100 +
9004
                       `PCIW_DEPTH *
9005
                       (4 - tb_subseq_waits + 1) ;
9006
 
9007
    // time used for maximum transaction length on PCI
9008
    `ifdef PCI33
9009
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9010
    `else
9011
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9012
    `endif
9013
 
9014
    // maximum wb clock cycles
9015
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9016
 
9017
    in_use = 1 ;
9018
    ok     = 1 ;
9019
 
9020
    fork
9021
    begin:wait_start
9022
        deadlock_counter = 0 ;
9023
        @(posedge wb_clock) ;
9024
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9025
        begin
9026 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9027
                deadlock_counter = deadlock_counter + 1 ;
9028
            else
9029
                deadlock_counter = 0;
9030 15 mihad
            @(posedge wb_clock) ;
9031
        end
9032
        if ( CYC_O !== 0 )
9033
        begin
9034
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9035
            in_use = 0 ;
9036
            ok     = 0 ;
9037
            disable main ;
9038
        end
9039
 
9040
        deadlock_counter = 0 ;
9041
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9042
        begin
9043
            deadlock_counter = deadlock_counter + 1 ;
9044
            @(posedge wb_clock) ;
9045
        end
9046
 
9047
        if ( CYC_O !== 1 )
9048
        begin
9049
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9050
            in_use = 0 ;
9051
            ok     = 0 ;
9052
            disable main ;
9053
        end
9054
    end //wait_start
9055
    begin:addr_monitor
9056
        @(posedge wb_clock) ;
9057
        while ( CYC_O !== 0 )
9058
            @(posedge wb_clock) ;
9059
 
9060
        while( CYC_O !== 1 )
9061
            @(posedge wb_clock) ;
9062
 
9063
        while (STB_O !== 1 )
9064
            @(posedge wb_clock) ;
9065
 
9066
        if ( WE_O !== write )
9067
        begin
9068
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9069
            if ( write !== 1 )
9070
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9071
            else
9072
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9073
        end
9074
 
9075
        if ( ADR_O !== address )
9076
        begin
9077
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9078
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9079
            ok = 0 ;
9080
        end
9081
    end
9082
    begin:transfer_checker
9083
        transfer_counter = 0 ;
9084
        @(posedge wb_clock) ;
9085
        while ( CYC_O !== 0 )
9086
            @(posedge wb_clock) ;
9087
 
9088
        while( CYC_O !== 1 )
9089
            @(posedge wb_clock) ;
9090
 
9091
        while( CYC_O === 1 )
9092
        begin
9093
            if ( (STB_O === 1) && (ACK_I === 1) )
9094
                transfer_counter = transfer_counter + 1 ;
9095
            @(posedge wb_clock) ;
9096
        end
9097
 
9098
        if ( check_transfers === 1 )
9099
        begin
9100
            if ( transfer_counter !== num_of_transfers )
9101
            begin
9102
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9103
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9104
                ok = 0 ;
9105
            end
9106
        end
9107
    end //transfer_checker
9108
    join
9109
 
9110
    in_use = 0 ;
9111
end
9112
endtask // wb_transaction_progress_monitor_backup
9113
 
9114
task wb_transaction_stop ;
9115
    input [31:0] num_of_transfers ;
9116
    integer transfer_counter ;
9117
begin:main
9118
    begin:transfer_checker
9119
        transfer_counter = 0 ;
9120
        @(posedge wb_clock) ;
9121
        while ( CYC_O !== 0 )
9122
            @(posedge wb_clock) ;
9123
 
9124
        while( CYC_O !== 1 )
9125
            @(posedge wb_clock) ;
9126
 
9127
        if ( (STB_O === 1) && (ACK_I === 1) )
9128
            transfer_counter = transfer_counter + 1 ;
9129
 
9130
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9131
        begin
9132
            @(posedge wb_clock) ;
9133
            if ( (STB_O === 1) && (ACK_I === 1) )
9134
                transfer_counter = transfer_counter + 1 ;
9135
        end
9136
    end //transfer_checker
9137
end
9138
endtask // wb_transaction_stop
9139
 
9140
task musnt_respond ;
9141
    output ok ;
9142
    reg in_use ;
9143
    integer i ;
9144
begin:main
9145
    if ( in_use === 1 )
9146
    begin
9147
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9148
        #20 $stop ;
9149
        ok = 0 ;
9150
        disable main ;
9151
    end
9152
 
9153
    in_use = 1 ;
9154
    ok = 1 ;
9155
 
9156
    fork
9157
    begin:wait_start
9158
        @(negedge FRAME) ;
9159
        disable count ;
9160
    end
9161
    begin:count
9162
        i = 0 ;
9163
        while ( i < 1000 )
9164
        begin
9165
            @(posedge pci_clock) ;
9166
            i = i + 1 ;
9167
        end
9168
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9169
        ok = 0 ;
9170
        disable wait_start ;
9171
    end
9172
    join
9173
 
9174
    @(posedge pci_clock) ;
9175
    while ( FRAME === 0 && ok )
9176
    begin
9177
        if ( DEVSEL !== 1 )
9178
        begin
9179
            ok = 0 ;
9180
        end
9181
        @(posedge pci_clock) ;
9182
    end
9183
 
9184
    while ( IRDY === 0 && ok )
9185
    begin
9186
        if ( DEVSEL !== 1 )
9187
        begin
9188
            ok = 0 ;
9189
        end
9190
        @(posedge pci_clock) ;
9191
    end
9192
    in_use = 0 ;
9193
end
9194
endtask
9195
 
9196
function [31:0] wb_to_pci_addr_convert ;
9197
    input [31:0] wb_address ;
9198
    input [31:0] translation_address ;
9199
    input [31:0] translate ;
9200
 
9201
    reg   [31:0] temp_address ;
9202
begin
9203
    if ( translate !== 1 )
9204
    begin
9205
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9206
    end
9207
    else
9208
    begin
9209
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9210
    end
9211
 
9212
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9213
    wb_to_pci_addr_convert = temp_address ;
9214
end
9215
endfunction //wb_to_pci_addr_convert
9216
 
9217
task find_pci_devices ;
9218
    integer device_num ;
9219
    reg     found ;
9220
    reg [11:0] pci_ctrl_offset ;
9221
    reg ok ;
9222
    reg [31:0] data ;
9223
begin:main
9224
    pci_ctrl_offset = 12'h004 ;
9225
 
9226
    // enable master & target operation
9227
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9228
 
9229
    if ( ok !== 1 )
9230
    begin
9231
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9232
        $stop ;
9233
        disable main ;
9234
    end
9235
    // find all possible devices on pci bus by performing configuration cycles
9236
    for ( device_num = 0 ; device_num <= 20 ; device_num = device_num + 1 )
9237
    begin
9238
        find_device ( device_num, found ) ;
9239
 
9240
        // check pci status register - if device is not present, Received Master Abort bit must be set
9241
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9242
 
9243
        if ( (data[29] !== 0) && (found !== 0) )
9244
    begin
9245
            $display( "Time %t ", $time ) ;
9246
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9247
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9248
            #20 $stop ;
9249
        end
9250
 
9251
        if ( (data[29] !== 1) && (found !== 1) )
9252
        begin
9253
            $display( "Time %t ", $time ) ;
9254
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9255
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9256
            #20 $stop ;
9257
        end
9258
 
9259
        // clear Master Abort status if set
9260
        if ( data[29] !== 0 )
9261
        begin
9262
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9263
        end
9264
    end
9265
end //main
9266
endtask //find_pci_devices
9267
 
9268
task find_device ;
9269
    input [31:0] device_num ;
9270
    output  found ;
9271
 
9272
    reg [31:0] read_data ;
9273
begin
9274
    found = 1'b0 ;
9275
 
9276
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9277
    if ( read_data == 32'hFFFF_FFFF)
9278
        $display("Device %d not present on PCI bus!", device_num) ;
9279
    else
9280
    begin
9281
        $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]) ;
9282
        found = 1'b1 ;
9283
    end
9284
end
9285
endtask //find_device
9286
 
9287
/*task set_bridge_parameters ;
9288
    reg [11:0] current_offset ;
9289
    reg [2:0] result ;
9290
    reg [31:0] write_data ;
9291
begin
9292
    // set burst size
9293
    // set latency timer
9294
    current_offset = 12'h00C ;
9295
    // set burst size to 16 and latency timer to 8
9296
    write_data     = {24'h0000_08, system_burst_size} ;
9297
    config_write(current_offset, write_data, 4'b1111) ;
9298
 
9299
    // set io image
9300
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9301
    write_data = 32'h0000_000_3 ;
9302
    config_write(current_offset, write_data, 4'b1111) ;
9303
 
9304
 
9305
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9306
    write_data = 32'h0001_000_1 ;
9307
    config_write(current_offset, write_data, 4'b1111) ;
9308
 
9309
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9310
    write_data = 32'hFFFF_0000 ;
9311
    config_write(current_offset, write_data, 4'b1111) ;
9312
 
9313
    // set memory image
9314
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9315
    write_data = 32'h0000_000_7 ;
9316
    config_write(current_offset, write_data, 4'b1111) ;
9317
 
9318
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9319
    write_data = 32'h0002_000_0 ;
9320
    config_write(current_offset, write_data, 4'b1111) ;
9321
 
9322
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9323
    write_data = 32'h0001_0000 ;
9324
    config_write(current_offset, write_data, 4'b1111) ;
9325
 
9326
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9327
    write_data = 32'hFFFF_0000 ;
9328
    config_write(current_offset, write_data, 4'b1111) ;
9329
 
9330
    // set parameters for bridge's target unit
9331
    // image control 0
9332
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9333
    write_data     = 32'h0000_0002 ;
9334
    config_write(current_offset, write_data, 4'b0001) ;
9335
 
9336
    // base_address 0
9337
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9338
    write_data      = 32'h2000_0000 ;
9339
    config_write(current_offset, write_data, 4'b1111) ;
9340
 
9341
    // address mask 0
9342
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9343
    write_data     = 32'hFFFF_F000 ;
9344
    config_write(current_offset, write_data, 4'b1111) ;
9345
 
9346
    // command register - enable response to io and mem space and PCI master
9347
    current_offset = 12'h004 ;
9348
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9349
    config_write(current_offset, write_data, 4'b1111) ;
9350
end
9351
endtask // set_bridge_parameters
9352
*/
9353
 
9354
task configuration_cycle_write ;
9355
    input [7:0]  bus_num ;
9356
    input [4:0]  device_num ;
9357
    input [2:0]  func_num ;
9358
    input [5:0]  reg_num ;
9359
    input [1:0]  type ;
9360
    input [3:0]  byte_enables ;
9361
    input [31:0] data ;
9362
 
9363
    `ifdef HOST
9364
    reg `WRITE_STIM_TYPE write_data ;
9365
    reg `WB_TRANSFER_FLAGS write_flags ;
9366
    reg `WRITE_RETURN_TYPE write_status ;
9367
    `endif
9368
 
9369
    reg [31:0] write_address ;
9370
    reg [31:0] temp_var ;
9371
    reg in_use ;
9372
    reg ok ;
9373
begin:main
9374
 
9375
    if ( in_use === 1 )
9376
    begin
9377
        $display(" Task conf_write re-entered! Time %t ", $time ) ;
9378
        disable main ;
9379
    end
9380
 
9381
    if ( device_num > 20 )
9382
    begin
9383
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9384
        disable main ;
9385
    end
9386
 
9387
    in_use = 1 ;
9388
 
9389
    if ( type )
9390
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9391
    else
9392
    begin
9393
        write_address = 0 ;
9394
        write_address[10:0] = { func_num, reg_num, type } ;
9395
        write_address[11 + device_num] = 1'b1 ;
9396
    end
9397
 
9398
fork
9399
begin
9400
    `ifdef HOST
9401
    // setup write flags
9402
    write_flags                    = 0 ;
9403
    write_flags`INIT_WAITS         = tb_init_waits ;
9404
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
9405
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
9406
 
9407
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9408
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9409
 
9410
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9411
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9412
    write_data`WRITE_SEL      = 4'hF ;
9413
    write_data`WRITE_TAG_STIM = 0 ;
9414
 
9415
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9416
 
9417
    // check if write succeeded
9418
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9419
    begin
9420
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9421
        $stop ;
9422
    end
9423
 
9424
    // write to configuration data register
9425
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
9426
 
9427
    write_data`WRITE_ADDRESS = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9428
    write_data`WRITE_DATA    = data ;
9429
    write_data`WRITE_SEL     = byte_enables ;
9430
 
9431
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9432
 
9433
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9434
    begin
9435
        $display("Configuration cycle generation failed! Time %t ", $time) ;
9436
        $stop ;
9437
    end
9438
 
9439
    `else
9440
    `ifdef GUEST
9441
 
9442
     if ( type )
9443
         write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9444
     else
9445
     begin
9446
         write_address = 0 ;
9447
         write_address[10:0] = { func_num, reg_num, type } ;
9448
         write_address[11 + device_num] = 1'b1 ;
9449
     end
9450
     PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9451
                 write_address,
9452
                 data, ~byte_enables,
9453
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9454
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9455
     do_pause(1) ;
9456
    `endif
9457
    `endif
9458
end
9459
begin
9460
    pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9461
end
9462
join
9463
 
9464
    in_use = 0 ;
9465
end
9466
endtask // configuration_cycle_write
9467
 
9468
task configuration_cycle_read ;
9469
    input [7:0]  bus_num ;
9470
    input [4:0]  device_num ;
9471
    input [2:0]  func_num ;
9472
    input [5:0]  reg_num ;
9473
    input [1:0]  type ;
9474
    input [3:0]  byte_enables ;
9475
    output [31:0] data ;
9476
 
9477
    reg `READ_STIM_TYPE read_data ;
9478
    reg `WB_TRANSFER_FLAGS  flags ;
9479
    reg `READ_RETURN_TYPE   read_status ;
9480
 
9481
    reg `WRITE_STIM_TYPE   write_data ;
9482
    reg `WRITE_RETURN_TYPE write_status ;
9483
 
9484
    reg [31:0] read_address ;
9485
    reg in_use ;
9486
 
9487
    reg [31:0] temp_var ;
9488
    reg master_check_data_prev ;
9489
begin:main
9490
 
9491
    if ( in_use === 1 )
9492
    begin
9493
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9494
        data = 32'hxxxx_xxxx ;
9495
        disable main ;
9496
    end
9497
 
9498
    if ( device_num > 20 )
9499
    begin
9500
        $display("Configuration cycle generation only supports access to 20 devices!") ;
9501
        data = 32'hxxxx_xxxx ;
9502
        disable main ;
9503
    end
9504
 
9505
    in_use = 1 ;
9506
 
9507
    `ifdef HOST
9508
    // setup flags
9509
    flags = 0 ;
9510
 
9511
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9512
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9513
 
9514
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9515
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9516
    write_data`WRITE_SEL      = 4'hF ;
9517
    write_data`WRITE_TAG_STIM = 0 ;
9518
 
9519
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9520
 
9521
    // check if write succeeded
9522
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9523
    begin
9524
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9525
        $stop ;
9526
        data = 32'hFFFF_FFFF ;
9527
        disable main ;
9528
    end
9529
 
9530
    // read from configuration data register
9531
    // setup flags for wb master to handle retries
9532
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9533
 
9534
    read_data`READ_ADDRESS  = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9535
    read_data`READ_SEL      = 4'hF ;
9536
    read_data`READ_TAG_STIM = 0 ;
9537
 
9538
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
9539
 
9540
    // check if read succeeded
9541
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
9542
    begin
9543
        $display("Configuration cycle generation failed! Configuration read not processed correctly by the bridge! Time %t ", $time) ;
9544
        $stop ;
9545
        data = 32'hFFFF_FFFF ;
9546
        disable main ;
9547
    end
9548
 
9549
 
9550
    data = read_status`READ_DATA ;
9551
    `else
9552
    `ifdef GUEST
9553
     master_check_data_prev = master1_check_received_data ;
9554
     if ( type )
9555
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9556
     else
9557
     begin
9558
         read_address = 0 ;
9559
         read_address[10:0] = { func_num, reg_num, type } ;
9560
         read_address[11 + device_num] = 1'b1 ;
9561
     end
9562
 
9563
     fork
9564
     begin
9565
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9566
                 read_address,
9567
                 data, ~byte_enables,
9568
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9569
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9570
         do_pause(1) ;
9571
     end
9572
     begin
9573
         @(master1_received_data_valid) ;
9574
         data = master1_received_data ;
9575
     end
9576
     join
9577
 
9578
    master1_check_received_data = master_check_data_prev ;
9579
    `endif
9580
    `endif
9581
 
9582
    in_use = 0 ;
9583
 
9584
end //main
9585
endtask // configuration_cycle_read
9586
 
9587
task display_warning;
9588
    input [31:0] error_address ;
9589
    input [31:0] expected_data ;
9590
    input [31:0] actual ;
9591
begin
9592
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
9593
end
9594
endtask // display warning
9595
 
9596
/*############################################################################
9597
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
9598
=====================
9599
############################################################################*/
9600
 
9601
// Task reslease the PCI bus for 'delay' clocks
9602
task do_pause;
9603
  input  [15:0] delay;
9604
  reg    [15:0] cnt;
9605
  begin
9606
    test_start <= 1'b0;  // no device is allowed to take this
9607
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
9608
    begin
9609
      if (~pci_reset_comb)
9610
      begin
9611
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9612
      end
9613
      `NO_ELSE;
9614
    end
9615
  end
9616
endtask // do_pause
9617
 
9618
// Reference task for using pci_behavioral_master! (from Blue Beaver)
9619
task DO_REF;
9620
  input  [79:0] name;
9621
  input  [2:0] master_number;
9622
  input  [PCI_BUS_DATA_RANGE:0] address;
9623
  input  [3:0] command;
9624
  input  [PCI_BUS_DATA_RANGE:0] data;
9625
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
9626
  input  [9:0] size;
9627
  input   make_addr_par_error, make_data_par_error;
9628
  input  [7:0] master_wait_states;
9629
  input  [7:0] target_wait_states;
9630
  input  [1:0] target_devsel_speed;
9631
  input   fast_back_to_back;
9632
  input  [2:0] target_termination;
9633
  input   expect_master_abort;
9634
  reg     waiting;
9635
  begin
9636
// Cautiously wait for previous command to be done
9637
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
9638
    begin
9639
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
9640
      begin
9641
        if (~pci_reset_comb)
9642
        begin
9643
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9644
        end
9645
        `NO_ELSE;
9646
      end
9647
      else
9648
      begin
9649
        waiting = 1'b0;  // ready to do next command
9650
      end
9651
    end
9652
    next_test_name[79:0] <= name[79:0];
9653
    test_master_number <= master_number[2:0];
9654
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
9655
    test_command[3:0] <= command[3:0] ;
9656
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
9657
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
9658
    test_size <= size;
9659
    test_make_addr_par_error <= make_addr_par_error;
9660
    test_make_data_par_error <= make_data_par_error;
9661
    test_master_initial_wait_states <= 4 - tb_init_waits ;
9662
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
9663
    test_target_initial_wait_states <= target_wait_states[7:4];
9664
    test_target_subsequent_wait_states <= target_wait_states[3:0];
9665
    test_target_devsel_speed <= target_devsel_speed[1:0];
9666
    test_fast_back_to_back <= fast_back_to_back;
9667
    test_target_termination <= target_termination[2:0];
9668
    test_expect_master_abort <= expect_master_abort;
9669
    test_start <= 1'b1;
9670
    if (~pci_reset_comb)
9671
    begin
9672
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9673
    end
9674
    `NO_ELSE;
9675
// wait for new command to start
9676
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
9677
    begin
9678
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
9679
      begin
9680
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9681
      end
9682
      else
9683
      begin
9684
        waiting = 1'b0;  // ready to do next command
9685
      end
9686
    end
9687
  end
9688
endtask // DO_REF
9689
 
9690
// Use Macros defined in pci_defines.vh as paramaters
9691
 
9692
// DO_REF (name[79:0], master_number[2:0],
9693
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
9694
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
9695
//          make_addr_par_error, make_data_par_error,
9696
//          master_wait_states[8:0], target_wait_states[8:0],
9697
//          target_devsel_speed[1:0], fast_back_to_back,
9698
//          target_termination[2:0],
9699
//          expect_master_abort);
9700
//
9701
// Example:
9702
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
9703
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
9704
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
9705
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
9706
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
9707
 
9708
// Access a location with no high-order bits set, assuring that no device responds
9709
task PCIU_CONFIG_READ_MASTER_ABORT;
9710
  input  [79:0] name;
9711
  input  [2:0] master_number;
9712
  input  [9:0] size;
9713
  begin
9714
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9715
               PCI_COMMAND_CONFIG_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9716
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9717
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9718
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9719
  end
9720
endtask // PCIU_CONFIG_READ_MASTER_ABORT
9721
 
9722
// Access a location with no high-order bits set, assuring that no device responds
9723
task PCIU_CONFIG_WRITE_MASTER_ABORT;
9724
  input  [79:0] name;
9725
  input  [2:0] master_number;
9726
  input  [9:0] size;
9727
  begin
9728
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9729
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9730
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9731
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9732
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9733
  end
9734
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
9735
 
9736
// Access a location with no high-order bits set, assuring that no device responds
9737
task PCIU_MEM_READ_MASTER_ABORT;
9738
  input  [79:0] name;
9739
  input  [2:0] master_number;
9740
  input  [9:0] size;
9741
  begin
9742
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9743
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9744
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9745
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9746
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9747
  end
9748
endtask // PCIU_MEM_READ_MASTER_ABORT
9749
 
9750
// Access a location with no high-order bits set, assuring that no device responds
9751
task PCIU_MEM_WRITE_MASTER_ABORT;
9752
  input  [79:0] name;
9753
  input  [2:0] master_number;
9754
  input  [9:0] size;
9755
  begin
9756
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9757
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9758
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9759
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9760
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9761
  end
9762
endtask // PCIU_MEM_WRITE_MASTER_ABORT
9763
 
9764
// Do variable length transfers with various paramaters
9765
task PCIU_CONFIG_READ;
9766
  input  [79:0] name;
9767
  input  [2:0] master_number;
9768
  input  [PCI_BUS_DATA_RANGE:0] address;
9769
  input  [PCI_BUS_DATA_RANGE:0] data;
9770
  input  [3:0] be ;
9771
  input  [9:0] size;
9772
  input  [7:0] master_wait_states;
9773
  input  [7:0] target_wait_states;
9774
  input  [1:0] target_devsel_speed;
9775
  input  [2:0] target_termination;
9776
  begin
9777
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9778
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
9779
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9780
              8'h0_0, target_wait_states[7:0],
9781
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9782
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9783
  end
9784
endtask // PCIU_CONFIG_READ
9785
 
9786
task PCIU_CONFIG_WRITE;
9787
  input  [79:0] name;
9788
  input  [2:0] master_number;
9789
  input  [PCI_BUS_DATA_RANGE:0] address;
9790
  input  [PCI_BUS_DATA_RANGE:0] data;
9791
  input  [3:0] be ;
9792
  input  [9:0] size;
9793
  input  [7:0] master_wait_states;
9794
  input  [7:0] target_wait_states;
9795
  input  [1:0] target_devsel_speed;
9796
  input  [2:0] target_termination;
9797
  begin
9798
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9799
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
9800
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9801
              8'h0_0, target_wait_states[7:0],
9802
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9803
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9804
  end
9805
endtask // PCIU_CONFIG_WRITE
9806
 
9807
task PCIU_READ;
9808
  input  [2:0] master_number;
9809
  input  [PCI_BUS_DATA_RANGE:0] address;
9810
  input  [3:0] command;
9811
  input  [PCI_BUS_DATA_RANGE:0] data;
9812
  input  [3:0] byte_en;
9813
  input  [9:0] size;
9814
  input  [7:0] master_wait_states;
9815
  input  [7:0] target_wait_states;
9816
  input  [1:0] target_devsel_speed;
9817
  input  [2:0] target_termination;
9818
  reg    [79:0] name;
9819
  begin
9820
    if (command == `BC_MEM_READ)
9821
        name = "MEM_READ  " ;
9822
    else if (command == `BC_MEM_READ_LN)
9823
        name = "MEM_RD_LN " ;
9824
    else if (command == `BC_MEM_READ_MUL )
9825
        name = "MEM_RD_MUL" ;
9826
    else
9827
        name = "WRONG_READ" ;
9828
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9829
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9830
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9831
              8'h0_0, target_wait_states[7:0],
9832
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9833
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9834
  end
9835
endtask // PCIU_READ
9836
 
9837
task PCIU_MEM_READ;
9838
  input  [79:0] name;
9839
  input  [2:0] master_number;
9840
  input  [PCI_BUS_DATA_RANGE:0] address;
9841
  input  [PCI_BUS_DATA_RANGE:0] data;
9842
  input  [9:0] size;
9843
  input  [7:0] master_wait_states;
9844
  input  [7:0] target_wait_states;
9845
  input  [1:0] target_devsel_speed;
9846
  input  [2:0] target_termination;
9847
  begin
9848
 
9849
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9850
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9851
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9852
              8'h0_0, target_wait_states[7:0],
9853
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9854
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9855
  end
9856
endtask // PCIU_MEM_READ
9857
 
9858
task PCIU_IO_READ;
9859
  input  [2:0] master_number;
9860
  input  [PCI_BUS_DATA_RANGE:0] address;
9861
  input  [PCI_BUS_DATA_RANGE:0] data;
9862
  input  [3:0] byte_en ;
9863
  input  [9:0] size;
9864
  input  [2:0] target_termination ;
9865
  begin
9866
 
9867
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9868
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9869
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9870
              8'h0_0, `Test_One_Zero_Target_WS,
9871
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9872
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9873
  end
9874
endtask // PCIU_IO_READ
9875
 
9876
task PCIU_IO_READ_MAKE_PERR;
9877
  input  [2:0] master_number;
9878
  input  [PCI_BUS_DATA_RANGE:0] address;
9879
  input  [PCI_BUS_DATA_RANGE:0] data;
9880
  input  [3:0] byte_en ;
9881
  input  [9:0] size;
9882
  input  [2:0] target_termination ;
9883
  begin
9884
 
9885
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9886
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9887
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9888
              8'h0_0, `Test_One_Zero_Target_WS,
9889
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9890
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9891
  end
9892
endtask // PCIU_IO_READ_MAKE_PERR
9893
 
9894
task PCIU_MEM_READ_LN;
9895
  input  [79:0] name;
9896
  input  [2:0] master_number;
9897
  input  [PCI_BUS_DATA_RANGE:0] address;
9898
  input  [PCI_BUS_DATA_RANGE:0] data;
9899
  input  [9:0] size;
9900
  input  [7:0] master_wait_states;
9901
  input  [7:0] target_wait_states;
9902
  input  [1:0] target_devsel_speed;
9903
  input  [2:0] target_termination;
9904
  begin
9905
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9906
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9907
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9908
              8'h0_0, target_wait_states[7:0],
9909
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9910
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9911
  end
9912
endtask // PCIU_MEM_READ_LN
9913
 
9914
task PCIU_MEM_READ_MUL;
9915
  input  [79:0] name;
9916
  input  [2:0] master_number;
9917
  input  [PCI_BUS_DATA_RANGE:0] address;
9918
  input  [PCI_BUS_DATA_RANGE:0] data;
9919
  input  [9:0] size;
9920
  input  [7:0] master_wait_states;
9921
  input  [7:0] target_wait_states;
9922
  input  [1:0] target_devsel_speed;
9923
  input  [2:0] target_termination;
9924
  begin
9925
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9926
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9927
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9928
              8'h0_0, target_wait_states[7:0],
9929
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9930
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9931
  end
9932
endtask // PCIU_MEM_READ_MUL
9933
 
9934
task PCIU_MEM_READ_MAKE_PERR;
9935
  input  [79:0] name;
9936
  input  [2:0] master_number;
9937
  input  [PCI_BUS_DATA_RANGE:0] address;
9938
  input  [PCI_BUS_DATA_RANGE:0] data;
9939
  input  [9:0] size;
9940
  input  [7:0] master_wait_states;
9941
  input  [7:0] target_wait_states;
9942
  input  [1:0] target_devsel_speed;
9943
  input  [2:0] target_termination;
9944
  begin
9945
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9946
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9947
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9948
              8'h0_0, target_wait_states[7:0],
9949
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9950
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9951
  end
9952
endtask // PCIU_MEM_READ_MAKE_PERR
9953
 
9954
task PCIU_MEM_WRITE;
9955
  input  [79:0] name;
9956
  input  [2:0] master_number;
9957
  input  [PCI_BUS_DATA_RANGE:0] address;
9958
  input  [PCI_BUS_DATA_RANGE:0] data;
9959
  input  [3:0] byte_en;
9960
  input  [9:0] size;
9961
  input  [7:0] master_wait_states;
9962
  input  [7:0] target_wait_states;
9963
  input  [1:0] target_devsel_speed;
9964
  input  [2:0] target_termination;
9965
  begin
9966
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9967
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9968
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9969
              8'h0_0, target_wait_states[7:0],
9970
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9971
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9972
  end
9973
endtask // PCIU_MEM_WRITE
9974
 
9975
task PCIU_IO_WRITE;
9976
  input  [2:0] master_number;
9977
  input  [PCI_BUS_DATA_RANGE:0] address;
9978
  input  [PCI_BUS_DATA_RANGE:0] data;
9979
  input  [3:0] byte_en;
9980
  input  [9:0] size;
9981
  input  [2:0] target_termination ;
9982
  begin
9983
 
9984
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9985
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9986
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9987
              8'h0_0, `Test_One_Zero_Target_WS,
9988
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9989
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9990
  end
9991
endtask // PCIU_IO_WRITE
9992
 
9993
task PCIU_IO_WRITE_MAKE_PERR ;
9994
  input  [2:0] master_number;
9995
  input  [PCI_BUS_DATA_RANGE:0] address;
9996
  input  [PCI_BUS_DATA_RANGE:0] data;
9997
  input  [3:0] byte_en;
9998
  input  [9:0] size;
9999
  input  [2:0] target_termination ;
10000
  begin
10001
 
10002
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10003
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
10004
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
10005
              8'h0_0, `Test_One_Zero_Target_WS,
10006
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
10007
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10008
  end
10009
endtask // PCIU_IO_WRITE
10010
 
10011
task PCIU_MEM_WRITE_MAKE_SERR;
10012
  input  [79:0] name;
10013
  input  [2:0] master_number;
10014
  input  [PCI_BUS_DATA_RANGE:0] address;
10015
  input  [PCI_BUS_DATA_RANGE:0] data;
10016
  input  [9:0] size;
10017
  input  [7:0] master_wait_states;
10018
  input  [7:0] target_wait_states;
10019
  input  [1:0] target_devsel_speed;
10020
  input  [2:0] target_termination;
10021
  begin
10022
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10023
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
10024
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
10025
              8'h0_0, target_wait_states[7:0],
10026
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10027
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10028
  end
10029
endtask // PCIU_MEM_WRITE_MAKE_SERR
10030
 
10031
task PCIU_MEM_WRITE_MAKE_PERR;
10032
  input  [79:0] name;
10033
  input  [2:0] master_number;
10034
  input  [PCI_BUS_DATA_RANGE:0] address;
10035
  input  [PCI_BUS_DATA_RANGE:0] data;
10036
  input  [9:0] size;
10037
  input  [7:0] master_wait_states;
10038
  input  [7:0] target_wait_states;
10039
  input  [1:0] target_devsel_speed;
10040
  input  [2:0] target_termination;
10041
  begin
10042
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10043
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
10044
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
10045
              8'h0_0, target_wait_states[7:0],
10046
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10047
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10048
  end
10049
endtask // PCIU_MEM_WRITE
10050
 
10051
/*--------------------------------------------------------------------------
10052
Initialization CASES
10053
--------------------------------------------------------------------------*/
10054
 
10055
// Initialize the basic Config Registers of the PCI bridge target device
10056
task configure_bridge_target;
10057
    reg [11:0] offset ;
10058
    reg [31:0] data ;
10059
    `ifdef HOST
10060
    reg `WRITE_STIM_TYPE   write_data ;
10061
    reg `WB_TRANSFER_FLAGS write_flags ;
10062
    reg `WRITE_RETURN_TYPE write_status ;
10063
    `else
10064
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10065
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10066
    `endif
10067
 
10068
    reg [31:0] temp_var ;
10069
begin
10070
`ifdef HOST //  set Header
10071
    offset  = 12'h4 ; // PCI Header Command register
10072
    data    = 32'h0000_0007 ; // enable master & target operation
10073
 
10074
    write_flags                      = 0 ;
10075
    write_flags`INIT_WAITS           = tb_init_waits ;
10076
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10077
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10078
 
10079
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
10080
    write_data`WRITE_SEL      = 4'h1 ;
10081
    write_data`WRITE_TAG_STIM = 0 ;
10082
    write_data`WRITE_DATA     = data ;
10083
 
10084
    next_test_name[79:0] <= "Init_Tar_R";
10085
 
10086
    $display(" bridge target - Enabling master and target operation!");
10087
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10088
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10089
    begin
10090
        $display("Write to configuration space failed! Time %t ", $time) ;
10091
    end
10092
 
10093
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10094
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10095
 
10096
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10097
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10098
 
10099
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10100
    write_data`WRITE_SEL      = 4'hf ;
10101
    write_data`WRITE_TAG_STIM = 0 ;
10102
    write_data`WRITE_DATA     = data ;
10103
 
10104
 `ifdef  NO_CNF_IMAGE
10105
  `ifdef PCI_IMAGE0 //      set P_BA0
10106
 
10107
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10108
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10109
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10110
    begin
10111
        $display("Write to configuration space failed! Time %t ", $time) ;
10112
    end
10113
  `endif
10114
 `else //      set P_BA0
10115
 
10116
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10117
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10118
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10119
    begin
10120
        $display("Write to configuration space failed! Time %t ", $time) ;
10121
    end
10122
 `endif
10123
 
10124
`else // GUEST, set Header, set P_BA0
10125
    data            = 32'h0000_0007 ; // enable master & target operation
10126
    byte_enables    = 4'hF ;
10127
    $display(" bridge target - Enabling master and target operation!");
10128
    configuration_cycle_write(0,             // bus number
10129
                              0,             // device number
10130
                              0,             // function number
10131
                              1,             // register number
10132
                              0,             // type of configuration cycle
10133
                              byte_enables,  // byte enables
10134
                              data           // data
10135
                             ) ;
10136
 
10137
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10138
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10139
    byte_enables = 4'hf ;
10140
    configuration_cycle_write(0,             // bus number
10141
                              0,             // device number
10142
                              0,             // function number
10143
                              4,             // register number
10144
                              0,             // type of configuration cycle
10145
                              byte_enables,  // byte enables
10146
                              data           // data
10147
                             ) ;
10148
 
10149
`endif
10150
end
10151
endtask // configure_bridge_target
10152
 
10153
// Initialize the basic Config Registers of the PCI bridge target device
10154
task configure_bridge_target_base_addresses;
10155
    reg [11:0] offset ;
10156
    reg [31:0] data ;
10157
    `ifdef HOST
10158
    reg `WRITE_STIM_TYPE   write_data ;
10159
    reg `WB_TRANSFER_FLAGS write_flags ;
10160
    reg `WRITE_RETURN_TYPE write_status ;
10161
    `else
10162
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10163
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10164
    `endif
10165
 
10166
    reg [31:0] temp_var ;
10167
begin
10168
`ifdef HOST //  set Header
10169
    offset  = 12'h4 ; // PCI Header Command register
10170
    data    = 32'h0000_0007 ; // enable master & target operation
10171
 
10172
    write_flags                    = 0 ;
10173
    write_flags`INIT_WAITS         = tb_init_waits ;
10174
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
10175
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10176
 
10177
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10178
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10179
 
10180
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10181
    write_data`WRITE_SEL      = 4'h1 ;
10182
    write_data`WRITE_TAG_STIM = 0 ;
10183
    write_data`WRITE_DATA     = data ;
10184
 
10185
    next_test_name[79:0] <= "Init_Tar_R";
10186
 
10187
    $display(" bridge target - Enabling master and target operation!");
10188
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10189
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10190
    begin
10191
        $display("Write to configuration space failed! Time %t ", $time) ;
10192
    end
10193
 
10194
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10195
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10196
 
10197
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10198
    write_data`WRITE_SEL      = 4'hf ;
10199
    write_data`WRITE_TAG_STIM = 0 ;
10200
    write_data`WRITE_DATA     = data ;
10201
 
10202
 `ifdef  NO_CNF_IMAGE
10203
  `ifdef PCI_IMAGE0 //      set P_BA0
10204
 
10205
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10206
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10207
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10208
    begin
10209
        $display("Write to configuration space failed! Time %t ", $time) ;
10210
    end
10211
  `endif
10212
 `else //      set P_BA0
10213
 
10214
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10215
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10216
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10217
    begin
10218
        $display("Write to configuration space failed! Time %t ", $time) ;
10219
    end
10220
 `endif
10221
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
10222
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10223
 
10224
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10225
    write_data`WRITE_SEL      = 4'hf ;
10226
    write_data`WRITE_TAG_STIM = 0 ;
10227
    write_data`WRITE_DATA     = data ;
10228
 
10229
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10230
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10231
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10232
    begin
10233
        $display("Write to configuration space failed! Time %t ", $time) ;
10234
    end
10235
 `ifdef PCI_IMAGE2
10236
 
10237
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
10238
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10239
 
10240
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10241
    write_data`WRITE_SEL      = 4'hf ;
10242
    write_data`WRITE_TAG_STIM = 0 ;
10243
    write_data`WRITE_DATA     = data ;
10244
 
10245
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10246
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10247
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10248
    begin
10249
        $display("Write to configuration space failed! Time %t ", $time) ;
10250
    end
10251
 `endif
10252
 `ifdef PCI_IMAGE3
10253
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
10254
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10255
 
10256
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10257
    write_data`WRITE_SEL      = 4'hf ;
10258
    write_data`WRITE_TAG_STIM = 0 ;
10259
    write_data`WRITE_DATA     = data ;
10260
 
10261
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10262
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10263
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10264
    begin
10265
        $display("Write to configuration space failed! Time %t ", $time) ;
10266
    end
10267
 `endif
10268
 `ifdef PCI_IMAGE4
10269
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
10270
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10271
 
10272
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10273
    write_data`WRITE_SEL      = 4'hf ;
10274
    write_data`WRITE_TAG_STIM = 0 ;
10275
    write_data`WRITE_DATA     = data ;
10276
 
10277
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10278
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10279
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10280
    begin
10281
        $display("Write to configuration space failed! Time %t ", $time) ;
10282
    end
10283
 `endif
10284
 `ifdef PCI_IMAGE5
10285
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
10286
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10287
 
10288
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10289
    write_data`WRITE_SEL      = 4'hf ;
10290
    write_data`WRITE_TAG_STIM = 0 ;
10291
    write_data`WRITE_DATA     = data ;
10292
 
10293
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10294
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10295
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10296
    begin
10297
        $display("Write to configuration space failed! Time %t ", $time) ;
10298
    end
10299
 `endif
10300
 
10301
`else // GUEST, set Header, set P_BA0
10302
    data            = 32'h0000_0007 ; // enable master & target operation
10303
    byte_enables    = 4'hF ;
10304
    $display(" bridge target - Enabling master and target operation!");
10305
    configuration_cycle_write(0,             // bus number
10306
                              0,             // device number
10307
                              0,             // function number
10308
                              1,             // register number
10309
                              0,             // type of configuration cycle
10310
                              byte_enables,  // byte enables
10311
                              data           // data
10312
                             ) ;
10313
 
10314
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10315
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10316
    byte_enables = 4'hf ;
10317
    configuration_cycle_write(0,             // bus number
10318
                              0,             // device number
10319
                              0,             // function number
10320
                              4,             // register number
10321
                              0,             // type of configuration cycle
10322
                              byte_enables,  // byte enables
10323
                              data           // data
10324
                             ) ;
10325
 
10326
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10327
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10328
    byte_enables = 4'hf ;
10329
    configuration_cycle_write(0,             // bus number
10330
                              0,             // device number
10331
                              0,             // function number
10332
                              5,             // register number
10333
                              0,             // type of configuration cycle
10334
                              byte_enables,  // byte enables
10335
                              data           // data
10336
                             ) ;
10337
 `ifdef PCI_IMAGE2
10338
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10339
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10340
    byte_enables = 4'hf ;
10341
    configuration_cycle_write(0,             // bus number
10342
                              0,             // device number
10343
                              0,             // function number
10344
                              6,             // register number
10345
                              0,             // type of configuration cycle
10346
                              byte_enables,  // byte enables
10347
                              data           // data
10348
                             ) ;
10349
 `endif
10350
 `ifdef PCI_IMAGE3
10351
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10352
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10353
    byte_enables = 4'hf ;
10354
    configuration_cycle_write(0,             // bus number
10355
                              0,             // device number
10356
                              0,             // function number
10357
                              7,             // register number
10358
                              0,             // type of configuration cycle
10359
                              byte_enables,  // byte enables
10360
                              data           // data
10361
                             ) ;
10362
 `endif
10363
 `ifdef PCI_IMAGE4
10364
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10365
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10366
    byte_enables = 4'hf ;
10367
    configuration_cycle_write(0,             // bus number
10368
                              0,             // device number
10369
                              0,             // function number
10370
                              8,             // register number
10371
                              0,             // type of configuration cycle
10372
                              byte_enables,  // byte enables
10373
                              data           // data
10374
                             ) ;
10375
 `endif
10376
 `ifdef PCI_IMAGE5
10377
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10378
    $display(" bridge target - Setting base address P_BA5 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
                              9,             // register number
10384
                              0,             // type of configuration cycle
10385
                              byte_enables,  // byte enables
10386
                              data           // data
10387
                             ) ;
10388
 `endif
10389
`endif
10390
end
10391
endtask // configure_bridge_target_base_addresses
10392
 
10393
/*--------------------------------------------------------------------------
10394
Test CASES
10395
--------------------------------------------------------------------------*/
10396
 
10397
// function converts PCI address to WB with the same data as the pci_decoder does
10398
function [31:0] pci_to_wb_addr_convert ;
10399
 
10400
    input [31:0] pci_address ;
10401
    input [31:0] translation_address ;
10402
    input [31:0] translate ;
10403
 
10404
    reg   [31:0] temp_address ;
10405
begin
10406
    if ( translate !== 1 )
10407
    begin
10408
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10409
    end
10410
    else
10411
    begin
10412
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10413
    end
10414
 
10415
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
10416
    pci_to_wb_addr_convert = temp_address ;
10417
end
10418
endfunction // pci_to_wb_addr_convert
10419
 
10420
// Test normal write and read to WB slave
10421
task test_normal_wr_rd;
10422
  input  [2:0]  Master_ID;
10423
  input  [PCI_BUS_DATA_RANGE:0] Address;
10424
  input  [PCI_BUS_DATA_RANGE:0] Data;
10425
  input  [3:0]  Be;
10426
  input  [2:0]  Image_num;
10427
  input  [9:0]  Set_size;
10428
  input         Set_addr_translation;
10429
  input         Set_prefetch_enable;
10430
  input  [7:0]  Cache_lsize;
10431
  input         Set_wb_wait_states;
10432
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
10433
 
10434
  reg    [31:0] rd_address;
10435
  reg    [31:0] rd_data;
10436
  reg    [3:0]  rd_be;
10437
  reg    [11:0] addr_offset;
10438
  reg    [31:0] read_data;
10439
  reg           continue ;
10440
  reg           ok   ;
10441
  reg    [31:0] expect_address ;
10442
  reg    [31:0] expect_rd_address ;
10443
  reg           expect_we ;
10444
  reg    [9:0]  expect_length_wr ;
10445
  reg    [9:0]  expect_length_rd ;
10446
  reg    [9:0]  expect_length_rd1 ;
10447
  reg    [9:0]  expect_length_rd2 ;
10448
  reg    [3:0]  use_rd_cmd ;
10449
  integer       i ;
10450
begin:main
10451
 
10452
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
10453
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10454
    $display(" - errors will be reported, but they should not occur!");
10455
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
10456
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10457
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
10458
    if ( ok !== 1 )
10459
    begin
10460
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10461
        test_fail("write to P_ERR_CS register didn't succeede") ;
10462
        disable main;
10463
    end
10464
 
10465
    `ifdef  ADDR_TRAN_IMPL
10466
 
10467
    // set or clear address translation
10468
    if (Set_addr_translation)
10469
    begin
10470
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10471
        $display(" - address translation will be performed!");
10472
    end
10473
    else
10474
    begin
10475
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10476
        $display(" - address translation will not be performed!");
10477
    end
10478
    // set or clear pre-fetch enable
10479
    if (Set_prefetch_enable)
10480
    begin
10481
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10482
        $display(" - bursts can be performed!");
10483
    end
10484
    else
10485
    begin
10486
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10487
        $display(" - bursts can not be performed!");
10488
    end
10489
 
10490
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10491
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10492
    if ( ok !== 1 )
10493
    begin
10494
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10495
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10496
        disable main;
10497
    end
10498
 
10499
    // predict the address and control signals on WB bus
10500
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
10501
    expect_we      = 1'b1 ; // WRITE
10502
 
10503
    `else
10504
 
10505
    // address translation is not implemented
10506
    $display("Address translation is NOT implemented for PCI images!");
10507
    // set or clear pre-fetch enable
10508
    if (Set_prefetch_enable)
10509
    begin
10510
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10511
        $display(" - bursts can be performed!");
10512
    end
10513
    else
10514
    begin
10515
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10516
        $display(" - bursts can not be performed!");
10517
    end
10518
 
10519
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10520
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10521
    if ( ok !== 1 )
10522
    begin
10523
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10524
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10525
        disable main;
10526
    end
10527
 
10528
    // predict the address and control signals on WB bus
10529
    expect_address = Address ;
10530
    expect_we      = 1'b1 ; // WRITE
10531
 
10532
    `endif
10533
 
10534
    // set WB SLAVE parameters
10535
    if (Set_wb_wait_states)
10536
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
10537
    else
10538
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
10539
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
10540
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
10541
 
10542
    if ( Set_size > (`PCIW_DEPTH - 2) )
10543
    begin
10544
        expect_length_wr = `PCIW_DEPTH - 2 ;
10545
    end
10546
    else
10547
    begin
10548
        expect_length_wr = Set_size ;
10549
    end
10550
    // write through the PCI bridge to WB slave
10551
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
10552
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
10553
 
10554
    fork
10555
    begin
10556
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
10557
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
10558
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10559
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10560
        do_pause( 1 ) ;
10561
    end
10562
    begin
10563
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
10564
       if ( ok !== 1 )
10565
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10566
       else
10567
           test_ok ;
10568
    end
10569
    join
10570
 
10571
    // predict the address and control signals on WB bus
10572
    expect_we      = 1'b0 ; // READ
10573
 
10574
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
10575
    $display("Memory read through PCI bridge to WB slave!");
10576
 
10577
    if ( expect_length_wr == 1 )
10578
    begin
10579
        if (Set_prefetch_enable)
10580
        begin
10581
            expect_length_rd1 = Cache_lsize ;
10582
            expect_length_rd2 = 0 ;
10583
                // If PCI behavioral master must check received DATA
10584
                master2_check_received_data = 0 ;
10585
                    master1_check_received_data = 0 ;
10586
        end
10587
        else
10588
        begin
10589
            expect_length_rd1 = 1 ;
10590
            expect_length_rd2 = 0 ;
10591
                // If PCI behavioral master must check received DATA
10592
                master2_check_received_data = 1 ;
10593
                    master1_check_received_data = 1 ;
10594
        end
10595
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10596
        expect_length_rd  = expect_length_rd1 ;
10597
    end
10598
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
10599
    begin
10600
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10601
        expect_length_rd2 = 0 ;
10602
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10603
        expect_length_rd  = expect_length_rd1 ;
10604
                // If PCI behavioral master must check received DATA
10605
        master2_check_received_data = 1 ;
10606
            master1_check_received_data = 1 ;
10607
    end
10608
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
10609
    begin
10610
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10611
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
10612
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10613
        expect_length_rd  = expect_length_rd1 ;
10614
                // If PCI behavioral master must check received DATA
10615
                master2_check_received_data = 1 ;
10616
            master1_check_received_data = 1 ;
10617
    end
10618
    else
10619
    begin
10620
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10621
        begin
10622
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10623
            expect_length_rd2 = 0 ;
10624
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10625
            expect_length_rd  = expect_length_rd1 ;
10626
                // If PCI behavioral master must check received DATA
10627
                master2_check_received_data = 0 ;
10628
                    master1_check_received_data = 0 ;
10629
        end
10630
        else
10631
        begin
10632
            if ( expect_length_wr > Cache_lsize )
10633
            begin
10634
                expect_length_rd1 = Cache_lsize ;
10635
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
10636
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10637
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10638
                else
10639
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10640
                expect_length_rd  = expect_length_rd1 ;
10641
                        // If PCI behavioral master must check received DATA
10642
                        master2_check_received_data = 1 ;
10643
                            master1_check_received_data = 1 ;
10644
            end
10645
            else
10646
            begin
10647
                expect_length_rd1 = Cache_lsize ;
10648
                expect_length_rd2 = 0 ;
10649
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10650
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10651
                else
10652
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10653
                expect_length_rd  = expect_length_wr ;
10654
                                if ( expect_length_wr == Cache_lsize )
10655
                        begin
10656
                                // If PCI behavioral master must check received DATA
10657
                                master2_check_received_data = 1 ;
10658
                                    master1_check_received_data = 1 ;
10659
                                end
10660
                                else
10661
                                begin
10662
                                // If PCI behavioral master must check received DATA
10663
                                master2_check_received_data = 0 ;
10664
                                    master1_check_received_data = 0 ;
10665
                end
10666
            end
10667
        end
10668
    end
10669
 
10670
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
10671
    expect_rd_address = expect_address ;
10672
    rd_data[31:0] = Data[31:0];
10673
    rd_be[3:0] = Be[3:0];
10674
 
10675
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
10676
    while (expect_length_rd2 > 0)
10677
    begin
10678
        // do read
10679
        $display("Read %d words!", expect_length_rd);
10680
 
10681
        fork
10682
        begin
10683
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10684
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10685
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10686
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10687
 
10688
            wb_transaction_stop( expect_length_rd - 1) ;
10689
 
10690
            do_pause( 1 ) ;
10691
        end
10692
        begin
10693
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10694
            if ( ok !== 1 )
10695
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
10696
 
10697
            repeat( 3 )
10698
                @(posedge pci_clock) ;
10699
 
10700
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10701
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10702
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10703
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10704
 
10705
            do_pause( 1 ) ;
10706
            while ( FRAME === 0 )
10707
                @(posedge pci_clock) ;
10708
 
10709
            while ( IRDY === 0 )
10710
                @(posedge pci_clock) ;
10711
 
10712
            disable monitor_error_event1 ;
10713
        end
10714
        begin:monitor_error_event1
10715
            @(error_event_int) ;
10716
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10717
            ok = 0 ;
10718
        end
10719
        join
10720
 
10721
        // increasing the starting address for PCI master and for WB transaction monitor
10722
        rd_address = rd_address + (4 * expect_length_rd) ;
10723
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
10724
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
10725
        rd_data[31:24] = Data[31:24] + expect_length_rd;
10726
        rd_data[23:16] = Data[23:16] + expect_length_rd;
10727
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
10728
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
10729
        for (i=0; i<expect_length_rd; i=i+1)
10730
            rd_be[3:0] = {Be[2:0], Be[3]};
10731
 
10732
        // set parameters for next read
10733
        if ( expect_length_rd2 == 1 )
10734
        begin
10735
                if (Set_prefetch_enable)
10736
                begin
10737
                    expect_length_rd1 = Cache_lsize ;
10738
                    expect_length_rd2 = 0 ;
10739
                        // If PCI behavioral master must check received DATA
10740
                        master2_check_received_data = 0 ;
10741
                            master1_check_received_data = 0 ;
10742
                end
10743
                else
10744
                begin
10745
                    expect_length_rd1 = 1 ;
10746
                    expect_length_rd2 = 0 ;
10747
                        // If PCI behavioral master must check received DATA
10748
                        master2_check_received_data = 1 ;
10749
                            master1_check_received_data = 1 ;
10750
                end
10751
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10752
            expect_length_rd  = expect_length_rd1 ;
10753
        end
10754
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
10755
        begin
10756
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10757
            expect_length_rd2 = 0 ;
10758
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10759
            expect_length_rd  = expect_length_rd1 ;
10760
                        // If PCI behavioral master must check received DATA
10761
                        master2_check_received_data = 1 ;
10762
                    master1_check_received_data = 1 ;
10763
        end
10764
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
10765
        begin
10766
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10767
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
10768
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10769
            expect_length_rd  = expect_length_rd1 ;
10770
                        // If PCI behavioral master must check received DATA
10771
                        master2_check_received_data = 1 ;
10772
                    master1_check_received_data = 1 ;
10773
        end
10774
        else
10775
        begin
10776
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10777
            begin
10778
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
10779
                expect_length_rd2 = 0 ;
10780
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10781
                expect_length_rd  = expect_length_rd1 ;
10782
                        // If PCI behavioral master must check received DATA
10783
                        master2_check_received_data = 0 ;
10784
                            master1_check_received_data = 0 ;
10785
            end
10786
            else
10787
            begin
10788
                if ( expect_length_rd2 > Cache_lsize )
10789
                begin
10790
                    expect_length_rd1 = Cache_lsize ;
10791
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
10792
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10793
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10794
                    else
10795
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10796
                    expect_length_rd  = expect_length_rd1 ;
10797
                                // If PCI behavioral master must check received DATA
10798
                                master2_check_received_data = 1 ;
10799
                                    master1_check_received_data = 1 ;
10800
                end
10801
                else
10802
                begin
10803
                    expect_length_rd  = expect_length_rd2 ;
10804
                    expect_length_rd1 = Cache_lsize ;
10805
                    expect_length_rd2 = 0 ;
10806
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10807
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10808
                    else
10809
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10810
                                        if ( expect_length_rd2 == Cache_lsize )
10811
                                begin
10812
                                        // If PCI behavioral master must check received DATA
10813
                                        master2_check_received_data = 1 ;
10814
                                            master1_check_received_data = 1 ;
10815
                                        end
10816
                                        else
10817
                                        begin
10818
                                        // If PCI behavioral master must check received DATA
10819
                                        master2_check_received_data = 0 ;
10820
                                            master1_check_received_data = 0 ;
10821
                        end
10822
                end
10823
            end
10824
        end
10825
    end
10826
    // do last read
10827
    $display("Read %d words!", expect_length_rd);
10828
 
10829
    fork
10830
    begin
10831
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10832
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10833
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10834
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10835
 
10836
        wb_transaction_stop(expect_length_rd - 1) ;
10837
        do_pause( 1 ) ;
10838
    end
10839
    begin
10840
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10841
 
10842
        do_pause(3) ;
10843
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10844
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10845
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10846
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10847
        do_pause(1) ;
10848
 
10849
        while ( FRAME === 0 )
10850
            @(posedge pci_clock) ;
10851
 
10852
        while ( IRDY === 0 )
10853
            @(posedge pci_clock) ;
10854
 
10855
        disable monitor_error_event2 ;
10856
    end
10857
    begin:monitor_error_event2
10858
        @(error_event_int) ;
10859
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10860
        ok = 0 ;
10861
    end
10862
    join
10863
 
10864
    if ( ok )
10865
        test_ok ;
10866
 
10867
    // Check that no ERRORs were reported
10868
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
10869
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
10870
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10871
    config_read( addr_offset, 4'hF, read_data ) ;
10872
    if ( read_data[8] !== 0 )
10873
    begin
10874
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
10875
        test_fail("error status was set even though no errors occured on WB bus") ;
10876
    end
10877
    else
10878
    begin
10879
        $display("No error was signaled, as expected!");
10880
        test_ok ;
10881
    end
10882
 
10883
end // main
10884
endtask // test_normal_wr_rd
10885
 
10886
// Test erroneous write to WB slave
10887
task test_wb_error_wr;
10888
  input  [2:0]  Master_ID;
10889
  input  [PCI_BUS_DATA_RANGE:0] Address;
10890
  input  [PCI_BUS_DATA_RANGE:0] Data;
10891
  input  [3:0]  Be;
10892
  input  [2:0]  Image_num;
10893
  input  [9:0]  Set_size;
10894
  input         Set_err_and_int_report;
10895
  input         Set_wb_wait_states;
10896
  input  [1:0]  Imm_BefLast_Last_error;
10897
 
10898
  reg    [11:0] addr_offset;
10899
  reg    [31:0] read_data;
10900
  reg           continue ;
10901
  reg           ok   ;
10902
  reg    [9:0]  expect_length ;
10903
  reg    [31:0] expect_address ;
10904
  reg    [0:0]  expect_we ;
10905
  reg    [31:0] rd_address;
10906
  reg    [31:0] rd_data;
10907
  reg    [3:0]  rd_be;
10908
  integer       i ;
10909
begin:main
10910
    if (Set_err_and_int_report)
10911
    begin
10912
        // enable ERROR reporting, because error must be reported and interrupt if required!
10913
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10914
        $display(" - errors will be reported when they will occur!");
10915
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
10916
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10917
        $display(" - interrupt will be reported when error will occur!");
10918
    end
10919
    else
10920
    begin
10921
        // disable ERROR reporting, because error and interrupt must not be reported!
10922
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10923
        $display(" - errors will NOT be reported when they will occur!");
10924
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
10925
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10926
        $display(" - interrupt will NOT be reported when error will occur!");
10927
    end
10928
    // enable/disable ERROR reporting
10929
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
10930
 
10931
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10932
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
10933
    if ( ok !== 1 )
10934
    begin
10935
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10936
        test_fail("PCI Error Control and Status register could not be written") ;
10937
        disable main;
10938
    end
10939
    // enable/disable INTERRUPT reporting
10940
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
10941
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
10942
    if ( ok !== 1 )
10943
    begin
10944
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
10945
        test_fail("Interrupt Control register could not be written") ;
10946
        disable main;
10947
    end
10948
 
10949
    `ifdef  ADDR_TRAN_IMPL
10950
 
10951
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
10952
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10953
    config_read( addr_offset, 4'hF, read_data ) ;
10954
    if ( read_data[2] !== 0 )
10955
    begin
10956
        $display("Address translation is set for PCI image%d!", Image_num);
10957
        // predict the address and control signals on WB bus
10958
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
10959
        expect_we      = 1'b1 ; // WRITE
10960
    end
10961
    else
10962
    begin
10963
        $display("Address translation is NOT set for PCI image%d!", Image_num);
10964
        // predict the address and control signals on WB bus
10965
        expect_address = Address ;
10966
        expect_we      = 1'b1 ; // WRITE
10967
    end
10968
 
10969
    `else
10970
 
10971
    // address translation is not implemented
10972
    $display("Address translation is NOT implemented for PCI images!");
10973
    // predict the address and control signals on WB bus
10974
    expect_address = Address ;
10975
    expect_we      = 1'b1 ; // WRITE
10976
 
10977
    `endif
10978
 
10979
    if ( Set_size > (`PCIW_DEPTH - 2) )
10980
    begin
10981
        expect_length = `PCIW_DEPTH - 2 ;
10982
    end
10983
    else
10984
    begin
10985
        expect_length = Set_size ;
10986
    end
10987
 
10988
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
10989
    begin
10990
        $display("ERR termination with first data!");
10991
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
10992
    end
10993
    else if (Imm_BefLast_Last_error == 1)
10994
    begin
10995
        $display("ERR termination before last data!");
10996
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
10997
    end
10998
    else
10999
    begin
11000
        $display("ERR termination with last data!");
11001
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
11002
    end
11003
 
11004
    // write through the PCI bridge to WB slave
11005
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
11006
    fork
11007
    begin
11008
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
11009
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
11010
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11011
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
11012
        do_pause( 1 ) ;
11013
    end
11014
    begin
11015
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11016
        begin
11017
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
11018
            if ( ok !== 1 )
11019
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11020
        end
11021
        else if (Imm_BefLast_Last_error == 1)
11022
        begin
11023
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
11024
            if ( ok !== 1 )
11025
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11026
        end
11027
        else
11028
        begin
11029
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
11030
            if ( ok !== 1 )
11031
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11032
        end
11033
    end
11034
    begin
11035
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11036
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11037
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11038
        else if (Imm_BefLast_Last_error == 1)
11039
        begin
11040
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
11041
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11042
            wb_transaction_stop(expect_length-2) ;
11043
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11044
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11045
        end
11046
        else
11047
        begin
11048
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
11049
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11050
            wb_transaction_stop(expect_length-1) ;
11051
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11052
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11053
        end
11054
    end
11055
    join
11056
 
11057
    if ( ok )
11058
        test_ok ;
11059
 
11060
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11061
    begin
11062
        rd_data[31:0] = Data[31:0];
11063
        rd_address[31:0] = expect_address;
11064
        rd_be[3:0] = Be[3:0];
11065
    end
11066
    else if (Imm_BefLast_Last_error == 1)
11067
    begin
11068
        rd_data[31:24] = Data[31:24] + expect_length - 2;
11069
        rd_data[23:16] = Data[23:16] + expect_length - 2;
11070
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
11071
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
11072
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
11073
        rd_be[3:0] = Be[3:0];
11074
        for (i=0; i<(expect_length-2); i=i+1)
11075
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11076
    end
11077
    else
11078
    begin
11079
        rd_data[31:24] = Data[31:24] + expect_length - 1;
11080
        rd_data[23:16] = Data[23:16] + expect_length - 1;
11081
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
11082
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
11083
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
11084
        rd_be[3:0] = Be[3:0];
11085
        for (i=0; i<(expect_length-1); i=i+1)
11086
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11087
    end
11088
 
11089
    master2_check_received_data = 0 ;
11090
    master1_check_received_data = 0 ;
11091
 
11092
    // Check if ERRORs were reported
11093
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
11094
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11095
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
11096
 
11097
    ok = 1 ;
11098
    config_read( addr_offset, 4'hF, read_data ) ;
11099
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
11100
    begin
11101
        $display("Error was signaled and reported, as expected!");
11102
        if (read_data[31:28] === rd_be)
11103
            $display("Byte enables written into P_ERR_CS register are as expected!");
11104
        else
11105
        begin
11106
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
11107
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
11108
            ok = 0 ;
11109
        end
11110
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
11111
            $display("Bus command written into P_ERR_CS register is as expected!");
11112
        else
11113
        begin
11114
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
11115
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
11116
            ok = 0 ;
11117
        end
11118
 
11119
        if ( ok )
11120
            test_ok ;
11121
 
11122
        $display("Reading the PCI Error Data register P_ERR_DATA.");
11123
 
11124
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11125
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
11126
        config_read( addr_offset, 4'hF, read_data ) ;
11127
        if (read_data === rd_data)
11128
        begin
11129
            $display("Data written into P_ERR_DATA register is as expected!");
11130
            test_ok ;
11131
        end
11132
        else
11133
        begin
11134
            $display("Data written into P_ERR_DATA register is NOT as expected!");
11135
            test_fail("PCI Erroneous Data register value was wrong") ;
11136
        end
11137
 
11138
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
11139
 
11140
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11141
 
11142
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
11143
        config_read( addr_offset, 4'hF, read_data ) ;
11144
        if (read_data === rd_address)
11145
        begin
11146
            $display("Address written into P_ERR_ADDR register is as expected!");
11147
            test_ok ;
11148
        end
11149
        else
11150
        begin
11151
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
11152
            test_fail("PCI Erroneous Address register value was wrong") ;
11153
        end
11154
    end
11155
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
11156
    begin
11157
        $display("Error was signaled and not reported, as expected!");
11158
        test_ok ;
11159
    end
11160
    else
11161
    begin
11162
        $display("Error was signaled and reported, as NOT expected!");
11163
        test_fail("Error status bit was set event though error reporting was disabled") ;
11164
    end
11165
 
11166
    // Check if Interrupts were reported
11167
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
11168
 
11169
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11170
    ok = 1 ;
11171
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11172
    config_read( addr_offset, 4'hF, read_data ) ;
11173
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
11174
    begin
11175
        $display("Interrupts was signaled and reported, as expected!");
11176
    end
11177
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
11178
    begin
11179
        $display("Interrupts was signaled and not reported, as expected!");
11180
    end
11181
    else
11182
    begin
11183
        $display("Interrupt was signaled and reported, as NOT expected!");
11184
        test_fail("PCI Error Interrupt status was set when not expected") ;
11185
        ok = 0 ;
11186
    end
11187
 
11188
    `ifdef HOST
11189
    repeat( 4 )
11190
        @(posedge wb_clock) ;
11191
 
11192
    if ( INT_O === Set_err_and_int_report )
11193
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
11194
    else
11195
    begin
11196
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
11197
        test_fail("Interrupt request didn't have expected value") ;
11198
        ok = 0 ;
11199
    end
11200
 
11201
    `else // GUEST
11202
    repeat( 4 )
11203
        @(posedge pci_clock) ;
11204
 
11205
    if ( INTA === !Set_err_and_int_report )
11206
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
11207
    else
11208
    begin
11209
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
11210
        test_fail("Interrupt request didn't have expected value") ;
11211
        ok = 0 ;
11212
    end
11213
 
11214
    `endif
11215
 
11216
    if ( ok )
11217
        test_ok ;
11218
 
11219
    if (Set_err_and_int_report)
11220
    begin
11221
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11222
        $display("Error and Interrupt must be cleared!");
11223
        // clear  ERROR reporting bit
11224
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11225
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
11226
        if ( ok !== 1 )
11227
        begin
11228
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11229
            test_fail("PCI Error Control and Status register could not be written to") ;
11230
            disable main;
11231
        end
11232
 
11233
        // clear INTERRUPT reporting bit
11234
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11235
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
11236
        if ( ok !== 1 )
11237
        begin
11238
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
11239
            test_fail("Interrupt Status register could not be written to") ;
11240
            disable main;
11241
        end
11242
 
11243
        test_ok ;
11244
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
11245
        `ifdef HOST
11246
 
11247
        repeat(4)
11248
            @(posedge wb_clock) ;
11249
        if ( INT_O === 1'b0 )
11250
        begin
11251
            $display("Interrupt pin INT_O was correctly cleared!");
11252
            test_ok ;
11253
        end
11254
        else
11255
        begin
11256
            $display("Interrupt pin INT_O was NOT correctly cleared!");
11257
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11258
            disable main;
11259
        end
11260
 
11261
        `else // GUEST
11262
 
11263
        repeat(4)
11264
            @(posedge pci_clock) ;
11265
        if ( INTA === 1'b1 )
11266
        begin
11267
            $display("Interrupt pin INTA was correctly cleared!");
11268
            test_ok ;
11269
        end
11270
        else
11271
        begin
11272
            $display("Interrupt pin INTA was NOT correctly cleared!");
11273
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11274
            disable main;
11275
        end
11276
 
11277
        `endif
11278
 
11279
    end
11280
    else
11281
    begin
11282
        $display("Error and Interrupt don't need to be cleared!");
11283
    end
11284
end // main
11285
endtask // test_wb_error_wr
11286
 
11287
task test_wb_error_rd;
11288
    reg    [11:0] addr_offset ;
11289
    reg    [11:0] ctrl_offset ;
11290
    reg    [11:0] ba_offset ;
11291
    reg    [11:0] am_offset ;
11292
    reg    [11:0] ta_offset ;
11293
    reg    [31:0] read_data;
11294
    reg           ok   ;
11295
    reg    [9:0]  expect_length ;
11296
    reg    [31:0] expect_address ;
11297
    reg    [0:0]  expect_we ;
11298
    reg    [31:0] rd_address;
11299
    reg    [31:0] rd_data;
11300
    reg    [3:0]  rd_be;
11301
    integer       i ;
11302
    reg           do_mem_aborts ;
11303
    reg           do_io_aborts ;
11304
begin:main
11305
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
11306
 
11307
    if ( target_mem_image !== -1 )
11308
    begin
11309
        do_mem_aborts = 1 ;
11310
 
11311
        if (target_mem_image === 1)
11312
        begin
11313
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
11314
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
11315
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
11316
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
11317
        end
11318
        else if (target_mem_image === 2)
11319
        begin
11320
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
11321
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
11322
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
11323
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
11324
        end
11325
        else if (target_mem_image === 3)
11326
        begin
11327
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
11328
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
11329
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
11330
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
11331
        end
11332
        else if (target_mem_image === 4)
11333
        begin
11334
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
11335
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
11336
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
11337
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
11338
        end
11339
        else if (target_mem_image === 5)
11340
        begin
11341
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
11342
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
11343
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
11344
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
11345
        end
11346
    end
11347
    else
11348
        do_mem_aborts = 0 ;
11349
 
11350
    if ( do_mem_aborts )
11351
    begin
11352
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
11353
 
11354
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11355
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
11356
        if ( ok !== 1 )
11357
        begin
11358
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11359
            test_fail("PCI Error Control and Status register could not be written") ;
11360
            disable main;
11361
        end
11362
 
11363
        // enable INTERRUPT reporting
11364
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
11365
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
11366
        if ( ok !== 1 )
11367
        begin
11368
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
11369
            test_fail("Interrupt Control register could not be written") ;
11370
            disable main;
11371
        end
11372
 
11373
        addr_offset = 12'h010 + (4*target_mem_image) ;
11374
 
11375
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
11376
        if ( ok !== 1 )
11377
        begin
11378
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
11379
            test_fail("PCI Base Address register could not be written") ;
11380
            disable main;
11381
        end
11382
 
11383
        // disable address translation and enable prefetch so read bursts can be performed
11384
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
11385
        if ( ok !== 1 )
11386
        begin
11387
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
11388
            test_fail("PCI Image Control register could not be written") ;
11389
            disable main;
11390
        end
11391
 
11392
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
11393
        if ( ok !== 1 )
11394
        begin
11395
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
11396
            test_fail("PCI Address Mask register could not be written") ;
11397
            disable main;
11398
        end
11399
 
11400
        addr_offset = 12'h00C ;
11401
 
11402
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
11403
        if ( ok !== 1 )
11404
        begin
11405
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
11406
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
11407
            disable main;
11408
        end
11409
 
11410
        // disable PCI master data checking
11411
        master1_check_received_data = 0 ;
11412
 
11413
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11414
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11415
 
11416
 
11417
        // do a single read error terminated on WB bus
11418
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
11419
 
11420
        fork
11421
        begin
11422
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11423
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11424
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11425
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
11426
 
11427
            do_pause( 1 ) ;
11428
        end
11429
        begin
11430
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11431
 
11432
            if ( ok !== 1 )
11433
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11434
 
11435
            do_pause(3) ;
11436
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11437
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11438
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11439
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11440
            do_pause(1) ;
11441
 
11442
            while ( FRAME === 0 )
11443
                @(posedge pci_clock) ;
11444
 
11445
            while ( IRDY === 0 )
11446
                @(posedge pci_clock) ;
11447
 
11448
            disable monitor_error_event1 ;
11449
        end
11450
        begin:monitor_error_event1
11451
            @(error_event_int) ;
11452
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11453
            ok = 0 ;
11454
        end
11455
        join
11456
 
11457
        if ( ok )
11458
            test_ok ;
11459 26 mihad
 
11460
        @(posedge pci_clock) ;
11461
        @(posedge pci_clock) ;
11462
        @(posedge wb_clock) ;
11463
        @(posedge wb_clock) ;
11464 15 mihad
 
11465
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11466
        addr_offset = 12'h004 ;
11467
        config_read(addr_offset, 4'hF, read_data) ;
11468
        ok = 1 ;
11469
        if ( read_data[27] !== 1 )
11470
        begin
11471
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11472
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11473
            ok = 0 ;
11474
        end
11475
        if ( read_data[28] !== 0 )
11476
        begin
11477
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11478
            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") ;
11479
            ok = 0 ;
11480
        end
11481
        if ( read_data[29] !== 0 )
11482
        begin
11483
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11484
            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") ;
11485
            ok = 0 ;
11486
        end
11487
 
11488
        // clear statuses
11489
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11490
        if ( !ok )
11491
        begin
11492
            test_fail("write to PCI Device Status register failed") ;
11493
            $display("Couldn't write PCI Device Status register") ;
11494
            disable main ;
11495
        end
11496
 
11497
        if ( ok )
11498
            test_ok ;
11499
 
11500
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11501
 
11502
        ok = 1 ;
11503
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11504
 
11505
        config_read(addr_offset, 4'hF, read_data) ;
11506
        if (read_data[8] !== 0)
11507
        begin
11508
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11509
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11510
            ok = 0 ;
11511
        end
11512
        else
11513
            test_ok ;
11514
 
11515
        if ( ok !== 1 )
11516
        begin
11517
            config_write(addr_offset, read_data, 4'hF, ok) ;
11518
            if ( !ok )
11519
            begin
11520
                test_fail("PCI Error Control and Status register could not be written") ;
11521
                disable main ;
11522
            end
11523
        end
11524
 
11525
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11526
        fork
11527
        begin
11528
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11529
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11530
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11531
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11532
 
11533
            do_pause( 1 ) ;
11534
        end
11535
        begin
11536
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11537
 
11538
            if ( ok !== 1 )
11539
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11540
 
11541
            do_pause(3) ;
11542
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11543
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11544
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11545
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11546
            do_pause(1) ;
11547
 
11548
            while ( FRAME === 0 )
11549
                @(posedge pci_clock) ;
11550
 
11551
            while ( IRDY === 0 )
11552
                @(posedge pci_clock) ;
11553
 
11554
            disable monitor_error_event2 ;
11555
        end
11556
        begin:monitor_error_event2
11557
            @(error_event_int) ;
11558
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11559
            ok = 0 ;
11560
        end
11561
        join
11562
 
11563
        if ( ok )
11564
            test_ok ;
11565
 
11566 26 mihad
        @(posedge pci_clock) ;
11567
        @(posedge pci_clock) ;
11568
        @(posedge wb_clock) ;
11569
        @(posedge wb_clock) ;
11570
 
11571 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11572
        addr_offset = 12'h004 ;
11573
        config_read(addr_offset, 4'hF, read_data) ;
11574
        ok = 1 ;
11575
        if ( read_data[27] !== 1 )
11576
        begin
11577
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11578
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11579
            ok = 0 ;
11580
        end
11581
        if ( read_data[28] !== 0 )
11582
        begin
11583
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11584
            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") ;
11585
            ok = 0 ;
11586
        end
11587
        if ( read_data[29] !== 0 )
11588
        begin
11589
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11590
            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") ;
11591
            ok = 0 ;
11592
        end
11593
 
11594
        // clear statuses
11595
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11596
        if ( !ok )
11597
        begin
11598
            test_fail("write to PCI Device Status register failed") ;
11599
            $display("Couldn't write PCI Device Status register") ;
11600
            disable main ;
11601
        end
11602
 
11603
        if ( ok )
11604
            test_ok ;
11605
 
11606
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11607
 
11608
        ok = 1 ;
11609
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11610
 
11611
        config_read(addr_offset, 4'hF, read_data) ;
11612
        if (read_data[8] !== 0)
11613
        begin
11614
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11615
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11616
            ok = 0 ;
11617
        end
11618
        else
11619
            test_ok ;
11620
 
11621
        if ( ok !== 1 )
11622
        begin
11623
            config_write(addr_offset, read_data, 4'hF, ok) ;
11624
            if ( !ok )
11625
            begin
11626
                test_fail("PCI Error Control and Status register could not be written") ;
11627
                disable main ;
11628
            end
11629
        end
11630
 
11631
        // do a single read error terminated on WB bus
11632
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
11633
 
11634
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11635
 
11636
        fork
11637
        begin
11638
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11639
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11640
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11641
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11642
 
11643
            do_pause( 1 ) ;
11644
        end
11645
        begin
11646
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11647
 
11648
            if ( ok !== 1 )
11649
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11650
 
11651
            do_pause(3) ;
11652
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11653
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11654
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11655
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11656
            do_pause(1) ;
11657
 
11658
            while ( FRAME === 0 )
11659
                @(posedge pci_clock) ;
11660
 
11661
            while ( IRDY === 0 )
11662
                @(posedge pci_clock) ;
11663
 
11664
            disable monitor_error_event3 ;
11665
        end
11666
        begin:monitor_error_event3
11667
            @(error_event_int) ;
11668
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11669
            ok = 0 ;
11670
        end
11671
        join
11672
 
11673
        if ( ok )
11674
            test_ok ;
11675
 
11676 26 mihad
        @(posedge pci_clock) ;
11677
        @(posedge pci_clock) ;
11678
        @(posedge wb_clock) ;
11679
        @(posedge wb_clock) ;
11680
 
11681 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11682
        addr_offset = 12'h004 ;
11683
        config_read(addr_offset, 4'hF, read_data) ;
11684
        ok = 1 ;
11685
        if ( read_data[27] !== 1 )
11686
        begin
11687
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11688
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11689
            ok = 0 ;
11690
        end
11691
        if ( read_data[28] !== 0 )
11692
        begin
11693
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11694
            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") ;
11695
            ok = 0 ;
11696
        end
11697
        if ( read_data[29] !== 0 )
11698
        begin
11699
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11700
            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") ;
11701
            ok = 0 ;
11702
        end
11703
 
11704
        // clear statuses
11705
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11706
        if ( !ok )
11707
        begin
11708
            test_fail("write to PCI Device Status register failed") ;
11709
            $display("Couldn't write PCI Device Status register") ;
11710
            disable main ;
11711
        end
11712
 
11713
        if ( ok )
11714
            test_ok ;
11715
 
11716
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11717
 
11718
        ok = 1 ;
11719
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11720
 
11721
        config_read(addr_offset, 4'hF, read_data) ;
11722
        if (read_data[8] !== 0)
11723
        begin
11724
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11725
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11726
            ok = 0 ;
11727
        end
11728
        else
11729
            test_ok ;
11730
 
11731
        if ( ok !== 1 )
11732
        begin
11733
            config_write(addr_offset, read_data, 4'hF, ok) ;
11734
            if ( !ok )
11735
            begin
11736
                test_fail("PCI Error Control and Status register could not be written") ;
11737
                disable main ;
11738
            end
11739
        end
11740
 
11741
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
11742
 
11743
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11744
 
11745
        fork
11746
        begin
11747
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11748
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11749
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11750
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11751
 
11752
            do_pause( 1 ) ;
11753
        end
11754
        begin
11755
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
11756
 
11757
            if ( ok !== 1 )
11758
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11759
 
11760
            do_pause(3) ;
11761
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11762
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11763
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11764
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11765
            do_pause(1) ;
11766
 
11767
            while ( FRAME === 0 )
11768
                @(posedge pci_clock) ;
11769
 
11770
            while ( IRDY === 0 )
11771
                @(posedge pci_clock) ;
11772
 
11773
            disable monitor_error_event4 ;
11774
        end
11775
        begin:monitor_error_event4
11776
            @(error_event_int) ;
11777
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11778
            ok = 0 ;
11779
        end
11780
        begin
11781
            wb_transaction_stop( 1 ) ;
11782
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11783
        end
11784
        join
11785
 
11786
        if ( ok )
11787
            test_ok ;
11788
 
11789 26 mihad
        @(posedge pci_clock) ;
11790
        @(posedge pci_clock) ;
11791
        @(posedge wb_clock) ;
11792
        @(posedge wb_clock) ;
11793
 
11794 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11795
        addr_offset = 12'h004 ;
11796
        config_read(addr_offset, 4'hF, read_data) ;
11797
        ok = 1 ;
11798
        if ( read_data[27] !== 1 )
11799
        begin
11800
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11801
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11802
            ok = 0 ;
11803
        end
11804
        if ( read_data[28] !== 0 )
11805
        begin
11806
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11807
            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") ;
11808
            ok = 0 ;
11809
        end
11810
        if ( read_data[29] !== 0 )
11811
        begin
11812
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11813
            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") ;
11814
            ok = 0 ;
11815
        end
11816
 
11817
        // clear statuses
11818
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11819
        if ( !ok )
11820
        begin
11821
            test_fail("write to PCI Device Status register failed") ;
11822
            $display("Couldn't write PCI Device Status register") ;
11823
            disable main ;
11824
        end
11825
 
11826
        if ( ok )
11827
            test_ok ;
11828
 
11829
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11830
 
11831
        ok = 1 ;
11832
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11833
 
11834
        config_read(addr_offset, 4'hF, read_data) ;
11835
        if (read_data[8] !== 0)
11836
        begin
11837
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11838
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11839
            ok = 0 ;
11840
        end
11841
        else
11842
            test_ok ;
11843
 
11844
        if ( ok !== 1 )
11845
        begin
11846
            config_write(addr_offset, read_data, 4'hF, ok) ;
11847
            if ( !ok )
11848
            begin
11849
                test_fail("PCI Error Control and Status register could not be written") ;
11850
                disable main ;
11851
            end
11852
        end
11853
 
11854
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
11855
 
11856
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11857
 
11858
        fork
11859
        begin
11860
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11861
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11862
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11863
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11864
 
11865
            do_pause( 1 ) ;
11866
        end
11867
        begin
11868
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11869
 
11870
            if ( ok !== 1 )
11871
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11872
 
11873
            do_pause(3) ;
11874
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11875
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11876
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11877
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11878
            do_pause(1) ;
11879
 
11880
            while ( FRAME === 0 )
11881
                @(posedge pci_clock) ;
11882
 
11883
            while ( IRDY === 0 )
11884
                @(posedge pci_clock) ;
11885
 
11886
            disable monitor_error_event5 ;
11887
        end
11888
        begin:monitor_error_event5
11889
            @(error_event_int) ;
11890
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11891
            ok = 0 ;
11892
        end
11893
        begin
11894
            wb_transaction_stop( 3 ) ;
11895
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11896
        end
11897
        join
11898
 
11899
        if ( ok )
11900
            test_ok ;
11901
 
11902 26 mihad
        @(posedge pci_clock) ;
11903
        @(posedge pci_clock) ;
11904
        @(posedge wb_clock) ;
11905
        @(posedge wb_clock) ;
11906
 
11907 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11908
        addr_offset = 12'h004 ;
11909
        config_read(addr_offset, 4'hF, read_data) ;
11910
        ok = 1 ;
11911
        if ( read_data[27] !== 1 )
11912
        begin
11913
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11914
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11915
            ok = 0 ;
11916
        end
11917
        if ( read_data[28] !== 0 )
11918
        begin
11919
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11920
            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") ;
11921
            ok = 0 ;
11922
        end
11923
        if ( read_data[29] !== 0 )
11924
        begin
11925
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11926
            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") ;
11927
            ok = 0 ;
11928
        end
11929
 
11930
        // clear statuses
11931
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11932
        if ( !ok )
11933
        begin
11934
            test_fail("write to PCI Device Status register failed") ;
11935
            $display("Couldn't write PCI Device Status register") ;
11936
            disable main ;
11937
        end
11938
 
11939
        if ( ok )
11940
            test_ok ;
11941
 
11942
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11943
 
11944
        ok = 1 ;
11945
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11946
 
11947
        config_read(addr_offset, 4'hF, read_data) ;
11948
        if (read_data[8] !== 0)
11949
        begin
11950
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11951
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11952
            ok = 0 ;
11953
        end
11954
        else
11955
            test_ok ;
11956
 
11957
        if ( ok !== 1 )
11958
        begin
11959
            config_write(addr_offset, read_data, 4'hF, ok) ;
11960
            if ( !ok )
11961
            begin
11962
                test_fail("PCI Error Control and Status register could not be written") ;
11963
                disable main ;
11964
            end
11965
        end
11966
 
11967
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
11968
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11969
        fork
11970
        begin
11971
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11972
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11973
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11974
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11975
 
11976
            do_pause( 1 ) ;
11977
        end
11978
        begin
11979
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11980
 
11981
            if ( ok !== 1 )
11982
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11983
 
11984
            do_pause(3) ;
11985
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11986
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11987
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11988
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11989
            do_pause(1) ;
11990
 
11991
            while ( FRAME === 0 )
11992
                @(posedge pci_clock) ;
11993
 
11994
            while ( IRDY === 0 )
11995
                @(posedge pci_clock) ;
11996
 
11997
            disable monitor_error_event6 ;
11998
        end
11999
        begin:monitor_error_event6
12000
            @(error_event_int) ;
12001
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12002
            ok = 0 ;
12003
        end
12004
        begin
12005
            wb_transaction_stop( 3 ) ;
12006
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12007
        end
12008
        join
12009
 
12010
        if ( ok )
12011
            test_ok ;
12012
 
12013 26 mihad
        @(posedge pci_clock) ;
12014
        @(posedge pci_clock) ;
12015
        @(posedge wb_clock) ;
12016
        @(posedge wb_clock) ;
12017
 
12018 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12019
        addr_offset = 12'h004 ;
12020
        config_read(addr_offset, 4'hF, read_data) ;
12021
        ok = 1 ;
12022
        if ( read_data[27] !== 1 )
12023
        begin
12024
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12025
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12026
            ok = 0 ;
12027
        end
12028
        if ( read_data[28] !== 0 )
12029
        begin
12030
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12031
            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") ;
12032
            ok = 0 ;
12033
        end
12034
        if ( read_data[29] !== 0 )
12035
        begin
12036
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12037
            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") ;
12038
            ok = 0 ;
12039
        end
12040
 
12041
        // clear statuses
12042
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12043
        if ( !ok )
12044
        begin
12045
            test_fail("write to PCI Device Status register failed") ;
12046
            $display("Couldn't write PCI Device Status register") ;
12047
            disable main ;
12048
        end
12049
 
12050
        if ( ok )
12051
            test_ok ;
12052
 
12053
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12054
 
12055
        ok = 1 ;
12056
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12057
 
12058
        config_read(addr_offset, 4'hF, read_data) ;
12059
        if (read_data[8] !== 0)
12060
        begin
12061
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12062
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12063
            ok = 0 ;
12064
        end
12065
        else
12066
            test_ok ;
12067
 
12068
        if ( ok !== 1 )
12069
        begin
12070
            config_write(addr_offset, read_data, 4'hF, ok) ;
12071
            if ( !ok )
12072
            begin
12073
                test_fail("PCI Error Control and Status register could not be written") ;
12074
                disable main ;
12075
            end
12076
        end
12077
 
12078
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
12079
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12080
        fork
12081
        begin
12082
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12083
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12084
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12085
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12086
 
12087
            do_pause( 1 ) ;
12088
        end
12089
        begin
12090
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12091
 
12092
            if ( ok !== 1 )
12093
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12094
 
12095
            do_pause(3) ;
12096
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12097
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12098
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12099
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
12100
            do_pause(1) ;
12101
 
12102
            while ( FRAME === 0 )
12103
                @(posedge pci_clock) ;
12104
 
12105
            while ( IRDY === 0 )
12106
                @(posedge pci_clock) ;
12107
 
12108
            disable monitor_error_event7 ;
12109
        end
12110
        begin:monitor_error_event7
12111
            @(error_event_int) ;
12112
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12113
            ok = 0 ;
12114
        end
12115
        begin
12116
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12117
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12118
        end
12119
        join
12120
 
12121
        if ( ok )
12122
            test_ok ;
12123
 
12124 26 mihad
        @(posedge pci_clock) ;
12125
        @(posedge pci_clock) ;
12126
        @(posedge wb_clock) ;
12127
        @(posedge wb_clock) ;
12128
 
12129 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12130
        addr_offset = 12'h004 ;
12131
        config_read(addr_offset, 4'hF, read_data) ;
12132
        ok = 1 ;
12133
        if ( read_data[27] !== 1 )
12134
        begin
12135
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12136
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12137
            ok = 0 ;
12138
        end
12139
        if ( read_data[28] !== 0 )
12140
        begin
12141
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12142
            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") ;
12143
            ok = 0 ;
12144
        end
12145
        if ( read_data[29] !== 0 )
12146
        begin
12147
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12148
            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") ;
12149
            ok = 0 ;
12150
        end
12151
 
12152
        // clear statuses
12153
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12154
        if ( !ok )
12155
        begin
12156
            test_fail("write to PCI Device Status register failed") ;
12157
            $display("Couldn't write PCI Device Status register") ;
12158
            disable main ;
12159
        end
12160
 
12161
        if ( ok )
12162
            test_ok ;
12163
 
12164
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12165
 
12166
        ok = 1 ;
12167
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12168
 
12169
        config_read(addr_offset, 4'hF, read_data) ;
12170
        if (read_data[8] !== 0)
12171
        begin
12172
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12173
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12174
            ok = 0 ;
12175
        end
12176
        else
12177
            test_ok ;
12178
 
12179
        if ( ok !== 1 )
12180
        begin
12181
            config_write(addr_offset, read_data, 4'hF, ok) ;
12182
            if ( !ok )
12183
            begin
12184
                test_fail("PCI Error Control and Status register could not be written") ;
12185
                disable main ;
12186
            end
12187
        end
12188
 
12189
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
12190
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12191
        fork
12192
        begin
12193
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12194
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12195
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12196
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12197
 
12198
            do_pause( 1 ) ;
12199
        end
12200
        begin
12201
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12202
 
12203
            if ( ok !== 1 )
12204
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12205
 
12206
            do_pause(3) ;
12207
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12208
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12209
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12210
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
12211
            do_pause(1) ;
12212
 
12213
            while ( FRAME === 0 )
12214
                @(posedge pci_clock) ;
12215
 
12216
            while ( IRDY === 0 )
12217
                @(posedge pci_clock) ;
12218
 
12219
            disable monitor_error_event8 ;
12220
        end
12221
        begin:monitor_error_event8
12222
            @(error_event_int) ;
12223
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12224
            ok = 0 ;
12225
        end
12226
        begin
12227
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12228
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12229
        end
12230
        join
12231
 
12232
        if ( ok )
12233
            test_ok ;
12234
 
12235 26 mihad
        @(posedge pci_clock) ;
12236
        @(posedge pci_clock) ;
12237
        @(posedge wb_clock) ;
12238
        @(posedge wb_clock) ;
12239
 
12240 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12241
 
12242
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12243
        addr_offset = 12'h004 ;
12244
        config_read(addr_offset, 4'hF, read_data) ;
12245
        ok = 1 ;
12246
        if ( read_data[27] !== 1 )
12247
        begin
12248
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12249
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12250
            ok = 0 ;
12251
        end
12252
        if ( read_data[28] !== 0 )
12253
        begin
12254
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12255
            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") ;
12256
            ok = 0 ;
12257
        end
12258
        if ( read_data[29] !== 0 )
12259
        begin
12260
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12261
            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") ;
12262
            ok = 0 ;
12263
        end
12264
 
12265
        // clear statuses
12266
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12267
        if ( !ok )
12268
        begin
12269
            test_fail("write to PCI Device Status register failed") ;
12270
            $display("Couldn't write PCI Device Status register") ;
12271
            disable main ;
12272
        end
12273
 
12274
        if ( ok )
12275
            test_ok ;
12276
 
12277
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12278
 
12279
        ok = 1 ;
12280
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12281
 
12282
        config_read(addr_offset, 4'hF, read_data) ;
12283
        if (read_data[8] !== 0)
12284
        begin
12285
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12286
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12287
            ok = 0 ;
12288
        end
12289
        else
12290
            test_ok ;
12291
 
12292
        if ( ok !== 1 )
12293
        begin
12294
            config_write(addr_offset, read_data, 4'hF, ok) ;
12295
            if ( !ok )
12296
            begin
12297
                test_fail("PCI Error Control and Status register could not be written") ;
12298
                disable main ;
12299
            end
12300
        end
12301
 
12302
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
12303
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12304
        fork
12305
        begin
12306
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12307
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12308
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12309
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12310
 
12311
            do_pause( 1 ) ;
12312
        end
12313
        begin
12314
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
12315
 
12316
            if ( ok !== 1 )
12317
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12318
 
12319
            do_pause(3) ;
12320
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12321
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12322
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12323
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12324
            do_pause(1) ;
12325
 
12326
            while ( FRAME === 0 )
12327
                @(posedge pci_clock) ;
12328
 
12329
            while ( IRDY === 0 )
12330
                @(posedge pci_clock) ;
12331
 
12332
            disable monitor_error_event9 ;
12333
        end
12334
        begin:monitor_error_event9
12335
            @(error_event_int) ;
12336
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12337
            ok = 0 ;
12338
        end
12339
        begin
12340
            wb_transaction_stop( 3 ) ;
12341
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12342
        end
12343
        join
12344
 
12345
        if ( ok )
12346
            test_ok ;
12347
 
12348
        // now check all other statuses too
12349
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
12350
        ok = 1 ;
12351
 
12352
        addr_offset = 12'h004 ;
12353
        config_read(addr_offset, 4'hF, read_data) ;
12354
        if (read_data[31] !== 0)
12355
        begin
12356
            $display("Detected Parity Error bit set for no reason") ;
12357
            test_fail("Detected Parity Error bit was set for no reason") ;
12358
            ok = 0 ;
12359
        end
12360
 
12361
        if (read_data[30] !== 0)
12362
        begin
12363
            $display("Signaled System Error bit set for no reason") ;
12364
            test_fail("Signaled System Error bit was set for no reason") ;
12365
            ok = 0 ;
12366
        end
12367
 
12368
        if (read_data[29] !== 0)
12369
        begin
12370
            $display("Received Master Abort bit set for no reason") ;
12371
            test_fail("Received Master Abort bit was set for no reason") ;
12372
            ok = 0 ;
12373
        end
12374
 
12375
        if (read_data[28] !== 0)
12376
        begin
12377
            $display("Received Target Abort bit set for no reason");
12378
            test_fail("Received Target Abort bit was set for no reason") ;
12379
            ok = 0 ;
12380
        end
12381
 
12382
        if (read_data[27] !== 0)
12383
        begin
12384
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
12385
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
12386
            ok = 0 ;
12387
        end
12388
 
12389
        if (read_data[24] !== 0)
12390
        begin
12391
            $display("Master Data Parity Error bit set for no reason") ;
12392
            test_fail("Master Data Parity Error bit was set for no reason") ;
12393
            ok = 0 ;
12394
        end
12395
 
12396
        if ( ok )
12397
            test_ok ;
12398
 
12399
        test_name = "DISABLE IMAGE" ;
12400
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12401
        if ( ok !== 1 )
12402
        begin
12403
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12404
            test_fail("PCI Address Mask register could not be written") ;
12405
            disable main;
12406
        end
12407
    end
12408
 
12409
    if ( target_io_image !== -1 )
12410
    begin
12411
        do_io_aborts = 1 ;
12412
 
12413
        if (target_io_image === 1)
12414
        begin
12415
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12416
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12417
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12418
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12419
        end
12420
        else if (target_io_image === 2)
12421
        begin
12422
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12423
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12424
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12425
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12426
        end
12427
        else if (target_io_image === 3)
12428
        begin
12429
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12430
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12431
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12432
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12433
        end
12434
        else if (target_io_image === 4)
12435
        begin
12436
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12437
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12438
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12439
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12440
        end
12441
        else if (target_io_image === 5)
12442
        begin
12443
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12444
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12445
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12446
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12447
        end
12448
    end
12449
    else
12450
        do_io_aborts = 0 ;
12451
 
12452
    if ( do_io_aborts )
12453
    begin
12454
 
12455
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
12456
 
12457
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12458
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
12459
        if ( ok !== 1 )
12460
        begin
12461
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12462
            test_fail("PCI Error Control and Status register could not be written") ;
12463
            disable main;
12464
        end
12465
 
12466
        // enable INTERRUPT reporting
12467
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12468
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
12469
        if ( ok !== 1 )
12470
        begin
12471
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
12472
            test_fail("Interrupt Control register could not be written") ;
12473
            disable main;
12474
        end
12475
 
12476
        addr_offset = 12'h010 + (4*target_io_image) ;
12477
 
12478
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
12479
        if ( ok !== 1 )
12480
        begin
12481
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
12482
            test_fail("PCI Base Address register could not be written") ;
12483
            disable main;
12484
        end
12485
 
12486
        // disable address translation and enable prefetch so read bursts can be performed
12487
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
12488
        if ( ok !== 1 )
12489
        begin
12490
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
12491
            test_fail("PCI Image Control register could not be written") ;
12492
            disable main;
12493
        end
12494
 
12495
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
12496
        if ( ok !== 1 )
12497
        begin
12498
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12499
            test_fail("PCI Address Mask register could not be written") ;
12500
            disable main;
12501
        end
12502
 
12503
        addr_offset = 12'h00C ;
12504
 
12505
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
12506
        if ( ok !== 1 )
12507
        begin
12508
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
12509
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
12510
            disable main;
12511
        end
12512
 
12513
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12514
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12515
 
12516
        // do a single read error terminated on WB bus
12517
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
12518
 
12519
        fork
12520
        begin
12521
            PCIU_IO_READ
12522
             (
12523
                `Test_Master_1,
12524
                Target_Base_Addr_R[target_io_image],
12525
                32'hAAAA_5555,
12526
                4'h0,
12527
                1,
12528
                `Test_Target_Retry_On
12529
             );
12530
 
12531
            do_pause( 1 ) ;
12532
        end
12533
        begin
12534
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
12535
 
12536
            if ( ok !== 1 )
12537
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12538
 
12539
            do_pause(3) ;
12540
 
12541
            PCIU_IO_READ
12542
             (
12543
                `Test_Master_1,
12544
                Target_Base_Addr_R[target_io_image],
12545
                32'hAAAA_5555,
12546
                4'h0,
12547
                1,
12548
                `Test_Target_Abort_On
12549
             );
12550
 
12551
            do_pause( 1 ) ;
12552
 
12553
            while ( FRAME === 0 )
12554
                @(posedge pci_clock) ;
12555
 
12556
            while ( IRDY === 0 )
12557
                @(posedge pci_clock) ;
12558
 
12559
            disable monitor_error_event10 ;
12560
        end
12561
        begin:monitor_error_event10
12562
            @(error_event_int) ;
12563
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12564
            ok = 0 ;
12565
        end
12566
        join
12567
 
12568
        if ( ok )
12569
            test_ok ;
12570
 
12571 26 mihad
        @(posedge pci_clock) ;
12572
        @(posedge pci_clock) ;
12573
        @(posedge wb_clock) ;
12574
        @(posedge wb_clock) ;
12575
 
12576 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12577
        addr_offset = 12'h004 ;
12578
        config_read(addr_offset, 4'hF, read_data) ;
12579
        ok = 1 ;
12580
        if ( read_data[27] !== 1 )
12581
        begin
12582
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12583
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12584
            ok = 0 ;
12585
        end
12586
        if ( read_data[28] !== 0 )
12587
        begin
12588
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12589
            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") ;
12590
            ok = 0 ;
12591
        end
12592
        if ( read_data[29] !== 0 )
12593
        begin
12594
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12595
            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") ;
12596
            ok = 0 ;
12597
        end
12598
 
12599
        // clear statuses
12600
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12601
        if ( !ok )
12602
        begin
12603
            test_fail("write to PCI Device Status register failed") ;
12604
            $display("Couldn't write PCI Device Status register") ;
12605
            disable main ;
12606
        end
12607
 
12608
        if ( ok )
12609
            test_ok ;
12610
 
12611
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12612
 
12613
        ok = 1 ;
12614
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12615
 
12616
        config_read(addr_offset, 4'hF, read_data) ;
12617
        if (read_data[8] !== 0)
12618
        begin
12619
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12620
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12621
            ok = 0 ;
12622
        end
12623
        else
12624
            test_ok ;
12625
 
12626
        if ( ok !== 1 )
12627
        begin
12628
            config_write(addr_offset, read_data, 4'hF, ok) ;
12629
            if ( !ok )
12630
            begin
12631
                test_fail("PCI Error Control and Status register could not be written") ;
12632
                disable main ;
12633
            end
12634
        end
12635
 
12636
        test_name = "DISABLE IMAGE" ;
12637
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12638
        if ( ok !== 1 )
12639
        begin
12640
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12641
            test_fail("PCI Address Mask register could not be written") ;
12642
            disable main;
12643
        end
12644
 
12645
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12646
 
12647
    end
12648
end // main
12649
endtask // test_wb_error_rd
12650
 
12651
task test_target_abort ;
12652
    input [2:0]  image_num ;
12653
    reg   [11:0] pci_ctrl_offset ;
12654
    reg   [11:0] ctrl_offset ;
12655
    reg   [11:0] ba_offset ;
12656
    reg   [11:0] am_offset ;
12657
    reg   [11:0] ta_offset ;
12658
    reg   [31:0] pci_address ;
12659
    reg   [3:0]  byte_enables ;
12660
    reg          ok ;
12661
begin:main
12662
    pci_ctrl_offset = 12'h4 ;
12663
    if (image_num === 0)
12664
    begin
12665
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
12666
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
12667
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
12668
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
12669
    end
12670
    else if (image_num === 1)
12671
    begin
12672
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12673
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12674
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12675
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12676
    end
12677
    else if (image_num === 2)
12678
    begin
12679
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12680
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12681
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12682
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12683
    end
12684
    else if (image_num === 3)
12685
    begin
12686
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12687
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12688
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12689
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12690
    end
12691
    else if (image_num === 4)
12692
    begin
12693
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12694
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12695
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12696
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12697
    end
12698
    else if (image_num === 5)
12699
    begin
12700
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12701
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12702
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12703
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12704
    end
12705
 
12706
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
12707
 
12708
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
12709
    if ( ok !== 1 )
12710
    begin
12711
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
12712
        test_fail("PCI Base Address register could not be written") ;
12713
        disable main ;
12714
    end
12715
 
12716
    // Set Address Mask of IMAGE
12717
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
12718
    if ( ok !== 1 )
12719
    begin
12720
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
12721
        test_fail("PCI Address Mask register could not be written") ;
12722
        disable main ;
12723
    end
12724
 
12725
    // Set Translation Address of IMAGE
12726
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
12727
    if ( ok !== 1 )
12728
    begin
12729
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
12730
        test_fail("PCI Translation Address Register could not be written") ;
12731
        disable main ;
12732
    end
12733
 
12734
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
12735
    if ( ok !== 1 )
12736
    begin
12737
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
12738
        test_fail("PCI Image Control register could not be written") ;
12739
        disable main ;
12740
    end
12741
 
12742
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
12743
 
12744
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
12745
 
12746
    pci_address  = Target_Base_Addr_R[image_num] ;
12747
    byte_enables = 4'b0001 ;
12748
 
12749
    fork
12750
    begin
12751
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12752
        do_pause ( 1 ) ;
12753
    end
12754
    begin:monitor_error_event1
12755
        @(error_event_int) ;
12756
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12757
        ok = 0 ;
12758
    end
12759
    begin
12760
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12761
        @(posedge pci_clock) ;
12762
        disable monitor_error_event1 ;
12763
    end
12764
    join
12765
 
12766
    if ( ok )
12767
        test_ok ;
12768
 
12769
    ok = 1 ;
12770
 
12771
    fork
12772
    begin
12773
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12774
        do_pause ( 1 ) ;
12775
    end
12776
    begin:monitor_error_event2
12777
        @(error_event_int) ;
12778
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12779
        ok = 0 ;
12780
    end
12781
    begin
12782
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12783
        @(posedge pci_clock) ;
12784
        disable monitor_error_event2 ;
12785
    end
12786
    join
12787
 
12788
    if ( ok )
12789
        test_ok ;
12790
 
12791
    ok = 1 ;
12792
 
12793
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
12794
    byte_enables = 4'b0011 ;
12795
 
12796
    fork
12797
    begin
12798
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12799
        do_pause ( 1 ) ;
12800
    end
12801
    begin:monitor_error_event3
12802
        @(error_event_int) ;
12803
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12804
        ok = 0 ;
12805
    end
12806
    begin
12807
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12808
        @(posedge pci_clock) ;
12809
        disable monitor_error_event3 ;
12810
    end
12811
    join
12812
 
12813
    if ( ok )
12814
        test_ok ;
12815
 
12816
    ok = 1 ;
12817
 
12818
    byte_enables = 4'b0000 ;
12819
 
12820
    fork
12821
    begin
12822
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12823
        do_pause ( 1 ) ;
12824
    end
12825
    begin:monitor_error_event4
12826
        @(error_event_int) ;
12827
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12828
        ok = 0 ;
12829
    end
12830
    begin
12831
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12832
        @(posedge pci_clock) ;
12833
        disable monitor_error_event4 ;
12834
    end
12835
    join
12836
 
12837
    if ( ok )
12838
        test_ok ;
12839
 
12840
    ok = 1 ;
12841
 
12842
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
12843
    byte_enables = 4'b0111 ;
12844
 
12845
    fork
12846
    begin
12847
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12848
        do_pause ( 1 ) ;
12849
    end
12850
    begin:monitor_error_event5
12851
        @(error_event_int) ;
12852
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12853
        ok = 0 ;
12854
    end
12855
    begin
12856
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12857
        @(posedge pci_clock) ;
12858
        disable monitor_error_event5 ;
12859
    end
12860
    join
12861
 
12862
    if ( ok )
12863
        test_ok ;
12864
 
12865
    ok = 1 ;
12866
 
12867
    byte_enables = 4'b0010 ;
12868
 
12869
    fork
12870
    begin
12871
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12872
        do_pause ( 1 ) ;
12873
    end
12874
    begin:monitor_error_event6
12875
        @(error_event_int) ;
12876
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12877
        ok = 0 ;
12878
    end
12879
    begin
12880
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12881
        @(posedge pci_clock) ;
12882
        disable monitor_error_event6 ;
12883
    end
12884
    join
12885
 
12886
    if ( ok )
12887
        test_ok ;
12888
 
12889
    ok = 1 ;
12890
    byte_enables = 4'b0001 ;
12891
 
12892
    fork
12893
    begin
12894
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12895
        do_pause ( 1 ) ;
12896
    end
12897
    begin:monitor_error_event7
12898
        @(error_event_int) ;
12899
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12900
        ok = 0 ;
12901
    end
12902
    begin
12903
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12904
        @(posedge pci_clock) ;
12905
        disable monitor_error_event7 ;
12906
    end
12907
    join
12908
 
12909
    if ( ok )
12910
        test_ok ;
12911
 
12912
    ok = 1 ;
12913
    byte_enables = 4'b0000 ;
12914
 
12915
    fork
12916
    begin
12917
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12918
        do_pause ( 1 ) ;
12919
    end
12920
    begin:monitor_error_event8
12921
        @(error_event_int) ;
12922
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12923
        ok = 0 ;
12924
    end
12925
    begin
12926
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12927
        @(posedge pci_clock) ;
12928
        disable monitor_error_event8 ;
12929
    end
12930
    join
12931
 
12932
    if ( ok )
12933
        test_ok ;
12934
 
12935
    ok = 1 ;
12936
 
12937
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
12938
    byte_enables = 4'b0110 ;
12939
 
12940
    fork
12941
    begin
12942
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
12943
        do_pause ( 1 ) ;
12944
    end
12945
    begin:monitor_error_event9
12946
        @(error_event_int) ;
12947
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12948
        ok = 0 ;
12949
    end
12950
    begin
12951
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12952
        @(posedge pci_clock) ;
12953
        disable monitor_error_event9 ;
12954
    end
12955
    join
12956
 
12957
    if ( ok )
12958
        test_ok ;
12959
 
12960
    ok = 1 ;
12961
    fork
12962
    begin
12963
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
12964
        do_pause ( 1 ) ;
12965
    end
12966
    begin:monitor_error_event10
12967
        @(error_event_int) ;
12968
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12969
        ok = 0 ;
12970
    end
12971
    begin
12972
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12973
        @(posedge pci_clock) ;
12974
        disable monitor_error_event10 ;
12975
    end
12976
    join
12977
 
12978
    if ( ok )
12979
        test_ok ;
12980
 
12981
    ok = 1 ;
12982
 
12983
    byte_enables = 4'b0001 ;
12984
 
12985
    fork
12986
    begin
12987
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12988
        do_pause ( 1 ) ;
12989
    end
12990
    begin:monitor_error_event11
12991
        @(error_event_int) ;
12992
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12993
        ok = 0 ;
12994
    end
12995
    begin
12996
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12997
        @(posedge pci_clock) ;
12998
        disable monitor_error_event11 ;
12999
    end
13000
    join
13001
 
13002
    if ( ok )
13003
        test_ok ;
13004
 
13005
    ok = 1 ;
13006
 
13007
    byte_enables = 4'b0101 ;
13008
 
13009
    fork
13010
    begin
13011
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13012
        do_pause ( 1 ) ;
13013
    end
13014
    begin:monitor_error_event12
13015
        @(error_event_int) ;
13016
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13017
        ok = 0 ;
13018
    end
13019
    begin
13020
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13021
        @(posedge pci_clock) ;
13022
        disable monitor_error_event12 ;
13023
    end
13024
    join
13025
 
13026
    if ( ok )
13027
        test_ok ;
13028
 
13029
    ok = 1 ;
13030
 
13031
    byte_enables = 4'b0011 ;
13032
 
13033
    fork
13034
    begin
13035
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13036
        do_pause ( 1 ) ;
13037
    end
13038
    begin:monitor_error_event13
13039
        @(error_event_int) ;
13040
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13041
        ok = 0 ;
13042
    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
        disable monitor_error_event13 ;
13047
    end
13048
    join
13049
 
13050
    if ( ok )
13051
        test_ok ;
13052
 
13053
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13054
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
13055
    ok = 1 ;
13056
    if ( pci_address[27] !== 1 )
13057
    begin
13058
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
13059
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
13060
        ok = 0 ;
13061
    end
13062
    if ( pci_address[28] !== 0 )
13063
    begin
13064
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
13065
        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") ;
13066
        ok = 0 ;
13067
    end
13068
    if ( pci_address[29] !== 0 )
13069
    begin
13070
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
13071
        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") ;
13072
        ok = 0 ;
13073
    end
13074
 
13075
    // clear statuses
13076
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
13077
    if ( !ok )
13078
    begin
13079
        test_fail("write to PCI Device Status register failed") ;
13080
        $display("Couldn't write PCI Device Status register") ;
13081
        disable main ;
13082
    end
13083
 
13084
    if ( ok )
13085
        test_ok ;
13086
 
13087
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
13088
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
13089
    if ( pci_address[8] !== 0 )
13090
    begin
13091
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
13092
    end
13093
    else
13094
        test_ok ;
13095
 
13096
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13097
 
13098
    test_name = "DISABLE IMAGE" ;
13099
 
13100
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
13101
    if ( ok !== 1 )
13102
    begin
13103
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
13104
        test_fail("PCI Address Mask register could not be written") ;
13105
        disable main ;
13106
    end
13107
end
13108
endtask // test_target_abort
13109
 
13110
task test_target_io_wr_rd ;
13111
    input [2:0]  image_num ;
13112
    input        translate_address ;
13113
    input [11:0] img_ctrl_offset ;
13114
    reg   [31:0] expect_address ;
13115
    reg   [31:0] pci_address ;
13116
    reg          translation ;
13117
    reg   [31:0] read_data ;
13118
    reg   [3:0]  byte_enables ;
13119
    reg          ok ;
13120
    reg          pci_ok ;
13121
    reg          wb_ok ;
13122
    integer      i ;
13123
begin:main
13124
    `ifdef ADDR_TRAN_IMPL
13125
        translation = translate_address ;
13126
    `else
13127
        translation = 0 ;
13128
    `endif
13129
 
13130
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13131
 
13132
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13133
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13134
    if ( translation )
13135
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13136
    else
13137
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13138
 
13139
    if ( !ok )
13140
    begin
13141
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13142
        test_fail("PCI Image Control register could not be written") ;
13143
    end
13144
 
13145
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
13146
    pci_address  = Target_Base_Addr_R[image_num] ;
13147
    byte_enables = 4'b0000 ;
13148
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13149
 
13150
    fork
13151
    begin
13152
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
13153
        do_pause ( 1 ) ;
13154
    end
13155
    begin
13156
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13157
        if ( wb_ok !== 1 )
13158
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13159
 
13160
        disable monitor_pci_error_1 ;
13161
    end
13162
    begin:monitor_pci_error_1
13163
        pci_ok = 1 ;
13164
        @(error_event_int) ;
13165
        pci_ok = 0 ;
13166
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
13167
    end
13168
    join
13169
 
13170
    byte_enables = 4'b1111 ;
13171
    for ( i = 0 ; i < 4 ; i = i + 1 )
13172
    begin:loop_1
13173
        byte_enables[i] = 0 ;
13174
        if ( i > 0 )
13175
            byte_enables[i - 1] = 1 ;
13176
        fork
13177
        begin
13178
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13179
            do_pause ( 1 ) ;
13180
        end
13181
        begin
13182
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13183
            if ( wb_ok !== 1 )
13184
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13185
 
13186
            disable monitor_pci_error_2 ;
13187
        end
13188
        begin:monitor_pci_error_2
13189
            pci_ok = 1 ;
13190
            @(error_event_int) ;
13191
            pci_ok = 0 ;
13192
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13193
        end
13194
        join
13195
 
13196
        if ( !pci_ok || !wb_ok )
13197
            disable loop_1 ;
13198
 
13199
        pci_address = pci_address + 1 ;
13200
        expect_address = expect_address + 1 ;
13201
    end
13202
 
13203
    if ( pci_ok && wb_ok )
13204
        test_ok ;
13205
 
13206
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
13207
    pci_address  = Target_Base_Addr_R[image_num] ;
13208
    byte_enables = 4'b1100 ;
13209
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13210
 
13211
    master1_check_received_data = 1 ;
13212
    fork
13213
    begin
13214
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13215
        do_pause( 1 ) ;
13216
    end
13217
    begin
13218
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13219
        if ( wb_ok !== 1 )
13220
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13221
 
13222
        do_pause ( 2 ) ;
13223
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13224
        do_pause ( 16 ) ;
13225
 
13226
        disable monitor_pci_error_3 ;
13227
    end
13228
    begin:monitor_pci_error_3
13229
        pci_ok = 1 ;
13230
        @(error_event_int) ;
13231
        pci_ok = 0 ;
13232
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13233
    end
13234
    join
13235
 
13236
    if ( !pci_ok || !wb_ok )
13237
    begin
13238
        disable main ;
13239
    end
13240
 
13241
    pci_address  = Target_Base_Addr_R[image_num] + 2;
13242
    byte_enables = 4'b0011 ;
13243
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13244
 
13245
    master1_check_received_data = 1 ;
13246
    fork
13247
    begin
13248
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13249
        do_pause( 1 ) ;
13250
    end
13251
    begin
13252
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13253
        if ( wb_ok !== 1 )
13254
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13255
 
13256
        do_pause ( 2 ) ;
13257
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13258
        do_pause ( 16 ) ;
13259
 
13260
        disable monitor_pci_error_4 ;
13261
    end
13262
    begin:monitor_pci_error_4
13263
        pci_ok = 1 ;
13264
        @(error_event_int) ;
13265
        pci_ok = 0 ;
13266
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13267
    end
13268
    join
13269
 
13270
    if ( !pci_ok || !wb_ok )
13271
    begin
13272
        disable main ;
13273
    end
13274
 
13275
    pci_address  = Target_Base_Addr_R[image_num] ;
13276
    byte_enables = 4'b0000 ;
13277
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13278
 
13279
    master1_check_received_data = 1 ;
13280
    fork
13281
    begin
13282
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13283
        do_pause( 1 ) ;
13284
    end
13285
    begin
13286
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13287
        if ( wb_ok !== 1 )
13288
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13289
 
13290
        do_pause ( 2 ) ;
13291
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13292
        do_pause ( 16 ) ;
13293
 
13294
        disable monitor_pci_error_5 ;
13295
    end
13296
    begin:monitor_pci_error_5
13297
        pci_ok = 1 ;
13298
        @(error_event_int) ;
13299
        pci_ok = 0 ;
13300
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13301
    end
13302
    join
13303
 
13304
    if ( pci_ok && wb_ok )
13305
        test_ok ;
13306
end
13307
endtask // test_target_io_wr_rd
13308
 
13309
task test_target_io_err_wr ;
13310
    input [2:0]  image_num ;
13311
    input        translate_address ;
13312
    input [11:0] img_ctrl_offset ;
13313
    input        enable_error_report ;
13314
    input        enable_error_interrupt ;
13315
 
13316
    reg   [31:0] expect_address ;
13317
    reg   [31:0] pci_address ;
13318
    reg          translation ;
13319
    reg   [31:0] read_data ;
13320
    reg   [3:0]  byte_enables ;
13321
    reg          ok ;
13322
    reg          pci_ok ;
13323
    reg          wb_ok ;
13324
    integer      i ;
13325
    reg   [11:0] offset ;
13326
begin:main
13327
    `ifdef ADDR_TRAN_IMPL
13328
        translation = translate_address ;
13329
    `else
13330
        translation = 0 ;
13331
    `endif
13332
 
13333
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
13334
 
13335
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13336
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13337
    if ( translation )
13338
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13339
    else
13340
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13341
 
13342
    if ( !ok )
13343
    begin
13344
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13345
        test_fail("PCI Image Control register could not be written") ;
13346
    end
13347
 
13348
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
13349
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13350
    if ( enable_error_report )
13351
    begin
13352
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
13353
        if ( !ok )
13354
        begin
13355
            test_fail("PCI Error Control and Status register could not be written") ;
13356
            disable main ;
13357
        end
13358
    end
13359
    else
13360
    begin
13361
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13362
        if ( !ok )
13363
        begin
13364
            test_fail("PCI Error Control and Status register could not be written") ;
13365
            disable main ;
13366
        end
13367
    end
13368
 
13369
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
13370
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
13371
    if ( enable_error_interrupt )
13372
    begin
13373
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
13374
        if ( !ok )
13375
        begin
13376
            test_fail("Interrupt Control register could not be written") ;
13377
            disable main ;
13378
        end
13379
    end
13380
    else
13381
    begin
13382
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13383
        if ( !ok )
13384
        begin
13385
            test_fail("Interrupt Control register could not be written") ;
13386
            disable main ;
13387
        end
13388
    end
13389
 
13390
    pci_address  = Target_Base_Addr_R[image_num] ;
13391
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13392
 
13393
    byte_enables = 4'b1111 ;
13394
 
13395
    for ( i = 0 ; i < 4 ; i = i + 1 )
13396
    begin:loop_1
13397
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
13398
        byte_enables[i] = 0 ;
13399
        if ( i > 0 )
13400
            byte_enables[i - 1] = 1 ;
13401
 
13402
        fork
13403
        begin
13404
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13405
            do_pause ( 1 ) ;
13406
        end
13407
        begin
13408
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
13409
            if ( wb_ok !== 1 )
13410
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13411
 
13412
            disable monitor_pci_error_2 ;
13413
        end
13414
        begin:monitor_pci_error_2
13415
            pci_ok = 1 ;
13416
            @(error_event_int) ;
13417
            pci_ok = 0 ;
13418
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13419
        end
13420
        join
13421
 
13422
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13423
        `ifdef HOST
13424
 
13425
            repeat ( 4 )
13426
                @( posedge wb_clock ) ;
13427
 
13428
            if ( enable_error_interrupt && enable_error_report )
13429
            begin
13430
                if ( INT_O !== 1 )
13431
                begin
13432
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
13433
                end
13434
            end
13435
            else
13436
            begin
13437
                if ( INT_O !== 0 )
13438
                begin
13439
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
13440
                end
13441
            end
13442
        `else
13443
            repeat ( 4 )
13444
                @( posedge pci_clock ) ;
13445
 
13446
            if ( enable_error_interrupt && enable_error_report )
13447
            begin
13448
                if ( INTA !== 0 )
13449
                begin
13450
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
13451
                end
13452
            end
13453
            else
13454
            begin
13455
                if ( INTA !== 1 )
13456
                begin
13457
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
13458
                end
13459
            end
13460
        `endif
13461
 
13462
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
13463
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13464
        config_read( offset, 4'hF, read_data ) ;
13465
        ok = 1 ;
13466
        if ( enable_error_report )
13467
        begin
13468
            if ( read_data[8] !== 1 )
13469
            begin
13470
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
13471
                ok = 0 ;
13472
            end
13473
 
13474
            if ( read_data[9] !== 0 )
13475
            begin
13476
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
13477
                ok = 0 ;
13478
            end
13479
 
13480
            if ( read_data[31:28] !== byte_enables )
13481
            begin
13482
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
13483
                ok = 0 ;
13484
            end
13485
 
13486
            if ( read_data[27:24] !== `BC_IO_WRITE )
13487
            begin
13488
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
13489
                ok = 0 ;
13490
            end
13491
 
13492
            if ( ok )
13493
                test_ok ;
13494
 
13495
            test_name = "CLEAR ERROR STATUS" ;
13496
            config_write( offset, read_data, 4'hF, ok ) ;
13497
            if ( !ok )
13498
                test_fail("PCI Error Control and Status register could not be written") ;
13499
 
13500
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
13501
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13502
            config_read ( offset, 4'hf, read_data ) ;
13503
 
13504
            if ( read_data !== expect_address )
13505
            begin
13506
                test_fail("value in Erroneous Address register was incorrect") ;
13507
                ok = 0 ;
13508
            end
13509
 
13510
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13511
            config_read ( offset, 4'hf, read_data ) ;
13512
 
13513
            if ( read_data !== 32'hAAAA_AAAA )
13514
            begin
13515
                test_fail("value in Erroneous Data register was incorrect") ;
13516
                ok = 0 ;
13517
            end
13518
 
13519
            if ( ok )
13520
                test_ok ;
13521
 
13522
        end
13523
        else
13524
        begin
13525
            if ( read_data[8] !== 0 )
13526
            begin
13527
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
13528
                ok = 0 ;
13529
            end
13530
            else
13531
                test_ok ;
13532
        end
13533
 
13534
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13535
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
13536
        ok = 1 ;
13537
 
13538
        config_read ( offset, 4'hF, read_data ) ;
13539
        if ( enable_error_report && enable_error_interrupt )
13540
        begin
13541
            if ( read_data[2] !== 1 )
13542
            begin
13543
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
13544
                ok = 0 ;
13545
            end
13546
 
13547
            test_name = "CLEARING INTERRUPT STATUS" ;
13548
            config_write( offset, read_data, 4'hF, ok ) ;
13549
            if ( !ok )
13550
                test_fail("Interrupt Status register could not be written") ;
13551
        end
13552
        else
13553
        begin
13554
            if ( read_data[2] !== 0 )
13555
            begin
13556
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
13557
                ok = 0 ;
13558
            end
13559
        end
13560
 
13561
        if ( ok )
13562
            test_ok ;
13563
 
13564
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
13565
        `ifdef HOST
13566
 
13567
            repeat ( 4 )
13568
                @( posedge wb_clock ) ;
13569
 
13570
            if ( INT_O !== 0 )
13571
            begin
13572
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
13573
            end
13574
            else
13575
                test_ok ;
13576
 
13577
        `else
13578
            repeat ( 4 )
13579
                @( posedge pci_clock ) ;
13580
 
13581
            if ( INTA !== 1 )
13582
            begin
13583
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
13584
            end
13585
            else
13586
                test_ok ;
13587
 
13588
        `endif
13589
 
13590
        pci_address = pci_address + 1 ;
13591
        expect_address = expect_address + 1 ;
13592
    end
13593
 
13594
end
13595
endtask // test_target_io_err_wr
13596
 
13597
task test_pci_image ;
13598
    input [2:0]  image_num ;
13599
    reg   [11:0] pci_ctrl_offset ;
13600
    reg   [11:0] ctrl_offset ;
13601
    reg   [11:0] ba_offset ;
13602
    reg   [11:0] am_offset ;
13603
    reg   [11:0] ta_offset ;
13604
    reg   [7:0]  cache_lsize ;
13605
    reg          ok ;
13606
    reg          test_io ;
13607
    reg          test_mem ;
13608
begin
13609
    pci_ctrl_offset = 12'h4 ;
13610
    if (image_num === 0)
13611
    begin
13612
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
13613
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
13614
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
13615
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
13616
    end
13617
    else if (image_num === 1)
13618
    begin
13619
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13620
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13621
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13622
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13623
    end
13624
    else if (image_num === 2)
13625
    begin
13626
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13627
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13628
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13629
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13630
    end
13631
    else if (image_num === 3)
13632
    begin
13633
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13634
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13635
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13636
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13637
    end
13638
    else if (image_num === 4)
13639
    begin
13640
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13641
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13642
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13643
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13644
    end
13645
    else if (image_num === 5)
13646
    begin
13647
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13648
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13649
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13650
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13651
    end
13652
 
13653
    `ifdef HOST
13654
        test_io  = 1 ;
13655
        test_mem = 1 ;
13656
    `else
13657
        if (image_num == 1)
13658
            test_io = `PCI_BA1_MEM_IO ;
13659
        else if ( image_num == 2 )
13660
            test_io = `PCI_BA2_MEM_IO ;
13661
        else if ( image_num == 3 )
13662
            test_io = `PCI_BA3_MEM_IO ;
13663
        else if ( image_num == 4 )
13664
            test_io = `PCI_BA4_MEM_IO ;
13665
        else if ( image_num == 5 )
13666
            test_io = `PCI_BA5_MEM_IO ;
13667
 
13668
        test_mem = !test_io ;
13669
    `endif
13670
 
13671
    $display(" ");
13672
    $display("########################################################################") ;
13673
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
13674
    test_name = "PCI IMAGE SETTINGS" ;
13675
 
13676
    // Set Base Address of IMAGE
13677
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
13678
    if ( ok !== 1 )
13679
    begin
13680
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13681
        test_fail("PCI Base Address register could not be written") ;
13682
    end
13683
 
13684
    // Set Address Mask of IMAGE
13685
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13686
    if ( ok !== 1 )
13687
    begin
13688
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13689
        test_fail("PCI Address Mask register could not be written") ;
13690
    end
13691
 
13692
    // Set Translation Address of IMAGE
13693
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13694
    if ( ok !== 1 )
13695
    begin
13696
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13697
        test_fail("PCI Translation Address register could not be written") ;
13698
    end
13699
 
13700
// Following are defines for byte enable signals !
13701
//      Byte Masks
13702
//      `Test_Byte_0                            (4'b1110)
13703
//      `Test_Byte_1                            (4'b1101)
13704
//      `Test_Byte_2                            (4'b1011)
13705
//      `Test_Byte_3                            (4'b0111)
13706
//      `Test_Half_0                            (4'b1100)
13707
//      `Test_Half_1                            (4'b0011)
13708
//      `Test_All_Bytes                         (4'b0000)
13709
 
13710
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
13711
    // Set Cache Line Size
13712
    cache_lsize = 8'h4 ;
13713
 
13714
    $display(" ");
13715
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13716
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13717
    if ( ok !== 1 )
13718
    begin
13719
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13720
        test_fail("PCI Device Control and Status register could not be written") ;
13721
    end
13722
 
13723
    if (test_mem)
13724
    begin
13725
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
13726
        // Task test_normal_wr_rd has the following parameters:
13727
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13728
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13729
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13730
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
13731
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
13732
 
13733
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13734
        // Set Cache Line Size
13735
        cache_lsize = 8'h4 ;
13736
 
13737
        $display(" ");
13738
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13739
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13740
        if ( ok !== 1 )
13741
        begin
13742
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13743
            test_fail("Cache Line Size register could not be written" ) ;
13744
        end
13745
 
13746
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
13747
        // Task test_normal_wr_rd has the following parameters:
13748
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13749
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13750
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13751
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
13752
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
13753
 
13754
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13755
        // Set Cache Line Size
13756
        cache_lsize = 8'h8 ;
13757
 
13758
        $display(" ");
13759
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13760
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13761
        if ( ok !== 1 )
13762
        begin
13763
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13764
            test_fail("Cache Line Size register could not be written" ) ;
13765
        end
13766
 
13767
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
13768
        // Task test_normal_wr_rd has the following parameters:
13769
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13770
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13771
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13772
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
13773
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13774
 
13775
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13776
        // Set Cache Line Size
13777
        cache_lsize = 8'h4 ;
13778
 
13779
        $display(" ");
13780
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13781
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13782
        if ( ok !== 1 )
13783
        begin
13784
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13785
            test_fail("Cache Line Size register could not be written" ) ;
13786
        end
13787
 
13788
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
13789
        // Task test_normal_wr_rd has the following parameters:
13790
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13791
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13792
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13793
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
13794
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13795
 
13796
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13797
        $display(" ");
13798
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
13799
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13800
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13801
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
13802
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
13803
 
13804
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13805
        $display(" ");
13806
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
13807
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13808
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13809
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
13810
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
13811
 
13812
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13813
        $display(" ");
13814
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
13815
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13816
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13817
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
13818
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
13819
 
13820
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13821
        $display(" ");
13822
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
13823
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13824
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13825
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
13826
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
13827
    end
13828
 
13829
    if ( test_io )
13830
    begin
13831
        test_name = "PCI IMAGE SETTINGS" ;
13832
 
13833
        // Set Base Address of IMAGE
13834
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
13835
        if ( ok !== 1 )
13836
        begin
13837
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13838
            test_fail("PCI Base Address register could not be written") ;
13839
        end
13840
 
13841
        // Set Address Mask of IMAGE
13842
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13843
        if ( ok !== 1 )
13844
        begin
13845
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13846
            test_fail("PCI Address Mask register could not be written") ;
13847
        end
13848
 
13849
        // Set Translation Address of IMAGE
13850
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13851
        if ( ok !== 1 )
13852
        begin
13853
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13854
            test_fail("PCI Translation Address register could not be written") ;
13855
        end
13856
 
13857
        // Set Cache Line Size
13858
        cache_lsize = 8'h4 ;
13859
 
13860
        $display(" ");
13861
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13862
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13863
        if ( ok !== 1 )
13864
        begin
13865
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13866
            test_fail("Cache Line Size register could not be written" ) ;
13867
        end
13868
 
13869
        test_target_io_wr_rd
13870
        (
13871
            image_num,    // image number
13872
            0,            // test with address translation
13873
            ctrl_offset   // image control register offset
13874
        ) ;
13875
 
13876
        test_target_io_wr_rd
13877
        (
13878
            image_num,    // image number
13879
            1,            // test with address translation
13880
            ctrl_offset   // image control register offset
13881
        ) ;
13882
 
13883
        test_target_io_err_wr
13884
        (
13885
            image_num,      // image number
13886
            0,              // address translation on/off
13887
            ctrl_offset,    // image control register offset
13888
            0,              // enable error reporting
13889
 
13890
        ) ;
13891
 
13892
        test_target_io_err_wr
13893
        (
13894
            image_num,      // image number
13895
            1,              // address translation on/off
13896
            ctrl_offset,    // image control register offset
13897
            0,              // enable error reporting
13898
            1               // enable error interrupts
13899
        ) ;
13900
 
13901
        test_target_io_err_wr
13902
        (
13903
            image_num,      // image number
13904
            0,              // address translation on/off
13905
            ctrl_offset,    // image control register offset
13906
            1,              // enable error reporting
13907
 
13908
        ) ;
13909
 
13910
        test_target_io_err_wr
13911
        (
13912
            image_num,      // image number
13913
            1,              // address translation on/off
13914
            ctrl_offset,    // image control register offset
13915
            1,              // enable error reporting
13916
            1               // enable error interrupts
13917
        ) ;
13918
    end
13919
 
13920
    // Test master abort with NON supported commands
13921
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
13922
 
13923
    // disable the image
13924
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
13925
end
13926
endtask //test_pci_image
13927
 
13928
task target_fast_back_to_back ;
13929
    reg   [11:0] pci_ctrl_offset ;
13930
    reg   [11:0] ctrl_offset ;
13931
    reg   [11:0] ba_offset ;
13932
    reg   [11:0] am_offset ;
13933
    reg   [11:0] ta_offset ;
13934
    reg   [11:0] cls_offset ;
13935
    reg          do_mem_fb2b ;
13936
    reg          do_io_fb2b ;
13937
    reg          ok ;
13938
begin:main
13939
 
13940
    if ( target_mem_image !== -1 )
13941
    begin
13942
        do_mem_fb2b = 1 ;
13943
 
13944
        if (target_mem_image === 1)
13945
        begin
13946
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13947
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13948
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13949
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13950
        end
13951
        else if (target_mem_image === 2)
13952
        begin
13953
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13954
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13955
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13956
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13957
        end
13958
        else if (target_mem_image === 3)
13959
        begin
13960
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13961
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13962
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13963
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13964
        end
13965
        else if (target_mem_image === 4)
13966
        begin
13967
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13968
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13969
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13970
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13971
        end
13972
        else if (target_mem_image === 5)
13973
        begin
13974
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13975
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13976
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13977
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13978
        end
13979
    end
13980
    else
13981
        do_mem_fb2b = 0 ;
13982
 
13983
    pci_ctrl_offset = 12'h4 ;
13984
    cls_offset      = 12'h00C ;
13985
 
13986
    if ( do_mem_fb2b )
13987
    begin
13988
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
13989
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13990
        if ( ok !== 1 )
13991
        begin
13992
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
13993
            test_fail("PCI Base Address register could not be written") ;
13994
            disable main ;
13995
        end
13996
 
13997
        // Set Address Mask of IMAGE
13998
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
13999
        if ( ok !== 1 )
14000
        begin
14001
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14002
            test_fail("PCI Address Mask register could not be written") ;
14003
            disable main ;
14004
        end
14005
 
14006
        // Set Translation Address of IMAGE
14007
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14008
        if ( ok !== 1 )
14009
        begin
14010
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14011
            test_fail("PCI Translation Address Register could not be written") ;
14012
            disable main ;
14013
        end
14014
 
14015
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14016
        if ( ok !== 1 )
14017
        begin
14018
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14019
            test_fail("PCI Image Control register could not be written") ;
14020
            disable main ;
14021
        end
14022
 
14023
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14024
        if ( ok !== 1 )
14025
        begin
14026
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14027
            test_fail("Cache Line Size register could not be written") ;
14028
            disable main ;
14029
        end
14030
 
14031
        // enable master 1 fast_b2b
14032
        configuration_cycle_write(0,             // bus number
14033
                                  1,             // device number
14034
                                  0,             // function number
14035
                                  1,             // register number
14036
                                  0,             // type of configuration cycle
14037
                                  4'b1111,       // byte enables
14038
                                  32'hFFFF_FFFF  // data
14039
                                 ) ;
14040
 
14041
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14042
 
14043
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
14044
        fork
14045
        begin
14046
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14047
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14048
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14049
                  0, `Test_One_Zero_Target_WS,
14050
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14051
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14052
 
14053
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14054
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14055
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14056
                  0, `Test_One_Zero_Target_WS,
14057
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14058
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14059
            do_pause(5) ;
14060
 
14061
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14062
        end
14063
        begin:wb_monitor1
14064
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14065
            if ( ok !== 1 )
14066
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14067
 
14068
            disable monitor_error_event1 ;
14069
        end
14070
        begin:monitor_error_event1
14071
            @(error_event_int) ;
14072
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14073
            ok = 0 ;
14074
            disable wb_monitor1 ;
14075
        end
14076
        join
14077
 
14078
        if ( ok )
14079
            test_ok ;
14080
 
14081
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
14082
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14083
        fork
14084
        begin
14085
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14086
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14087
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14088
                  0, `Test_One_Zero_Target_WS,
14089
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14090
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14091
 
14092
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
14093
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14094
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14095
                  0, `Test_One_Zero_Target_WS,
14096
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14097
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14098
            do_pause(5) ;
14099
 
14100
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14101
 
14102
        end
14103
        begin:wb_monitor2
14104
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
14105
            if ( ok !== 1 )
14106
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14107
            else
14108
            begin
14109
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
14110
                if ( ok !== 1 )
14111
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14112
            end
14113
 
14114
            disable monitor_error_event2 ;
14115
        end
14116
        begin:monitor_error_event2
14117
            @(error_event_int) ;
14118
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14119
            ok = 0 ;
14120
            disable wb_monitor2 ;
14121
        end
14122
        join
14123
 
14124
        if ( ok )
14125
            test_ok ;
14126
 
14127
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
14128
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14129
        fork
14130
        begin
14131
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14132
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14133
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14134
                  0, `Test_One_Zero_Target_WS,
14135
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14136
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14137
 
14138
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14139
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14140
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14141
                  0, `Test_One_Zero_Target_WS,
14142
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14143
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14144
            do_pause(5) ;
14145
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14146
 
14147
        end
14148
        begin:wb_monitor3
14149
            fork
14150
            begin
14151
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14152
                if ( ok !== 1 )
14153
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14154
            end
14155
            begin
14156
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
14157
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
14158
                if ( ok !== 1 )
14159
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14160
            end
14161
            join
14162
 
14163
            if ( ok )
14164
            begin
14165
                fork
14166
                begin
14167
                    do_pause(3) ;
14168
 
14169
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14170
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
14171
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14172
                        0, `Test_One_Zero_Target_WS,
14173
                        `Test_Devsel_Medium, `Test_Fast_B2B,
14174
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14175
 
14176
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14177
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14178
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14179
                            0, `Test_One_Zero_Target_WS,
14180
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14181
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14182
 
14183
                    do_pause(1) ;
14184
                end
14185
                begin
14186
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
14187
                    if ( ok !== 1 )
14188
                    begin
14189
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14190
                        disable monitor_error_event3 ;
14191
                    end
14192
                    else
14193
                    begin
14194
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
14195
                        if ( ok !== 1 )
14196
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14197
                    end
14198
                end
14199 26 mihad
                begin
14200
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14201
                        if ( ok !== 1 )
14202
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14203
                end
14204 15 mihad
                join
14205
            end
14206
            disable monitor_error_event3 ;
14207
        end
14208
        begin:monitor_error_event3
14209
            @(error_event_int) ;
14210
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14211
            ok = 0 ;
14212
            disable wb_monitor3 ;
14213
        end
14214
        join
14215
 
14216
        if ( ok )
14217
            test_ok ;
14218
 
14219
        test_name = "DISABLING MEM IMAGE" ;
14220
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14221
        if ( ok !== 1 )
14222
        begin
14223
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14224
            test_fail("PCI Address Mask register could not be written") ;
14225
            disable main ;
14226
        end
14227
    end
14228
 
14229
    if ( target_io_image !== -1 )
14230
    begin
14231
        do_io_fb2b = 1 ;
14232
 
14233
        if (target_io_image === 1)
14234
        begin
14235
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14236
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14237
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14238
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14239
        end
14240
        else if (target_io_image === 2)
14241
        begin
14242
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14243
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14244
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14245
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14246
        end
14247
        else if (target_io_image === 3)
14248
        begin
14249
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14250
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14251
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14252
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14253
        end
14254
        else if (target_io_image === 4)
14255
        begin
14256
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14257
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14258
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14259
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14260
        end
14261
        else if (target_io_image === 5)
14262
        begin
14263
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14264
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14265
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14266
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14267
        end
14268
    end
14269
    else
14270
        do_io_fb2b = 0 ;
14271
 
14272
    if ( do_io_fb2b )
14273
    begin
14274
 
14275
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
14276
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14277
        if ( ok !== 1 )
14278
        begin
14279
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14280
            test_fail("PCI Base Address register could not be written") ;
14281
            disable main ;
14282
        end
14283
 
14284
        // Set Address Mask of IMAGE
14285
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
14286
        if ( ok !== 1 )
14287
        begin
14288
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14289
            test_fail("PCI Address Mask register could not be written") ;
14290
            disable main ;
14291
        end
14292
 
14293
        // Set Translation Address of IMAGE
14294
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
14295
        if ( ok !== 1 )
14296
        begin
14297
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14298
            test_fail("PCI Translation Address Register could not be written") ;
14299
            disable main ;
14300
        end
14301
 
14302
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14303
        if ( ok !== 1 )
14304
        begin
14305
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14306
            test_fail("PCI Image Control register could not be written") ;
14307
            disable main ;
14308
        end
14309
 
14310
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14311
        if ( ok !== 1 )
14312
        begin
14313
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14314
            test_fail("Cache Line Size register could not be written") ;
14315
            disable main ;
14316
        end
14317
 
14318
        // enable master 1 fast_b2b
14319
        configuration_cycle_write(0,             // bus number
14320
                                  1,             // device number
14321
                                  0,             // function number
14322
                                  1,             // register number
14323
                                  0,             // type of configuration cycle
14324
                                  4'b1111,       // byte enables
14325
                                  32'hFFFF_FFFF  // data
14326
                                 ) ;
14327
 
14328
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14329
 
14330
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
14331
        fork
14332
        begin
14333
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
14334
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
14335
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14336
                  0, `Test_One_Zero_Target_WS,
14337
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14338
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14339
 
14340
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
14341
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
14342
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14343
                  0, `Test_One_Zero_Target_WS,
14344
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14345
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14346
            do_pause(5) ;
14347
 
14348
        end
14349
        begin:wb_monitor4
14350
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
14351
            if ( ok !== 1 )
14352
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14353
 
14354
            if ( ok )
14355
            begin
14356
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
14357
                if ( ok !== 1 )
14358
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14359
            end
14360
 
14361
            disable monitor_error_event4 ;
14362
        end
14363
        begin:monitor_error_event4
14364
            @(error_event_int) ;
14365
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14366
            ok = 0 ;
14367
            disable wb_monitor4 ;
14368
        end
14369
        join
14370
 
14371
        if ( ok )
14372
            test_ok ;
14373
 
14374
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
14375
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14376
        fork
14377
        begin
14378
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14379
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
14380
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14381
                  0, `Test_One_Zero_Target_WS,
14382
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14383
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14384
 
14385
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14386
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14387
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14388
                  0, `Test_One_Zero_Target_WS,
14389
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14390
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14391
            do_pause(5) ;
14392
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14393
        end
14394
        begin:wb_monitor5
14395
            fork
14396
            begin
14397
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
14398
                if ( ok !== 1 )
14399
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14400
            end
14401
            begin
14402
                wb_transaction_stop( 1 ) ;
14403
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
14404
                if ( ok !== 1 )
14405
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14406
            end
14407
            join
14408
 
14409
            if ( ok )
14410
            begin
14411
                fork
14412
                begin
14413
                    do_pause(3) ;
14414
 
14415
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14416
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
14417
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14418
                            0, `Test_One_Zero_Target_WS,
14419
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14420
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14421
 
14422
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14423
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14424
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14425
                            0, `Test_One_Zero_Target_WS,
14426
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14427
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14428
 
14429
                    do_pause(1) ;
14430
                end
14431
                begin
14432
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
14433
                    if ( ok !== 1 )
14434
                    begin
14435
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14436
                        disable monitor_error_event5 ;
14437
                    end
14438
                    else
14439
                    begin
14440
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
14441
                        if ( ok !== 1 )
14442
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14443
                    end
14444
                end
14445
                join
14446
            end
14447
            disable monitor_error_event5 ;
14448
        end
14449
        begin:monitor_error_event5
14450
            @(error_event_int) ;
14451
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14452
            ok = 0 ;
14453
            disable wb_monitor5 ;
14454
        end
14455
        join
14456
 
14457
        if ( ok )
14458
            test_ok ;
14459
 
14460
        test_name = "DISABLING IO IMAGE" ;
14461
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14462
        if ( ok !== 1 )
14463
        begin
14464
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14465
            test_fail("PCI Address Mask register could not be written") ;
14466
            disable main ;
14467
        end
14468
    end
14469
 
14470
end
14471
endtask //target_fast_back_to_back
14472
 
14473
task target_disconnects ;
14474
    reg   [11:0] pci_ctrl_offset ;
14475
    reg   [11:0] ctrl_offset ;
14476
    reg   [11:0] ba_offset ;
14477
    reg   [11:0] am_offset ;
14478
    reg   [11:0] ta_offset ;
14479
    reg   [11:0] cls_offset ;
14480
    reg          pci_ok ;
14481
    reg          wb_ok ;
14482
    reg          ok ;
14483
    reg   [31:0] pci_address ;
14484
    reg   [31:0] data ;
14485
    reg   [3:0]  byte_enables ;
14486
    reg   [9:0]  expect_length ;
14487
 
14488
    reg          do_mem_disconnects ;
14489
    reg          do_io_disconnects ;
14490
begin:main
14491
    if ( target_mem_image !== -1 )
14492
    begin
14493
        do_mem_disconnects = 1 ;
14494
 
14495
        if (target_mem_image === 1)
14496
        begin
14497
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14498
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14499
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14500
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14501
        end
14502
        else if (target_mem_image === 2)
14503
        begin
14504
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14505
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14506
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14507
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14508
        end
14509
        else if (target_mem_image === 3)
14510
        begin
14511
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14512
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14513
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14514
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14515
        end
14516
        else if (target_mem_image === 4)
14517
        begin
14518
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14519
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14520
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14521
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14522
        end
14523
        else if (target_mem_image === 5)
14524
        begin
14525
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14526
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14527
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14528
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14529
        end
14530
    end
14531
    else
14532
        do_mem_disconnects = 0 ;
14533
 
14534
    pci_ctrl_offset = 12'h4 ;
14535
    cls_offset = 12'h00C ;
14536
 
14537
    master1_check_received_data = 0 ;
14538
    master2_check_received_data = 0 ;
14539
 
14540
    `ifdef HOST
14541
        `ifdef NO_CNF_IMAGE
14542
        `else
14543
            `define TEST_BURST_CONFIG_READ
14544
        `endif
14545
    `else
14546
        `define TEST_BURST_CONFIG_READ
14547
        `define TEST_BURST_CONFIG_WRITE
14548
    `endif
14549
 
14550
    `ifdef TEST_BURST_CONFIG_WRITE
14551
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14552
 
14553
        data = 32'h0000_08_08 ;
14554
 
14555
        test_name = "TARGET DISCONNECT ON BURST WRITE TO CONFIGURATION SPACE" ;
14556
        byte_enables = 4'b0000 ;
14557
 
14558
        fork
14559
        begin
14560
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14561
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14562
                    byte_enables,
14563
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14564
                    8'h0_0, `Test_One_Zero_Target_WS,
14565
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14566
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14567
 
14568
            data = 32'h0000_04_04 ;
14569
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14570
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14571
                    byte_enables,
14572
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14573
                    8'h0_0, `Test_One_Zero_Target_WS,
14574
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14575
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14576
            do_pause( 1 ) ;
14577
            while ( FRAME !== 1 || IRDY !== 1 )
14578
                @(posedge pci_clock) ;
14579
 
14580
            disable monitor_error_event1 ;
14581
        end
14582
        begin:monitor_error_event1
14583
            ok = 1 ;
14584
            @(error_event_int) ;
14585
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14586
            ok = 0 ;
14587
        end
14588
        join
14589
 
14590
        config_read(pci_address, 4'hF, data) ;
14591
        if ( data [15:0] !== 16'h04_04 )
14592
        begin
14593
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14594
        end
14595
        else if ( ok )
14596
            test_ok ;
14597
 
14598
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14599
        data         = 32'h0000_0808 ;
14600
        byte_enables = 4'h0 ;
14601
        fork
14602
        begin
14603
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14604
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14605
                    byte_enables,
14606
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14607
                    8'h0_0, `Test_One_Zero_Target_WS,
14608
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14609
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14610
 
14611
            data = 32'h0000_04_04 ;
14612
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14613
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14614
                    byte_enables,
14615
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14616
                    8'h0_0, `Test_One_Zero_Target_WS,
14617
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14618
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14619
 
14620
            do_pause( 1 ) ;
14621
            while ( FRAME !== 1 || IRDY !== 1 )
14622
                @(posedge pci_clock) ;
14623
 
14624
            disable monitor_error_event2 ;
14625
        end
14626
        begin:monitor_error_event2
14627
            ok = 1 ;
14628
            @(error_event_int) ;
14629
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14630
            ok = 0 ;
14631
        end
14632
        join
14633
 
14634
        config_read(pci_address, 4'hF, data) ;
14635
        if ( data [15:0] !== 16'h04_04 )
14636
        begin
14637
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14638
        end
14639
        else if ( ok )
14640
            test_ok ;
14641
    `endif
14642
 
14643
    `ifdef TEST_BURST_CONFIG_READ
14644
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14645
 
14646
        data = 32'h0000_04_04 ;
14647
 
14648
        test_name = "TARGET DISCONNECT ON BURST READ FROM CONFIGURATION SPACE" ;
14649
        byte_enables = 4'b0000 ;
14650
 
14651
        fork
14652
        begin
14653
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14654
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14655
                    byte_enables,
14656
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14657
                    8'h0_0, `Test_One_Zero_Target_WS,
14658
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14659
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14660
            do_pause( 1 ) ;
14661
 
14662
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14663
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14664
                    byte_enables,
14665
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14666
                    8'h0_0, `Test_One_Zero_Target_WS,
14667
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14668
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14669
            do_pause( 1 ) ;
14670
 
14671
            while ( FRAME !== 1 || IRDY !== 1 )
14672
                @(posedge pci_clock) ;
14673
 
14674
            disable monitor_error_event3 ;
14675
        end
14676
        begin:monitor_error_event3
14677
            ok = 1 ;
14678
            @(error_event_int) ;
14679
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14680
            ok = 0 ;
14681
        end
14682
        join
14683
 
14684
        if ( ok )
14685
            test_ok ;
14686
 
14687
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14688
        fork
14689
        begin
14690
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14691
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14692
                    byte_enables,
14693
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14694
                    8'h0_0, `Test_One_Zero_Target_WS,
14695
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14696
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14697
            do_pause( 1 ) ;
14698
 
14699
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14700
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14701
                    byte_enables,
14702
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14703
                    8'h0_0, `Test_One_Zero_Target_WS,
14704
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14705
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14706
            do_pause( 1 ) ;
14707
 
14708
            while ( FRAME !== 1 || IRDY !== 1 )
14709
                @(posedge pci_clock) ;
14710
 
14711
            disable monitor_error_event4 ;
14712
        end
14713
        begin:monitor_error_event4
14714
            ok = 1 ;
14715
            @(error_event_int) ;
14716
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14717
            ok = 0 ;
14718
        end
14719
        join
14720
 
14721
        if ( ok )
14722
            test_ok ;
14723
    `endif
14724
 
14725
    `ifdef TEST_BURST_CONFIG_READ
14726
        `undef TEST_BURST_CONFIG_READ
14727
    `endif
14728
 
14729
    `ifdef TEST_BURST_CONFIG_WRITE
14730
        `undef TEST_BURST_CONFIG_WRITE
14731
    `endif
14732
 
14733
    master1_check_received_data = 1 ;
14734
    master2_check_received_data = 1 ;
14735
 
14736
    if ( do_mem_disconnects )
14737
    begin
14738
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
14739
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
14740
        if ( ok !== 1 )
14741
        begin
14742
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14743
            test_fail("PCI Base Address register could not be written") ;
14744
            disable main ;
14745
        end
14746
 
14747
        // Set Address Mask of IMAGE
14748
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
14749
        if ( ok !== 1 )
14750
        begin
14751
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14752
            test_fail("PCI Address Mask register could not be written") ;
14753
            disable main ;
14754
        end
14755
 
14756
        // Set Translation Address of IMAGE
14757
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14758
        if ( ok !== 1 )
14759
        begin
14760
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14761
            test_fail("PCI Translation Address Register could not be written") ;
14762
            disable main ;
14763
        end
14764
 
14765
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14766
        if ( ok !== 1 )
14767
        begin
14768
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14769
            test_fail("PCI Image Control register could not be written") ;
14770
            disable main ;
14771
        end
14772
 
14773
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
14774
        if ( ok !== 1 )
14775
        begin
14776
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14777
            test_fail("Cache Line Size register could not be written") ;
14778
            disable main ;
14779
        end
14780
 
14781
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14782
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14783
        data = 32'hAAAA_AAAA ;
14784
        byte_enables = 4'h0 ;
14785
        expect_length = `PCIW_DEPTH - 2 ;
14786
 
14787
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14788
        fork
14789
        begin
14790
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14791
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14792
                        byte_enables,
14793
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
14794
                        8'h0_0, `Test_One_Zero_Target_WS,
14795
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14796
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14797
            do_pause( 3 ) ;
14798
 
14799
            while ( FRAME !== 1 || IRDY !== 1 )
14800
                @(posedge pci_clock) ;
14801
 
14802
            disable monitor_error_event5 ;
14803
        end
14804
        begin:monitor_error_event5
14805
            pci_ok = 1 ;
14806
            @(error_event_int) ;
14807
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14808
            pci_ok = 0 ;
14809
        end
14810
        begin
14811
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14812
            if ( wb_ok !== 1 )
14813
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14814
        end
14815
        join
14816
 
14817
        if ( wb_ok && pci_ok )
14818
            test_ok ;
14819
 
14820
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14821
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14822
        data = 32'hAAAA_AAAA ;
14823
        byte_enables = 4'h0 ;
14824
        expect_length = `PCIW_DEPTH - 2 ;
14825
 
14826
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14827
        fork
14828
        begin
14829
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14830
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14831
                        byte_enables,
14832
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
14833
                        8'h0_0, `Test_One_Zero_Target_WS,
14834
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14835
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14836
            do_pause( 3 ) ;
14837
 
14838
            while ( FRAME !== 1 || IRDY !== 1 )
14839
                @(posedge pci_clock) ;
14840
 
14841
            disable monitor_error_event6 ;
14842
        end
14843
        begin:monitor_error_event6
14844
            pci_ok = 1 ;
14845
            @(error_event_int) ;
14846
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14847
            pci_ok = 0 ;
14848
        end
14849
        begin
14850
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14851
            if ( wb_ok !== 1 )
14852
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14853
        end
14854
        join
14855
 
14856
        if ( wb_ok && pci_ok )
14857
            test_ok ;
14858
 
14859
        master1_check_received_data = 1 ;
14860
//        master2_check_received_data = 0 ;
14861
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
14862
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14863
        data = 32'hAAAA_AAAA ;
14864
        byte_enables = 4'h0 ;
14865
        expect_length = 4 ;
14866
 
14867
        fork
14868
        begin
14869
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14870
                        `BC_MEM_READ_LN, 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_Before, `Test_Expect_No_Master_Abort);
14876
            do_pause( 1 ) ;
14877
 
14878
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14879
            if ( wb_ok !== 1 )
14880
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14881
 
14882
            do_pause(2) ;
14883
 
14884
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14885
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14886
                        byte_enables,
14887
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14888
                        8'h0_0, `Test_One_Zero_Target_WS,
14889
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14890
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
14891
            do_pause( 3 ) ;
14892
 
14893
            while ( FRAME !== 1 || IRDY !== 1 )
14894
                @(posedge pci_clock) ;
14895
 
14896
            disable monitor_error_event7 ;
14897
        end
14898
        begin:monitor_error_event7
14899
            pci_ok = 1 ;
14900
            @(error_event_int) ;
14901
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14902
            pci_ok = 0 ;
14903
        end
14904
        join
14905
 
14906
        if ( wb_ok && pci_ok )
14907
            test_ok ;
14908
 
14909
        master1_check_received_data = 1 ;
14910
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
14911
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14912
        data = 32'hAAAA_AAAA ;
14913
        byte_enables = 4'h0 ;
14914
        expect_length = 4 ;
14915
 
14916
        fork
14917
        begin
14918
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14919
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14920
                        byte_enables,
14921
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14922
                        8'h0_0, `Test_One_Zero_Target_WS,
14923
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14924
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14925
            do_pause( 1 ) ;
14926
 
14927
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14928
            if ( wb_ok !== 1 )
14929
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14930
 
14931
            do_pause(2) ;
14932
 
14933
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14934
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14935
                        byte_enables,
14936
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14937
                        8'h0_0, `Test_One_Zero_Target_WS,
14938
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14939
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
14940
            do_pause( 3 ) ;
14941
 
14942
            while ( FRAME !== 1 || IRDY !== 1 )
14943
                @(posedge pci_clock) ;
14944
 
14945
            disable monitor_error_event8 ;
14946
        end
14947
        begin:monitor_error_event8
14948
            pci_ok = 1 ;
14949
            @(error_event_int) ;
14950
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14951
            pci_ok = 0 ;
14952
        end
14953
        join
14954
 
14955
        if ( wb_ok && pci_ok )
14956
            test_ok ;
14957
 
14958
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
14959
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
14960
        data = 32'hDEAF_BEAF ;
14961
        byte_enables = 4'h0 ;
14962
        expect_length = 1 ;
14963
 
14964
        fork
14965
        begin
14966
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
14967
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14968
                        byte_enables,
14969
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14970
                        8'h0_0, `Test_One_Zero_Target_WS,
14971
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14972
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14973
            do_pause( 3 ) ;
14974
 
14975
            while ( FRAME !== 1 || IRDY !== 1 )
14976
                @(posedge pci_clock) ;
14977
 
14978
            disable monitor_error_event9 ;
14979
        end
14980
        begin:monitor_error_event9
14981
            pci_ok = 1 ;
14982
            @(error_event_int) ;
14983
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14984
            pci_ok = 0 ;
14985
        end
14986
        begin
14987
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14988
            if ( wb_ok !== 1 )
14989
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14990
        end
14991
        join
14992
 
14993
        if ( wb_ok && pci_ok )
14994
            test_ok ;
14995
 
14996
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
14997
        data = 32'hDEAD_BEAF ;
14998
        byte_enables = 4'h0 ;
14999
        expect_length = 1 ;
15000
 
15001
        fork
15002
        begin
15003
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15004
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15005
                        byte_enables,
15006
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15007
                        8'h0_0, `Test_One_Zero_Target_WS,
15008
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15009
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15010
            do_pause( 3 ) ;
15011
 
15012
            while ( FRAME !== 1 || IRDY !== 1 )
15013
                @(posedge pci_clock) ;
15014
 
15015
            disable monitor_error_event10 ;
15016
        end
15017
        begin:monitor_error_event10
15018
            pci_ok = 1 ;
15019
            @(error_event_int) ;
15020
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15021
            pci_ok = 0 ;
15022
        end
15023
        begin
15024
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15025
            if ( wb_ok !== 1 )
15026
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15027
        end
15028
        join
15029
 
15030
        if ( wb_ok && pci_ok )
15031
            test_ok ;
15032
 
15033
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15034
        data = 32'hAAAA_AAAA ;
15035
        byte_enables = 4'h0 ;
15036
        expect_length = 1 ;
15037
 
15038
        fork
15039
        begin
15040
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15041
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15042
                        byte_enables,
15043
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15044
                        8'h0_0, `Test_One_Zero_Target_WS,
15045
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15046
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15047
            do_pause( 3 ) ;
15048
 
15049
            while ( FRAME !== 1 || IRDY !== 1 )
15050
                @(posedge pci_clock) ;
15051
 
15052
            disable monitor_error_event11 ;
15053
        end
15054
        begin:monitor_error_event11
15055
            pci_ok = 1 ;
15056
            @(error_event_int) ;
15057
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15058
            pci_ok = 0 ;
15059
        end
15060
        begin
15061
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15062
            if ( wb_ok !== 1 )
15063
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15064
        end
15065
        join
15066
 
15067
        if ( wb_ok && pci_ok )
15068
            test_ok ;
15069
 
15070
        master1_check_received_data = 1 ;
15071
 
15072
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
15073
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
15074
        data = 32'hDEAF_BEAF ;
15075
        byte_enables = 4'h0 ;
15076
        expect_length = 1 ;
15077
 
15078
        fork
15079
        begin
15080
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15081
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15082
                        byte_enables,
15083
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15084
                        8'h0_0, `Test_One_Zero_Target_WS,
15085
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15086
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15087
            do_pause( 1 ) ;
15088
 
15089
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15090
            if ( wb_ok !== 1 )
15091
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15092
 
15093
            do_pause(3) ;
15094
 
15095
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15096
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15097
                        byte_enables,
15098
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15099
                        8'h0_0, `Test_One_Zero_Target_WS,
15100
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15101
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
15102
            do_pause( 3 ) ;
15103
 
15104
            while ( FRAME !== 1 || IRDY !== 1 )
15105
                @(posedge pci_clock) ;
15106
 
15107
            disable monitor_error_event12 ;
15108
        end
15109
        begin:monitor_error_event12
15110
            pci_ok = 1 ;
15111
            @(error_event_int) ;
15112
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15113
            pci_ok = 0 ;
15114
        end
15115
        join
15116
 
15117
        if ( wb_ok && pci_ok )
15118
            test_ok ;
15119
 
15120
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
15121
        data = 32'hDEAD_BEAF ;
15122
        byte_enables = 4'h0 ;
15123
        expect_length = 1 ;
15124
 
15125
        fork
15126
        begin
15127
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15128
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15129
                        byte_enables,
15130
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15131
                        8'h0_0, `Test_One_Zero_Target_WS,
15132
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15133
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15134
            do_pause( 1 ) ;
15135
 
15136
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15137
            if ( wb_ok !== 1 )
15138
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15139
 
15140
            do_pause(3) ;
15141
 
15142
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15143
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15144
                        byte_enables,
15145
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15146
                        8'h0_0, `Test_One_Zero_Target_WS,
15147
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15148
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15149
            do_pause( 3 ) ;
15150
 
15151
            while ( FRAME !== 1 || IRDY !== 1 )
15152
                @(posedge pci_clock) ;
15153
 
15154
            disable monitor_error_event13 ;
15155
        end
15156
        begin:monitor_error_event13
15157
            pci_ok = 1 ;
15158
            @(error_event_int) ;
15159
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15160
            pci_ok = 0 ;
15161
        end
15162
        join
15163
 
15164
        if ( wb_ok && pci_ok )
15165
            test_ok ;
15166
 
15167
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15168
        data = 32'hAAAA_AAAA ;
15169
        byte_enables = 4'h0 ;
15170
        expect_length = 1 ;
15171
 
15172
        fork
15173
        begin
15174
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15175
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15176
                        byte_enables,
15177
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15178
                        8'h0_0, `Test_One_Zero_Target_WS,
15179
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15180
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15181
            do_pause( 1 ) ;
15182
 
15183
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15184
            if ( wb_ok !== 1 )
15185
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15186
 
15187
            do_pause(3) ;
15188
 
15189
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15190
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15191
                        byte_enables,
15192
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15193
                        8'h0_0, `Test_One_Zero_Target_WS,
15194
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15195
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15196
            do_pause( 3 ) ;
15197
 
15198
            while ( FRAME !== 1 || IRDY !== 1 )
15199
                @(posedge pci_clock) ;
15200
 
15201
            disable monitor_error_event14 ;
15202
        end
15203
        begin:monitor_error_event14
15204
            pci_ok = 1 ;
15205
            @(error_event_int) ;
15206
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15207
            pci_ok = 0 ;
15208
        end
15209
        join
15210
 
15211
        if ( wb_ok && pci_ok )
15212
            test_ok ;
15213
 
15214
        // disable the image
15215
        test_name = "DISABLING MEMORY IMAGE" ;
15216
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15217
        if ( ok !== 1 )
15218
        begin
15219
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15220
            test_fail("PCI Address Mask register could not be written") ;
15221
            disable main ;
15222
        end
15223
    end
15224
//*
15225
    if ( target_io_image !== -1 )
15226
    begin
15227
        do_io_disconnects = 1 ;
15228
 
15229
        if (target_io_image === 1)
15230
        begin
15231
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15232
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15233
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15234
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15235
        end
15236
        else if (target_io_image === 2)
15237
        begin
15238
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15239
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15240
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15241
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15242
        end
15243
        else if (target_io_image === 3)
15244
        begin
15245
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15246
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15247
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15248
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15249
        end
15250
        else if (target_io_image === 4)
15251
        begin
15252
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15253
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15254
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15255
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15256
        end
15257
        else if (target_io_image === 5)
15258
        begin
15259
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15260
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15261
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15262
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15263
        end
15264
    end
15265
    else
15266
        do_io_disconnects = 0 ;
15267
 
15268
    if ( do_io_disconnects )
15269
    begin
15270
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
15271
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
15272
        if ( ok !== 1 )
15273
        begin
15274
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15275
            test_fail("PCI Base Address register could not be written") ;
15276
            disable main ;
15277
        end
15278
 
15279
        // Set Address Mask of IMAGE
15280
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
15281
        if ( ok !== 1 )
15282
        begin
15283
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15284
            test_fail("PCI Address Mask register could not be written") ;
15285
            disable main ;
15286
        end
15287
 
15288
        // Set Translation Address of IMAGE
15289
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
15290
        if ( ok !== 1 )
15291
        begin
15292
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15293
            test_fail("PCI Translation Address Register could not be written") ;
15294
            disable main ;
15295
        end
15296
 
15297
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15298
        if ( ok !== 1 )
15299
        begin
15300
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
15301
            test_fail("PCI Image Control register could not be written") ;
15302
            disable main ;
15303
        end
15304
 
15305
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
15306
        if ( ok !== 1 )
15307
        begin
15308
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
15309
            test_fail("Cache Line Size register could not be written") ;
15310
            disable main ;
15311
        end
15312
 
15313
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
15314
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
15315
        data = 32'h5555_5555 ;
15316
        byte_enables = 4'h0 ;
15317
        expect_length = 1 ;
15318
 
15319
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15320
 
15321
        fork
15322
        begin
15323
            PCIU_IO_WRITE
15324
            (
15325
                `Test_Master_1,             // which master
15326
                pci_address,                // to what address
15327
                data,                       // data
15328
                byte_enables,               // byte enable
15329
                expect_length + 1,          // length to request
15330
                `Test_Target_Retry_On       // expected target termination
15331
            ) ;
15332
 
15333
            do_pause( 3 ) ;
15334
 
15335
            while ( FRAME !== 1 || IRDY !== 1 )
15336
                @(posedge pci_clock) ;
15337
 
15338
            disable monitor_error_event15 ;
15339
        end
15340
        begin:monitor_error_event15
15341
            pci_ok = 1 ;
15342
            @(error_event_int) ;
15343
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15344
            pci_ok = 0 ;
15345
        end
15346
        begin
15347
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15348
            if ( wb_ok !== 1 )
15349
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15350
        end
15351
        join
15352
 
15353
        if ( wb_ok && pci_ok )
15354
            test_ok ;
15355
 
15356
        data = 32'hAAAA_AAAA ;
15357
        fork
15358
        begin
15359
            PCIU_IO_WRITE
15360
            (
15361
                `Test_Master_1,             // which master
15362
                pci_address,                // to what address
15363
                data,                       // data
15364
                byte_enables,               // byte enable
15365
                expect_length + 2,          // length to request
15366
                `Test_Target_Retry_Before   // expected target termination
15367
            ) ;
15368
 
15369
            do_pause( 3 ) ;
15370
 
15371
            while ( FRAME !== 1 || IRDY !== 1 )
15372
                @(posedge pci_clock) ;
15373
 
15374
            disable monitor_error_event16 ;
15375
        end
15376
        begin:monitor_error_event16
15377
            pci_ok = 1 ;
15378
            @(error_event_int) ;
15379
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15380
            pci_ok = 0 ;
15381
        end
15382
        begin
15383
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15384
            if ( wb_ok !== 1 )
15385
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15386
        end
15387
        join
15388
 
15389
        if ( wb_ok && pci_ok )
15390
            test_ok ;
15391
 
15392
        master2_check_received_data = 1 ;
15393
 
15394
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
15395
 
15396
        fork
15397
        begin
15398
 
15399
             PCIU_IO_READ
15400
             (
15401
                `Test_Master_2,
15402
                pci_address[PCI_BUS_DATA_RANGE:0],
15403
                data,
15404
                byte_enables,
15405
                2,
15406
                `Test_Target_Retry_Before
15407
             );
15408
 
15409
            do_pause( 1 ) ;
15410
 
15411
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15412
            if ( wb_ok !== 1 )
15413
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15414
 
15415
            do_pause(3) ;
15416
 
15417
            PCIU_IO_READ
15418
             (
15419
                `Test_Master_2,
15420
                pci_address[PCI_BUS_DATA_RANGE:0],
15421
                data,
15422
                byte_enables,
15423
                expect_length + 1,
15424
                `Test_Target_Retry_On
15425
             );
15426
 
15427
            do_pause( 3 ) ;
15428
 
15429
            while ( FRAME !== 1 || IRDY !== 1 )
15430
                @(posedge pci_clock) ;
15431
 
15432
            disable monitor_error_event17 ;
15433
        end
15434
        begin:monitor_error_event17
15435
            pci_ok = 1 ;
15436
            @(error_event_int) ;
15437
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15438
            pci_ok = 0 ;
15439
        end
15440
        join
15441
 
15442
        if ( wb_ok && pci_ok )
15443
            test_ok ;
15444
 
15445
        fork
15446
        begin
15447
 
15448
             PCIU_IO_READ
15449
             (
15450
                `Test_Master_2,
15451
                pci_address[PCI_BUS_DATA_RANGE:0],
15452
                data,
15453
                byte_enables,
15454
                2,
15455
                `Test_Target_Retry_Before
15456
             );
15457
 
15458
            do_pause( 1 ) ;
15459
 
15460
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15461
            if ( wb_ok !== 1 )
15462
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15463
 
15464
            do_pause(3) ;
15465
 
15466
            PCIU_IO_READ
15467
             (
15468
                `Test_Master_2,
15469
                pci_address[PCI_BUS_DATA_RANGE:0],
15470
                data,
15471
                byte_enables,
15472
                expect_length + 2,
15473
                `Test_Target_Retry_Before
15474
             );
15475
 
15476
            do_pause( 3 ) ;
15477
 
15478
            while ( FRAME !== 1 || IRDY !== 1 )
15479
                @(posedge pci_clock) ;
15480
 
15481
            disable monitor_error_event18 ;
15482
        end
15483
        begin:monitor_error_event18
15484
            pci_ok = 1 ;
15485
            @(error_event_int) ;
15486
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15487
            pci_ok = 0 ;
15488
        end
15489
        join
15490
 
15491
        if ( wb_ok && pci_ok )
15492
            test_ok ;
15493
 
15494
        test_name = "DISABLING IO IMAGE" ;
15495
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15496
        if ( ok !== 1 )
15497
        begin
15498
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15499
            test_fail("PCI Address Mask register could not be written") ;
15500
            disable main ;
15501
        end
15502
    end
15503
//*/
15504
end
15505
endtask // target_disconnects
15506
 
15507
task target_unsupported_cmds ;
15508
        input [31:0] Address;
15509
        input [2:0]  image_num ;
15510
    reg          ok ;
15511
begin:main
15512
        // PCI IACK behavioral Target must NOT respond!!!
15513
    irq_respond = 0 ;
15514
 
15515
    $display("  ") ;
15516
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
15517
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
15518
    ipci_unsupported_commands_master.master_reference
15519
    (
15520
        Address,                // first part of address in dual address cycle
15521
        Address,                // second part of address in dual address cycle
15522
        `BC_IACK,                       // dual address cycle command
15523
        `BC_IACK,               // normal command
15524
        4'h0,               // byte enables
15525
        32'h1234_5678,      // data
15526
        1'b0,               // make address parity error on first phase of dual address
15527
        1'b0,               // make address parity error on second phase of dual address
15528
        ok                  // result of operation
15529
    ) ;
15530
    if ( ok )
15531
        test_ok ;
15532
    else
15533
    begin
15534
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15535
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
15536
    end
15537
 
15538
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
15539
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
15540
    ipci_unsupported_commands_master.master_reference
15541
    (
15542
        Address,                // first part of address in dual address cycle
15543
        Address,                // second part of address in dual address cycle
15544
        `BC_SPECIAL,            // dual address cycle command
15545
        `BC_SPECIAL,            // normal command
15546
        4'h0,               // byte enables
15547
        32'h1234_5678,      // data
15548
        1'b0,               // make address parity error on first phase of dual address
15549
        1'b0,               // make address parity error on second phase of dual address
15550
        ok                  // result of operation
15551
    ) ;
15552
    if ( ok )
15553
        test_ok ;
15554
    else
15555
    begin
15556
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15557
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
15558
    end
15559
 
15560
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
15561
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
15562
    ipci_unsupported_commands_master.master_reference
15563
    (
15564
        Address,                // first part of address in dual address cycle
15565
        Address,                // second part of address in dual address cycle
15566
        `BC_RESERVED0,          // dual address cycle command
15567
        `BC_RESERVED0,      // normal command
15568
        4'h0,               // byte enables
15569
        32'h1234_5678,      // data
15570
        1'b0,               // make address parity error on first phase of dual address
15571
        1'b0,               // make address parity error on second phase of dual address
15572
        ok                  // result of operation
15573
    ) ;
15574
    if ( ok )
15575
        test_ok ;
15576
    else
15577
    begin
15578
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15579
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
15580
    end
15581
 
15582
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
15583
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
15584
    ipci_unsupported_commands_master.master_reference
15585
    (
15586
        Address,                // first part of address in dual address cycle
15587
        Address,                // second part of address in dual address cycle
15588
        `BC_RESERVED1,          // dual address cycle command
15589
        `BC_RESERVED1,      // normal command
15590
        4'h0,               // byte enables
15591
        32'h1234_5678,      // data
15592
        1'b0,               // make address parity error on first phase of dual address
15593
        1'b0,               // make address parity error on second phase of dual address
15594
        ok                  // result of operation
15595
    ) ;
15596
    if ( ok )
15597
        test_ok ;
15598
    else
15599
    begin
15600
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15601
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
15602
    end
15603
 
15604
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
15605
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
15606
    ipci_unsupported_commands_master.master_reference
15607
    (
15608
        Address,                // first part of address in dual address cycle
15609
        Address,                // second part of address in dual address cycle
15610
        `BC_RESERVED2,          // dual address cycle command
15611
        `BC_RESERVED2,      // normal command
15612
        4'h0,               // byte enables
15613
        32'h1234_5678,      // data
15614
        1'b0,               // make address parity error on first phase of dual address
15615
        1'b0,               // make address parity error on second phase of dual address
15616
        ok                  // result of operation
15617
    ) ;
15618
    if ( ok )
15619
        test_ok ;
15620
    else
15621
    begin
15622
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15623
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
15624
    end
15625
 
15626
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
15627
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
15628
    ipci_unsupported_commands_master.master_reference
15629
    (
15630
        Address,                // first part of address in dual address cycle
15631
        Address,                // second part of address in dual address cycle
15632
        `BC_RESERVED3,          // dual address cycle command
15633
        `BC_RESERVED3,      // normal command
15634
        4'h0,               // byte enables
15635
        32'h1234_5678,      // data
15636
        1'b0,               // make address parity error on first phase of dual address
15637
        1'b0,               // make address parity error on second phase of dual address
15638
        ok                  // result of operation
15639
    ) ;
15640
    if ( ok )
15641
        test_ok ;
15642
    else
15643
    begin
15644
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15645
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
15646
    end
15647
 
15648
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
15649
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
15650
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
15651
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
15652
    ipci_unsupported_commands_master.master_reference
15653
    (
15654
        Address,                // first part of address in dual address cycle
15655
        Address,                // second part of address in dual address cycle
15656
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
15657
        `BC_MEM_WRITE,      // normal command
15658
        4'h0,               // byte enables;
15659
        32'h1234_5678,      // data
15660
        1'b0,               // make address parity error on first phase of dual address
15661
        1'b0,               // make address parity error on second phase of dual address
15662
        ok                  // result of operation
15663
    ) ;
15664
    if ( ok )
15665
        test_ok ;
15666
    else
15667
    begin
15668
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15669
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
15670
    end
15671
 
15672
    irq_respond = 1 ;
15673
 
15674
end
15675
endtask // target_unsupported_cmds
15676
 
15677
task target_completion_expiration ;
15678
    reg   [11:0] pci_ctrl_offset ;
15679
    reg   [11:0] pci_ba_offset ;
15680
    reg   [11:0] pci_am_offset ;
15681
    reg   [11:0] pci_device_ctrl_offset ;
15682
    reg   [11:0] pci_err_cs_offset ;
15683
    reg   [11:0] icr_offset ;
15684
    reg   [11:0] isr_offset ;
15685
    reg   [11:0] lat_tim_cls_offset ;
15686
 
15687
    reg [31:0] temp_val1 ;
15688
    reg [31:0] temp_val2 ;
15689
    reg        ok   ;
15690
 
15691
    reg [31:0] pci_image_base ;
15692
    integer i ;
15693
 
15694
    reg     error_monitor_done ;
15695
begin:main
15696
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15697
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
15698
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
15699
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15700
 
15701
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
15702
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
15703
    lat_tim_cls_offset = 12'hC ;
15704
    pci_device_ctrl_offset    = 12'h4 ;
15705
 
15706
    pci_image_base = Target_Base_Addr_R[1] ;
15707
 
15708
    // enable master & target operation
15709
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
15710
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
15711
    if ( ok !== 1 )
15712
    begin
15713
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
15714
        test_fail("write to PCI Device Control register failed") ;
15715
        disable main ;
15716
    end
15717
 
15718
    // prepare image control register
15719
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
15720
    if ( ok !== 1 )
15721
    begin
15722
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
15723
        test_fail("write to PCI Image Control register failed") ;
15724
        disable main ;
15725
    end
15726
 
15727
    // prepare base address register
15728
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
15729
    if ( ok !== 1 )
15730
    begin
15731
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
15732
        test_fail("write to PCI Base Address register failed") ;
15733
        disable main ;
15734
    end
15735
 
15736
    // write address mask register
15737
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15738
    if ( ok !== 1 )
15739
    begin
15740
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
15741
        test_fail("write to PCI Address Mask register failed") ;
15742
        disable main ;
15743
    end
15744
 
15745
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
15746
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15747
    if ( ok !== 1 )
15748
    begin
15749
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
15750
        test_fail("write to PCI Error Control and Status register failed") ;
15751
        disable main ;
15752
    end
15753
 
15754
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
15755
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
15756
    if ( ok !== 1 )
15757
    begin
15758
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
15759
        test_fail("write to Interrupt Control register failed") ;
15760
        disable main ;
15761
    end
15762
 
15763
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
15764
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
15765
    if ( ok !== 1 )
15766
    begin
15767
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
15768
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
15769
        disable main ;
15770
    end
15771
 
15772
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15773
 
15774
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15775
    test_name = "FLUSH OF DELAYED READ NOT COMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
15776
 
15777
 
15778
end
15779
endtask // target_completion_expired
15780
 
15781
task config_write ;
15782
    input [11:0] offset ;
15783
    input [31:0] data ;
15784
    input [3:0]  byte_enable ;
15785
    output       ok ;
15786
    `ifdef HOST
15787
    reg   `WRITE_STIM_TYPE   write_data ;
15788
    reg   `WB_TRANSFER_FLAGS write_flags ;
15789
    reg   `WRITE_RETURN_TYPE write_status ;
15790
    `else
15791
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
15792
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
15793
    `endif
15794
    reg in_use ;
15795
    reg [31:0] temp_var ;
15796
begin
15797
    if ( in_use === 1 )
15798
    begin
15799
        $display("config_read task re-entered! Time %t ", $time) ;
15800
        ok = 0 ;
15801
        #20 $stop ;
15802
    end
15803
    else
15804
    begin
15805
        ok = 1 ;
15806
        in_use = 1 ;
15807
    end
15808
    `ifdef HOST
15809
    write_flags                    = 0 ;
15810
    write_flags`INIT_WAITS         = tb_init_waits ;
15811
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
15812
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
15813
 
15814
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
15815
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15816
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
15817
    write_data`WRITE_SEL                         = byte_enable ;
15818
    write_data`WRITE_TAG_STIM                    = 0 ;
15819
    write_data`WRITE_DATA                        = data ;
15820
 
15821
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
15822
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
15823
    begin
15824
        $display("Write to configuration space failed! Time %t ", $time) ;
15825
        ok = 0 ;
15826
    end
15827
 
15828
    @(posedge wb_clock) ;
15829
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
15830
    // here we just wait for two guest cycles for conf space bits to synchronize
15831
    repeat( 2 )
15832
        @(posedge pci_clock) ;
15833
 
15834
    `else // GUEST
15835
    byte_enables_l = ~byte_enable ;
15836
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
15837
 
15838
    fork
15839
    begin
15840
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15841
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15842
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
15843
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15844
              8'h0_0, `Test_One_Zero_Target_WS,
15845
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
15846
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
15847
    do_pause( 1 ) ;
15848
    end
15849
    begin
15850
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
15851
        @(posedge pci_clock) ;
15852
    end
15853
    join
15854
 
15855
     repeat( 2 )
15856
         @(posedge wb_clock) ;
15857
 
15858
    `endif
15859
    in_use = 0 ;
15860
end
15861
endtask // config_write
15862
 
15863
task config_read ;
15864
    input [11:0] offset ;
15865
    input [3:0]  byte_enable ;
15866
    output [31:0] data ;
15867
 
15868
    reg `READ_STIM_TYPE    read_data ;
15869
    reg `WB_TRANSFER_FLAGS read_flags ;
15870
    reg `READ_RETURN_TYPE  read_status ;
15871
 
15872
    reg [31:0] pci_address ;
15873
    reg [3:0] byte_enables_l ;
15874
 
15875
    reg master_check_data_prev ;
15876
    reg in_use ;
15877
    reg [31:0] temp_var ;
15878
begin:main
15879
    if ( in_use === 1 )
15880
    begin
15881
        $display("config_read task re-entered! Time %t ", $time) ;
15882
        data = 32'hxxxx_xxxx ;
15883
        disable main ;
15884
    end
15885
 
15886
    in_use = 1 ;
15887
 
15888
`ifdef HOST
15889 26 mihad
    repeat(4)
15890
        @(posedge pci_clock) ;
15891
    repeat(4)
15892
        @(posedge wb_clock) ;
15893 15 mihad
    read_flags                    = 0 ;
15894
    read_flags`INIT_WAITS         = tb_init_waits ;
15895
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
15896
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
15897
 
15898
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
15899
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15900
 
15901
    read_data`READ_ADDRESS  = temp_var + offset ;
15902
    read_data`READ_SEL      = byte_enable ;
15903
    read_data`READ_TAG_STIM = 0 ;
15904
 
15905
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
15906
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
15907
    begin
15908
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
15909
        #20 $stop ;
15910
    end
15911
    data = read_status`READ_DATA ;
15912
`else
15913
  `ifdef GUEST
15914 26 mihad
    repeat(4)
15915
        @(posedge wb_clock) ;
15916
    repeat(4)
15917
        @(posedge pci_clock) ;
15918 15 mihad
    master_check_data_prev = master2_check_received_data ;
15919
    master2_check_received_data = 0 ;
15920
 
15921
    byte_enables_l = ~byte_enable ;
15922
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
15923
 
15924
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
15925
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
15926
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
15927
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15928
             8'h4_0, `Test_One_Zero_Target_WS,
15929
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
15930
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
15931
    do_pause( 1 ) ;
15932
 
15933
    @(master2_received_data_valid) ;
15934
    data = master2_received_data ;
15935
 
15936
    master2_check_received_data = master_check_data_prev ;
15937
  `endif
15938
`endif
15939
    in_use = 0 ;
15940
end
15941
endtask //config_read
15942
 
15943
task test_fail ;
15944
    input [7999:0] failure_reason ;
15945
    reg   [8007:0] display_failure ;
15946
    reg   [799:0] display_test ;
15947
begin
15948
    tests_failed = tests_failed + 1 ;
15949
 
15950
    display_failure = {failure_reason, "!"} ;
15951
    while ( display_failure[7999:7992] == 0 )
15952
        display_failure = display_failure << 8 ;
15953
 
15954
    display_test = test_name ;
15955
    while ( display_test[799:792] == 0 )
15956
       display_test = display_test << 8 ;
15957
 
15958
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15959
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
15960
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
15961
    $fdisplay( tb_log_file, " *FAILED* because") ;
15962
    $fdisplay( tb_log_file, " %s", display_failure ) ;
15963
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15964
    $fdisplay( tb_log_file, " " ) ;
15965
 
15966
    `ifdef STOP_ON_FAILURE
15967
    #20 $stop ;
15968
    `endif
15969
end
15970
endtask // test_fail
15971
 
15972
task test_ok ;
15973
    reg [799:0] display_test ;
15974
begin
15975
   tests_successfull = tests_successfull + 1 ;
15976
 
15977
   display_test = test_name ;
15978
   while ( display_test[799:792] == 0 )
15979
       display_test = display_test << 8 ;
15980
 
15981
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15982
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
15983
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
15984
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
15985
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
15986
   $fdisplay( tb_log_file, " " ) ;
15987
end
15988
endtask // test_ok
15989
 
15990
task test_summary;
15991
begin
15992
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
15993
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
15994
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
15995
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
15996
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
15997
    $fclose(tb_log_file) ;
15998
end
15999
endtask
16000
 
16001
endmodule

powered by: WebSVN 2.1.0

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