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

Subversion Repositories pci

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

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 33 mihad
 
864
            target_completion_expiration ;
865 15 mihad
            $display(" ") ;
866
            $display("PCI transaction ordering tests finished!") ;
867
        end
868
    end
869
 
870
    test_summary ;
871
 
872
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
873
    $stop ;
874
end
875
endtask // run_tests
876
 
877
task do_reset;
878
begin
879
    next_test_name[79:0] <= "Reset.....";
880
 
881
    reset = 1'b1 ;
882
    #100 ;
883
    `ifdef HOST
884
        @(posedge wb_clock) ;
885
    `else
886
    `ifdef GUEST
887
        @(posedge pci_clock) ;
888
    `endif
889
    `endif
890
 
891
    reset <= 1'b0 ;
892
 
893
end
894
endtask
895
 
896
/*############################################################################
897
WB SLAVE UNIT tasks
898
===================
899
############################################################################*/
900
 
901
task configure_target ;
902
    input [1:0]  device_num ;
903
    reg   [31:0] base_address1 ;
904
    reg   [31:0] base_address2 ;
905
    reg   [2:0]  Master_ID;
906
    reg   [31:0] Target_Config_Addr;
907
begin
908
    if (device_num === 1)
909
    begin
910
        base_address1       = `BEH_TAR1_MEM_START ;
911
        base_address2       = `BEH_TAR1_IO_START  ;
912
        Master_ID           = `Test_Master_2 ;
913
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
914
    end
915
    else
916
    if (device_num === 2)
917
    begin
918
        base_address1       = `BEH_TAR2_MEM_START ;
919
        base_address2       = `BEH_TAR2_IO_START  ;
920
        Master_ID           = `Test_Master_1 ;
921
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
922
    end
923
 
924
    // write target's base addresses
925
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
926
    // type 0 cycle, byte enables, base address
927
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
928
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
929
 
930
    // enable target's response and master
931
    // enable parity errors, disable system error
932
 
933
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
934
 
935
end
936
endtask //configure_target
937
 
938
task test_wb_image ;
939
    input [2:0]  image_num ;
940
    reg   [11:0] ctrl_offset ;
941
    reg   [11:0] ba_offset ;
942
    reg   [11:0] am_offset ;
943
    reg   [11:0] ta_offset ;
944
    reg   [11:0] err_cs_offset ;
945
    reg `WRITE_STIM_TYPE write_data ;
946
    reg `READ_STIM_TYPE  read_data ;
947
    reg `READ_RETURN_TYPE read_status ;
948
 
949
    reg `WRITE_RETURN_TYPE write_status ;
950
    reg `WB_TRANSFER_FLAGS write_flags ;
951
    reg [31:0] temp_val ;
952
    reg        ok   ;
953
    reg [11:0] pci_ctrl_offset ;
954
    reg [31:0] image_base ;
955
    reg [31:0] target_address ;
956
    reg [31:0] translation_address ;
957
    integer    i ;
958
    integer    j ;
959
begin:main
960
    pci_ctrl_offset = 12'h4 ;
961
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
962
    // image 0 can only be configuration image - start with 1
963
    if (image_num === 1)
964
    begin
965
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
966
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
967
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
968
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
969
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
970
    end
971
    else if (image_num === 2)
972
    begin
973
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
974
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
975
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
976
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
977
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
978
    end
979
    else if (image_num === 3)
980
    begin
981
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
982
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
983
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
984
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
985
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
986
    end
987
    else if (image_num === 4)
988
    begin
989
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
990
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
991
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
992
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
993
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
994
    end
995
    else if (image_num === 5)
996
    begin
997
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
998
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
999
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1000
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1001
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1002
    end
1003
    else
1004
    begin
1005
        test_name   = "WB IMAGES' FEATURES TEST" ;
1006
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1007
        disable main ;
1008
    end
1009
 
1010
    target_address  = `BEH_TAR1_MEM_START ;
1011
    image_base      = 0 ;
1012
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1013
 
1014
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1015
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1016
    write_flags                      = 0 ;
1017
    write_flags`INIT_WAITS           = tb_init_waits ;
1018
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1019
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1020
 
1021
    test_name = "WB IMAGE CONFIGURATION" ;
1022
    // enable master & target operation
1023
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1024
    if ( ok !== 1 )
1025
    begin
1026
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1027
        test_fail("write to PCI Device Control register didn't succeede");
1028
        disable main ;
1029
    end
1030
 
1031
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1032
    if ( ok !== 1 )
1033
    begin
1034
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1035
        test_fail("write to WB Error Control and Status register didn't succeede");
1036
        disable main ;
1037
    end
1038
 
1039
    // prepare image control register
1040
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1041
    if ( ok !== 1 )
1042
    begin
1043
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1044
        test_fail("write to WB Image Control register didn't succeede");
1045
        disable main ;
1046
    end
1047
 
1048
    // prepare base address register
1049
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1050
    if ( ok !== 1 )
1051
    begin
1052
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1053
        test_fail("write to WB Base Address register didn't succeede");
1054
        disable main ;
1055
    end
1056
 
1057
    // write address mask register
1058
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1059
    if ( ok !== 1 )
1060
    begin
1061
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1062
        test_fail("write to WB Address Mask register didn't succeede");
1063
        disable main ;
1064
    end
1065
 
1066
    fork
1067
    begin
1068
        write_data`WRITE_ADDRESS = target_address ;
1069
        write_data`WRITE_DATA    = wmem_data[0] ;
1070
        write_data`WRITE_SEL     = 4'hF ;
1071
 
1072
        // handle retries from now on
1073
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1074
 
1075
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1076
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1077
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1078
        begin
1079
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1080
            test_fail("WB Slave state machine failed to post single memory write");
1081
            disable main ;
1082
        end
1083
 
1084
        // read written data back
1085
        read_data`READ_ADDRESS  = target_address ;
1086
        read_data`READ_SEL      = 4'hF ;
1087
        read_data`READ_TAG_STIM = 0 ;
1088
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1089
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1090
        begin
1091
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1092
            test_fail("PCI bridge didn't process the read as expected");
1093
            disable main ;
1094
        end
1095
 
1096
        if (read_status`READ_DATA !== wmem_data[0])
1097
        begin
1098
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1099
            test_fail("PCI bridge returned unexpected Read Data");
1100
        end
1101
        else
1102
            test_ok ;
1103
    end
1104
    begin
1105
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1106
        if ( ok !== 1 )
1107
        begin
1108
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1109
        end
1110
        else
1111
            test_ok ;
1112
 
1113
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1114
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1115
        if ( ok !== 1 )
1116
        begin
1117
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1118
        end
1119
    end
1120
    join
1121
 
1122
    // if address translation is implemented - try it out
1123
    translation_address = image_base ;
1124
    `ifdef ADDR_TRAN_IMPL
1125
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1126
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1127
    if ( ok !== 1 )
1128
    begin
1129
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1130
        test_fail("write to WB Image Translation Address Register failed") ;
1131
        disable main ;
1132
    end
1133
 
1134
    target_address  = `BEH_TAR2_MEM_START ;
1135
    image_base      = 0 ;
1136
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1137
 
1138
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1139
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1140
 
1141
    write_flags                      = 0 ;
1142
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1143
 
1144
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1145
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1146
    if ( ok !== 1 )
1147
    begin
1148
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1149
        test_fail("write to WB Image Base Address Register failed") ;
1150
        disable main ;
1151
    end
1152
 
1153
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1154
    // enable address translation
1155
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1156
    if ( ok !== 1 )
1157
    begin
1158
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1159
        test_fail("write to WB Image Control Register failed") ;
1160
        disable main ;
1161
    end
1162
 
1163
    `endif
1164
 
1165
    fork
1166
    begin
1167
        write_data`WRITE_ADDRESS = target_address + 4 ;
1168
        write_data`WRITE_DATA    = wmem_data[1] ;
1169
        write_data`WRITE_SEL     = 4'hF ;
1170
 
1171
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1172
 
1173
        `ifdef ADDR_TRAN_IMPL
1174
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1175
        `else
1176
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1177
        `endif
1178
 
1179
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1180
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1181
        begin
1182
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1183
            test_fail("WB Slave state machine failed to post single memory write") ;
1184
            disable main ;
1185
        end
1186
 
1187
        // read written data back
1188
        read_data`READ_ADDRESS  = target_address + 4 ;
1189
        read_data`READ_SEL      = 4'hF ;
1190
        read_data`READ_TAG_STIM = 0 ;
1191
 
1192
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1193
 
1194
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1195
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1196
        begin
1197
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1198
            test_fail("PCI bridge failed to process single delayed memory read") ;
1199
            disable main ;
1200
        end
1201
 
1202
        if (read_status`READ_DATA !== wmem_data[1])
1203
        begin
1204
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1205
            test_fail("PCI bridge returned unexpected Read Data");
1206
        end
1207
        else
1208
            test_ok ;
1209
    end
1210
    begin
1211
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 4, translation_address, 1'b1 ), `BC_MEM_WRITE, 1, 0, 1'b1, 0, 0, ok ) ;
1212
        if ( ok !== 1 )
1213
        begin
1214
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1215
        end
1216
        else
1217
            test_ok ;
1218
 
1219
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1220
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 4, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1221
        if ( ok !== 1 )
1222
        begin
1223
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1224
        end
1225
    end
1226
    join
1227
 
1228
    // now do one burst write - length of 6 - minimum depth of fifo is 8, one loc. is always free and one is taken up by address entry
1229
    // prepare write data
1230
    for ( i = 0 ; i < 6 ; i = i + 1 )
1231
    begin
1232
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1233
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1234
        write_data`WRITE_SEL     = 4'hF ;
1235
        wishbone_master.blk_write_data[i] = write_data ;
1236
    end
1237
 
1238
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1239
    write_flags`WB_TRANSFER_CAB    = 1 ;
1240
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1241
 
1242
    fork
1243
    begin
1244
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1245
        wishbone_master.wb_block_write(write_flags, write_status) ;
1246
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1247
        begin
1248
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1249
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1250
            disable main ;
1251
        end
1252
    end
1253
    begin
1254
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_WRITE, 6, 0, 1'b1, 0, 0, ok ) ;
1255
        if ( ok !== 1 )
1256
        begin
1257
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1258
        end
1259
        else
1260
            test_ok ;
1261
    end
1262
    join
1263
 
1264
    // set burst size and latency timer
1265
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1266
 
1267
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1268
    write_flags`WB_TRANSFER_CAB    = 1 ;
1269
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1270
 
1271
    // prepare read data
1272
    for ( i = 0 ; i < 4 ; i = i + 1 )
1273
    begin
1274
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1275
        read_data`READ_SEL     = 4'hF ;
1276
        wishbone_master.blk_read_data_in[i] = read_data ;
1277
    end
1278
 
1279
    fork
1280
    begin
1281
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1282
        wishbone_master.wb_block_read(write_flags, read_status) ;
1283
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1284
        begin
1285
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1286
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1287
            disable main ;
1288
        end
1289
 
1290
        // check data read from target
1291
        for ( i = 0 ; i < 4 ; i = i + 1 )
1292
        begin
1293
            read_status = wishbone_master.blk_read_data_out[i] ;
1294
            if (read_status`READ_DATA !== wmem_data[2 + i])
1295
            begin
1296
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1297
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1298
            end
1299
        end
1300
    end
1301
    begin
1302
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1303
        if ( ok !== 1 )
1304
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1305
        else
1306
            test_ok ;
1307
 
1308
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 12, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1309
        if ( ok !== 1 )
1310
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1311
        else
1312
            test_ok ;
1313
 
1314
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 16, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1315
        if ( ok !== 1 )
1316
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1317
        else
1318
            test_ok ;
1319
 
1320
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 20, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1321
        if ( ok !== 1 )
1322
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1323
        else
1324
            test_ok ;
1325
 
1326
    end
1327
    join
1328
 
1329
    // now repeat this same burst read with various image features enabled or disabled
1330
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1331
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1332
    if (ok !== 1)
1333
    begin
1334
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1335
        test_fail("write to WB Image control register failed") ;
1336
        disable main ;
1337
    end
1338
 
1339
    fork
1340
    begin
1341
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1342
        wishbone_master.wb_block_read(write_flags, read_status) ;
1343
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1344
        begin
1345
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1346
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1347
            disable main ;
1348
        end
1349
 
1350
        // check data read from target
1351
        for ( i = 0 ; i < 4 ; i = i + 1 )
1352
        begin
1353
            read_status = wishbone_master.blk_read_data_out[i] ;
1354
            if (read_status`READ_DATA !== wmem_data[2 + i])
1355
            begin
1356
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1357
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1358
            end
1359
            else
1360
                test_ok ;
1361
        end
1362
    end
1363
    begin
1364
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ_LN, 4, 0, 1'b1, 0, 0, ok ) ;
1365
        if ( ok !== 1 )
1366
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1367
    end
1368
    join
1369
 
1370
    read_data`READ_ADDRESS  = target_address ;
1371
    read_data`READ_SEL      = 4'hF ;
1372
    read_data`READ_TAG_STIM = 0 ;
1373
 
1374
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1375
    fork
1376
    begin
1377
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1378
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1379
        begin
1380
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1381
            test_fail("delayed single memory read wasn't processed as expected") ;
1382
            disable main ;
1383
        end
1384
 
1385
        if (read_status`READ_DATA !== wmem_data[0])
1386
        begin
1387
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1388
            test_fail("delayed single memory read data value returned was not as expected") ;
1389
        end
1390
        else
1391
            test_ok ;
1392
    end
1393
    begin
1394
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1395
        if ( ok !== 1 )
1396
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1397
    end
1398
    join
1399
 
1400
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1401
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1402
    if (ok !== 1)
1403
    begin
1404
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1405
        test_fail("write to WB Image control register failed") ;
1406
        disable main ;
1407
    end
1408
 
1409
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1410
    fork
1411
    begin
1412
        wishbone_master.wb_block_read(write_flags, read_status) ;
1413
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1414
        begin
1415
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1416
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1417
            disable main ;
1418
        end
1419
 
1420
        // check data read from target
1421
        for ( i = 0 ; i < 4 ; i = i + 1 )
1422
        begin
1423
            read_status = wishbone_master.blk_read_data_out[i] ;
1424
            if (read_status`READ_DATA !== wmem_data[2 + i])
1425
            begin
1426
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1427
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1428
            end
1429
            else
1430
                test_ok ;
1431
        end
1432
    end
1433
    begin
1434
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 4, 0, 1'b1, 0, 0, ok ) ;
1435
        if ( ok !== 1 )
1436
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1437
    end
1438
    join
1439
 
1440
    read_data`READ_ADDRESS  = target_address + 4 ;
1441
    read_data`READ_SEL      = 4'hF ;
1442
    read_data`READ_TAG_STIM = 0 ;
1443
 
1444
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1445
    fork
1446
    begin
1447
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1448
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1449
        begin
1450
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1451
            test_fail("delayed single memory read wasn't processed as expected") ;
1452
            disable main ;
1453
        end
1454
 
1455
        if (read_status`READ_DATA !== wmem_data[1])
1456
        begin
1457
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1458
            test_fail("delayed single memory read data value returned was not as expected") ;
1459
        end
1460
        else
1461
            test_ok ;
1462
    end
1463
    begin
1464
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 4, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1465
        if ( ok !== 1 )
1466
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1467
    end
1468
    join
1469
 
1470
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1471
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1472
    if (ok !== 1)
1473
    begin
1474
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1475
        test_fail("write to WB Image control register failed") ;
1476
        disable main ;
1477
    end
1478
 
1479
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1480
    fork
1481
    begin
1482
        wishbone_master.wb_block_read(write_flags, read_status) ;
1483
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1484
        begin
1485
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1486
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1487
            disable main ;
1488
        end
1489
 
1490
        // check data read from target
1491
        for ( i = 0 ; i < 4 ; i = i + 1 )
1492
        begin
1493
            read_status = wishbone_master.blk_read_data_out[i] ;
1494
            if (read_status`READ_DATA !== wmem_data[2 + i])
1495
            begin
1496
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1497
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1498
            end
1499
            else
1500
                test_ok ;
1501
        end
1502
    end
1503
    begin
1504
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 0, 0, ok ) ;
1505
        if ( ok !== 1 )
1506
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1507
    end
1508
    join
1509
 
1510
    read_data`READ_ADDRESS  = target_address + 8 ;
1511
    read_data`READ_SEL      = 4'hF ;
1512
    read_data`READ_TAG_STIM = 0 ;
1513
 
1514
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1515
    fork
1516
    begin
1517
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1518
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1519
        begin
1520
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1521
            test_fail("delayed single memory read wasn't processed as expected") ;
1522
            disable main ;
1523
        end
1524
 
1525
        if (read_status`READ_DATA !== wmem_data[2])
1526
        begin
1527
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1528
            test_fail("delayed single memory read data value returned was not as expected") ;
1529
        end
1530
        else
1531
            test_ok ;
1532
    end
1533
    begin
1534
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1535
        if ( ok !== 1 )
1536
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1537
    end
1538
    join
1539
 
1540
    // map image to IO space
1541
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1542
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1543
    if ( ok !== 1 )
1544
    begin
1545
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1546
        test_fail("write to WB Image Base Address register failed") ;
1547
        disable main ;
1548
    end
1549
 
1550
    write_data`WRITE_ADDRESS = target_address ;
1551
    write_data`WRITE_DATA    = wmem_data[11] ;
1552
    write_data`WRITE_SEL     = 4'hF ;
1553
 
1554
    // handle retries from now on
1555
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1556
 
1557
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1558
    fork
1559
    begin
1560
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1561
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1562
        begin
1563
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1564
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1565
            disable main ;
1566
        end
1567
    end
1568
    begin
1569
        // currently IO commands not supported in behavioral models - master abort
1570
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address, translation_address, 1'b1 ), `BC_IO_WRITE, 0, 0, 1'b1, 0, 0, ok ) ;
1571
        if ( ok !== 1 )
1572
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1573
        else
1574
            test_ok ;
1575
    end
1576
    join
1577
 
1578
    read_data`READ_ADDRESS  = target_address ;
1579
    read_data`READ_SEL      = 4'hF ;
1580
    read_data`READ_TAG_STIM = 0 ;
1581
 
1582
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1583
 
1584
    // currently io commands are not supported by behavioral target - transfer should not be completed
1585
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1586
    fork
1587
    begin
1588
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1589
        if (read_status`CYC_ERR !== 1)
1590
        begin
1591
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1592
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1593
            disable main ;
1594
        end
1595
        else
1596
            test_ok ;
1597
    end
1598
    begin
1599
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address, translation_address, 1'b1 ), `BC_IO_READ, 0, 0, 1'b1, 0, 0, ok ) ;
1600
        if ( ok !== 1 )
1601
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1602
    end
1603
    join
1604
 
1605
    // test byte addressing
1606
    read_data`READ_ADDRESS = target_address + 2 ;
1607
    read_data`READ_SEL     = 4'b1100 ;
1608
 
1609
    fork
1610
    begin
1611
        // currently io commands are not supported by behavioral target - transfer should not be completed
1612
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1613
        if (read_status`CYC_ERR !== 1)
1614
        begin
1615
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1616
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1617
            disable main ;
1618
        end
1619
        else test_ok ;
1620
    end
1621
    begin
1622
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 2, translation_address, 1'b1 ), `BC_IO_READ, 0, 0, 1'b1, 0, 0, ok ) ;
1623
        if ( ok !== 1 )
1624
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1625
    end
1626
    join
1627
 
1628
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1629
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1630
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1631
    if ( ok !== 1 )
1632
    begin
1633
        test_fail("WB Base address register could not be written") ;
1634
        disable main ;
1635
    end
1636
 
1637
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1638
    if ( ok !== 1 )
1639
    begin
1640
        test_fail("WB Address Mask register could not be written") ;
1641
        disable main ;
1642
    end
1643
 
1644
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1645
    if ( ok !== 1 )
1646
    begin
1647
        test_fail("WB Image Control register could not be written") ;
1648
        disable main ;
1649
    end
1650
 
1651
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1652
    write_data`WRITE_DATA    = wmem_data[11] ;
1653
    write_data`WRITE_SEL     = 4'b1000 ;
1654
 
1655
    // handle retries from now on
1656
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1657
 
1658
    fork
1659
    begin
1660
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1661
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1662
        begin
1663
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1664
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1665
            disable main ;
1666
        end
1667
    end
1668
    begin
1669
        // currently IO commands not supported in behavioral models - master abort
1670
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1671
        if ( ok !== 1 )
1672
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1673
        else
1674
            test_ok ;
1675
    end
1676
    join
1677
 
1678
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1679
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1680
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1681
 
1682
    fork
1683
    begin
1684
        // currently io commands are not supported by behavioral target - transfer should not be completed
1685
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1686
        if (read_status`CYC_ERR !== 1)
1687
        begin
1688
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1689
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1690
            disable main ;
1691
        end
1692
        else test_ok ;
1693
    end
1694
    begin
1695
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1696
        if ( ok !== 1 )
1697
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1698
    end
1699
    join
1700
 
1701
    test_name = "DISABLING WB IMAGE" ;
1702
 
1703
    // disable current image
1704
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1705
    if ( ok !== 1 )
1706
    begin
1707
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1708
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1709
        disable main ;
1710
    end
1711
 
1712
    // clear master abort status bit
1713
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1714
    if ( ok !== 1 )
1715
    begin
1716
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1717
        test_fail("write to PCI Device Status register not accepted as expected") ;
1718
        disable main ;
1719
    end
1720
 
1721
end //main
1722
endtask //test_wb_image
1723
 
1724
task wb_slave_errors ;
1725
    reg   [11:0] ctrl_offset ;
1726
    reg   [11:0] ba_offset ;
1727
    reg   [11:0] am_offset ;
1728
    reg   [11:0] ta_offset ;
1729
    reg `WRITE_STIM_TYPE write_data ;
1730
    reg `READ_STIM_TYPE  read_data ;
1731
    reg `READ_RETURN_TYPE read_status ;
1732
 
1733
    reg `WRITE_RETURN_TYPE write_status ;
1734
    reg `WB_TRANSFER_FLAGS write_flags ;
1735
    reg [31:0] temp_val1 ;
1736
    reg [31:0] temp_val2 ;
1737
    reg        ok   ;
1738
    reg [11:0] pci_ctrl_offset ;
1739
    reg [31:0] image_base ;
1740
    reg [31:0] target_address ;
1741
    integer    i ;
1742
    reg skip ;
1743
fork
1744
begin:main
1745
 
1746
    `ifdef GUEST
1747
        skip = 1 ;
1748
    `else
1749
        skip = 0 ;
1750
    `endif
1751
 
1752
    pci_ctrl_offset = 12'h4 ;
1753
 
1754
    // image 1 is used for error testing, since it is always implemented
1755
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1756
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1757
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1758
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1759
 
1760
    target_address  = `BEH_TAR1_MEM_START ;
1761
    image_base      = 0 ;
1762
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1763
 
1764
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1765
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1766
    write_flags                    = 0 ;
1767
    write_flags`INIT_WAITS         = tb_init_waits ;
1768
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1769
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1770
 
1771
    // enable master & target operation
1772
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1773
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1774
    if ( ok !== 1 )
1775
    begin
1776
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1777
        test_fail("PCI Device Control register couldn't be written") ;
1778
        disable no_transaction ;
1779
        disable main ;
1780
    end
1781
 
1782
    // prepare image control register
1783
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1784
    if ( ok !== 1 )
1785
    begin
1786
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1787
        test_fail("WB Image Control register couldn't be written") ;
1788
        disable no_transaction ;
1789
        disable main ;
1790
    end
1791
 
1792
    // prepare base address register
1793
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1794
    if ( ok !== 1 )
1795
    begin
1796
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1797
        test_fail("WB Base Address register couldn't be written") ;
1798
        disable no_transaction ;
1799
        disable main ;
1800
    end
1801
 
1802
    // write address mask register
1803
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1804
    if ( ok !== 1 )
1805
    begin
1806
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1807
        test_fail("WB Address Mask register couldn't be written") ;
1808
        disable no_transaction ;
1809
        disable main ;
1810
    end
1811
 
1812
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1813
 
1814
    skip = 0 ;
1815
 
1816
    // memory mapped image - access is erroneous when address is not alligned
1817
    write_data`WRITE_ADDRESS = target_address + 1 ;
1818
    write_data`WRITE_DATA    = wmem_data[0] ;
1819
    write_data`WRITE_SEL     = 4'hF ;
1820
 
1821
    // handle retries from now on
1822
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1823
 
1824
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1825
 
1826
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1827
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1828
    begin
1829
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1830
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1831
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1832
        disable no_transaction ;
1833
        disable main ;
1834
    end
1835
 
1836
    write_data`WRITE_ADDRESS = target_address + 2 ;
1837
 
1838
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1839
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1840
    begin
1841
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1842
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1843
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1844
        disable no_transaction ;
1845
        disable main ;
1846
 
1847
    end
1848
 
1849
    write_data`WRITE_ADDRESS = target_address + 3 ;
1850
 
1851
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1852
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1853
    begin
1854
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1855
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1856
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1857
        disable no_transaction ;
1858
        disable main ;
1859
    end
1860
 
1861
    test_ok ;
1862
 
1863
    // perform same tests for read accesses
1864
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1865
 
1866
    read_data`READ_ADDRESS  = target_address + 2 ;
1867
    read_data`READ_SEL      = 4'hF ;
1868
    read_data`READ_TAG_STIM = 0 ;
1869
 
1870
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1871
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1872
    begin
1873
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1874
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1875
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1876
        disable no_transaction ;
1877
        disable main ;
1878
    end
1879
 
1880
    test_ok ;
1881
 
1882
    // prepare write data
1883
    for ( i = 0 ; i < 6 ; i = i + 1 )
1884
    begin
1885
        write_data`WRITE_DATA    = wmem_data[i] ;
1886
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1887
        write_data`WRITE_SEL     = 4'hF ;
1888
        wishbone_master.blk_write_data[i] = write_data ;
1889
    end
1890
 
1891
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1892
    write_flags`WB_TRANSFER_CAB    = 1 ;
1893
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1894
 
1895
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1896
    wishbone_master.wb_block_write(write_flags, write_status) ;
1897
 
1898
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1899
    begin
1900
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1901
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1902
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1903
        disable no_transaction ;
1904
        disable main ;
1905
    end
1906
 
1907
    // prepare read data
1908
    for ( i = 0 ; i < 6 ; i = i + 1 )
1909
    begin
1910
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1911
        read_data`READ_SEL     = 4'hF ;
1912
        wishbone_master.blk_read_data_in[i] = read_data ;
1913
    end
1914
 
1915
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1916
    wishbone_master.wb_block_read(write_flags, read_status) ;
1917
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1918
    begin
1919
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1920
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1921
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
1922
        disable no_transaction ;
1923
        disable main ;
1924
    end
1925
 
1926
    test_ok ;
1927
 
1928
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1929
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
1930
 
1931
    // map image to IO space
1932
    `ifdef GUEST
1933
        skip = 1 ;
1934
    `endif
1935
 
1936
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
1937
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1938
    if ( ok !== 1 )
1939
    begin
1940
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1941
        test_fail("WB Image Base Address register couldn't be written") ;
1942
        disable no_transaction ;
1943
        disable main ;
1944
    end
1945
 
1946
    skip = 0 ;
1947
 
1948
    write_data`WRITE_ADDRESS = target_address ;
1949
    write_data`WRITE_DATA    = wmem_data[0] ;
1950
    write_data`WRITE_SEL     = 4'b1010 ;
1951
 
1952
    // don't handle retries
1953
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1954
 
1955
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
1956
 
1957
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1958
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1959
    begin
1960
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1961
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1962
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1963
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1964
        disable no_transaction ;
1965
        disable main ;
1966
    end
1967
 
1968
    write_data`WRITE_ADDRESS = target_address + 1 ;
1969
    write_data`WRITE_SEL     = 4'b0011 ;
1970
 
1971
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1972
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1973
    begin
1974
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1975
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1976
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1977
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1978
        disable no_transaction ;
1979
        disable main ;
1980
    end
1981
 
1982
    write_data`WRITE_SEL     = 4'b1100 ;
1983
 
1984
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1985
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1986
    begin
1987
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
1988
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
1989
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1990
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
1991
        disable no_transaction ;
1992
        disable main ;
1993
    end
1994
 
1995
    write_data`WRITE_ADDRESS = target_address + 2 ;
1996
    write_data`WRITE_SEL     = 4'b0101 ;
1997
 
1998
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1999
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2000
    begin
2001
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2002
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2003
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2004
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2005
        disable no_transaction ;
2006
        disable main ;
2007
    end
2008
 
2009
    write_data`WRITE_SEL     = 4'b1000 ;
2010
 
2011
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2012
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2013
    begin
2014
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2015
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2016
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2017
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2018
        disable no_transaction ;
2019
        disable main ;
2020
    end
2021
 
2022
    write_data`WRITE_ADDRESS = target_address + 3 ;
2023
    write_data`WRITE_SEL     = 4'b1010 ;
2024
 
2025
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2026
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2027
    begin
2028
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2029
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2030
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2031
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2032
        disable no_transaction ;
2033
        disable main ;
2034
    end
2035
 
2036
    write_data`WRITE_SEL     = 4'b0110 ;
2037
 
2038
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2039
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2040
    begin
2041
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2042
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2043
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2044
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2045
        disable no_transaction ;
2046
        disable main ;
2047
    end
2048
 
2049
    test_ok ;
2050
 
2051
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2052
 
2053
    read_data`READ_ADDRESS  = target_address + 3 ;
2054
    read_data`READ_SEL      = 4'hF ;
2055
    read_data`READ_TAG_STIM = 0 ;
2056
 
2057
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2058
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2059
    begin
2060
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2061
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2062
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2063
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2064
        disable no_transaction ;
2065
        disable main ;
2066
    end
2067
 
2068
    test_ok ;
2069
 
2070
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2071
    // prepare write data
2072
    for ( i = 0 ; i < 6 ; i = i + 1 )
2073
    begin
2074
        write_data`WRITE_DATA    = wmem_data[i] ;
2075
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2076
        write_data`WRITE_SEL     = 4'hF ;
2077
        wishbone_master.blk_write_data[i] = write_data ;
2078
    end
2079
 
2080
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2081
    write_flags`WB_TRANSFER_CAB    = 1 ;
2082
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2083
 
2084
    wishbone_master.wb_block_write(write_flags, write_status) ;
2085
 
2086
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2087
    begin
2088
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2089
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2090
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2091
        disable no_transaction ;
2092
        disable main ;
2093
    end
2094
 
2095
    test_ok ;
2096
 
2097
    test_name = "CAB I/O READ TO WB SLAVE" ;
2098
    // prepare read data
2099
    for ( i = 0 ; i < 6 ; i = i + 1 )
2100
    begin
2101
        read_data`READ_ADDRESS = target_address + 4*i ;
2102
        read_data`READ_SEL     = 4'hF ;
2103
        wishbone_master.blk_read_data_in[i] = read_data ;
2104
    end
2105
 
2106
    wishbone_master.wb_block_read(write_flags, read_status) ;
2107
 
2108
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2109
    begin
2110
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2111
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2112
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2113
        disable no_transaction ;
2114
        disable main ;
2115
    end
2116
 
2117
    test_ok ;
2118
 
2119
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2120
 
2121
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2122
 
2123
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2124
    write_data`WRITE_ADDRESS = target_address + 1 ;
2125
    write_data`WRITE_DATA    = wmem_data[0] ;
2126
    write_data`WRITE_SEL     = 4'hF ;
2127
 
2128
    // don't handle retries
2129
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2130
 
2131
    `ifdef HOST
2132
        `define DO_W_CONF_TEST
2133
        `define DO_R_CONF_TEST
2134
    `else
2135
        `ifdef WB_CNF_IMAGE
2136
             `define DO_R_CONF_TEST
2137
        `endif
2138
    `endif
2139
 
2140
    `ifdef DO_W_CONF_TEST
2141
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2142
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2143
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2144
    begin
2145
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2146
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2147
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2148
        disable no_transaction ;
2149
        disable main ;
2150
    end
2151
 
2152
    write_data`WRITE_ADDRESS = target_address + 2 ;
2153
 
2154
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2155
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2156
    begin
2157
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2158
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2159
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2160
        disable no_transaction ;
2161
        disable main ;
2162
    end
2163
 
2164
    write_data`WRITE_ADDRESS = target_address + 3 ;
2165
 
2166
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2167
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2168
    begin
2169
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2170
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2171
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2172
        disable no_transaction ;
2173
        disable main ;
2174
    end
2175
 
2176
    test_ok ;
2177
    `endif
2178
 
2179
    `ifdef DO_R_CONF_TEST
2180
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2181
    read_data`READ_ADDRESS  = target_address + 3 ;
2182
    read_data`READ_SEL      = 4'hF ;
2183
    read_data`READ_TAG_STIM = 0 ;
2184
 
2185
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2186
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2187
    begin
2188
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2189
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2190
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2191
        disable no_transaction ;
2192
        disable main ;
2193
    end
2194
 
2195
    test_ok ;
2196
    `endif
2197
 
2198
    `ifdef DO_W_CONF_TEST
2199
    // prepare write data
2200
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2201
    for ( i = 0 ; i < 6 ; i = i + 1 )
2202
    begin
2203
        write_data`WRITE_DATA    = wmem_data[i] ;
2204
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2205
        write_data`WRITE_SEL     = 4'hF ;
2206
        wishbone_master.blk_write_data[i] = write_data ;
2207
    end
2208
 
2209
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2210
    write_flags`WB_TRANSFER_CAB    = 1 ;
2211
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2212
 
2213
    wishbone_master.wb_block_write(write_flags, write_status) ;
2214
 
2215
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2216
    begin
2217
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2218
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2219
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2220
        disable no_transaction ;
2221
        disable main ;
2222
    end
2223
    test_ok ;
2224
    `endif
2225
 
2226
    `ifdef DO_R_CONF_TEST
2227
    // prepare read data
2228
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2229
    for ( i = 0 ; i < 6 ; i = i + 1 )
2230
    begin
2231
        read_data`READ_ADDRESS = target_address + 4*i ;
2232
        read_data`READ_SEL     = 4'hF ;
2233
        wishbone_master.blk_read_data_in[i] = read_data ;
2234
    end
2235
 
2236
    wishbone_master.wb_block_read(write_flags, read_status) ;
2237
 
2238
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2239
    begin
2240
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2241
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2242
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2243
        disable no_transaction ;
2244
        disable main ;
2245
    end
2246
    test_ok ;
2247
    `endif
2248
 
2249
    `ifdef GUEST
2250
        skip = 1 ;
2251
    `endif
2252
 
2253
    // disable image
2254
    test_name = "DISABLE IMAGE" ;
2255
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2256
    if ( ok !== 1 )
2257
    begin
2258
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2259
        test_fail("WB Address Mask register couldn't be written") ;
2260
        disable no_transaction ;
2261
        disable main ;
2262
    end
2263
 
2264
    skip = 0 ;
2265
 
2266
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2267
 
2268
    disable no_transaction ;
2269
end
2270
begin:no_transaction
2271
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2272
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2273
    forever
2274
    begin
2275
        @(posedge pci_clock) ;
2276
        if ( skip !== 1 )
2277
        begin
2278
            if ( FRAME !== 1 )
2279
            begin
2280
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2281
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2282
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2283
            end
2284
        end
2285
    end
2286
end
2287
join
2288
endtask //wb_slave_errors
2289
 
2290
task wb_to_pci_error_handling ;
2291
    reg   [11:0] ctrl_offset ;
2292
    reg   [11:0] ba_offset ;
2293
    reg   [11:0] am_offset ;
2294
    reg   [11:0] ta_offset ;
2295
    reg   [11:0] err_cs_offset ;
2296
    reg `WRITE_STIM_TYPE write_data ;
2297
    reg `READ_STIM_TYPE  read_data ;
2298
    reg `READ_RETURN_TYPE read_status ;
2299
 
2300
    reg `WRITE_RETURN_TYPE write_status ;
2301
    reg `WB_TRANSFER_FLAGS write_flags ;
2302
    reg [31:0] temp_val1 ;
2303
    reg [31:0] temp_val2 ;
2304
    reg        ok   ;
2305
    reg [11:0] pci_ctrl_offset ;
2306
    reg [31:0] image_base ;
2307
    reg [31:0] target_address ;
2308
    integer    num_of_trans ;
2309
    integer    current ;
2310
    integer    i ;
2311
begin:main
2312
 
2313
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2314
 
2315
    pci_ctrl_offset = 12'h4 ;
2316
 
2317
    // disable error interrupts and disable error reporting
2318
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2319
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2320
    if ( ok !== 1 )
2321
    begin
2322
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2323
        test_fail("PCI Device Control register couldn't be written") ;
2324
        disable main ;
2325
    end
2326
 
2327
    // image 1 is used for error testing, since it is always implemented
2328
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2329
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2330
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2331
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2332
 
2333
    // set master abort testing address to address that goes out of target's range
2334
    target_address  = `BEH_TAR1_MEM_START ;
2335
    image_base      = 0 ;
2336
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2337
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2338
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2339
 
2340
    write_flags                    = 0 ;
2341
    write_flags`INIT_WAITS         = tb_init_waits ;
2342
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2343
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2344
 
2345
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2346
 
2347
    // enable master & target operation
2348
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2349
    if ( ok !== 1 )
2350
    begin
2351
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2352
        test_fail("PCI Device Control register couldn't be written") ;
2353
        disable main ;
2354
    end
2355
 
2356
    // prepare image control register
2357
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2358
    if ( ok !== 1 )
2359
    begin
2360
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2361
        test_fail("WB Image Control register couldn't be written") ;
2362
        disable main ;
2363
    end
2364
 
2365
    // prepare base address register
2366
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2367
    if ( ok !== 1 )
2368
    begin
2369
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2370
        test_fail("WB Image Base Address register couldn't be written") ;
2371
        disable main ;
2372
    end
2373
 
2374
    // write address mask register
2375
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2376
    if ( ok !== 1 )
2377
    begin
2378
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2379
        test_fail("WB Image Address Mask register couldn't be written") ;
2380
        disable main ;
2381
    end
2382
 
2383
    // disable error reporting
2384
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2385
    if ( ~ok )
2386
    begin
2387
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2388
        test_fail("WB Error Control and Status register couldn't be written") ;
2389
        disable main ;
2390
    end
2391
 
2392
    // perform two writes - one to error address and one to OK address
2393
    // prepare write buffer
2394
 
2395
    write_data`WRITE_ADDRESS = target_address ;
2396
    write_data`WRITE_DATA    = wmem_data[100] ;
2397
    write_data`WRITE_SEL     = 4'hF ;
2398
 
2399
    wishbone_master.blk_write_data[0] = write_data ;
2400
 
2401
    write_flags`WB_TRANSFER_SIZE = 2 ;
2402
 
2403
    // don't handle retries
2404
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2405
    write_flags`WB_TRANSFER_CAB    = 0 ;
2406
 
2407
    $display("Introducing master abort error on single WB to PCI write!") ;
2408
 
2409
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2410
    // first disable target 1
2411
 
2412
    configuration_cycle_write(0,             // bus number
2413
                              1,             // device number
2414
                              0,             // function number
2415
                              1,             // register number
2416
                              0,             // type of configuration cycle
2417
                              4'b0001,       // byte enables
2418
                              32'h0000_0000  // data
2419
                             ) ;
2420
 
2421
    fork
2422
    begin
2423
        // start no response monitor in parallel with writes
2424
        musnt_respond(ok) ;
2425
        if ( ok !== 1 )
2426
        begin
2427
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2428
            $display("Testbench is configured wrong!") ;
2429
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2430
        end
2431
        else
2432
            test_ok ;
2433
    end
2434
    begin
2435
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2436
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2437
       begin
2438
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2439
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2440
           test_fail("WB Slave state machine failed to post single memory write");
2441
           disable main ;
2442
       end
2443
    end
2444
    join
2445
 
2446
    /*// read data from second write
2447
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2448
    read_data`READ_ADDRESS = target_address ;
2449
    read_data`READ_SEL     = 4'hF ;
2450
    read_data`READ_TAG_STIM = 0 ;
2451
 
2452
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2453
 
2454
    if ( read_status`READ_DATA !== wmem_data[101] )
2455
    begin
2456
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2457
    end
2458
    */
2459
 
2460
    // read error status register - no errors should be reported since reporting was disabled
2461
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2462
 
2463
    @(posedge pci_clock) ;
2464
    // wait for two WB clocks for synchronization to be finished
2465
    repeat (2)
2466
        @(posedge wb_clock) ;
2467
 
2468
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2469
    if ( temp_val1[8] !== 0 )
2470
    begin
2471
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2472
        $display("Error reporting was disabled, but error was reported anyway!") ;
2473
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2474
        disable main ;
2475
    end
2476
    test_ok ;
2477
 
2478
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2479
    // check for interrupts - there should be no interrupt requests active
2480
    `ifdef HOST
2481
        repeat(4)
2482
            @(posedge wb_clock) ;
2483
 
2484
        if ( INT_O !== 0 )
2485
        begin
2486
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2487
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2488
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2489
        end
2490
        else
2491
            test_ok ;
2492
    `else
2493
    `ifdef GUEST
2494
        repeat( 4 )
2495
            @(posedge pci_clock) ;
2496
 
2497
        if ( INTA !== 1 )
2498
        begin
2499
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2500
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2501
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2502
        end
2503
        else
2504
            test_ok ;
2505
    `endif
2506
    `endif
2507
 
2508
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2509
    // check PCI status register
2510
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2511
    if ( temp_val1[29] !== 1 )
2512
    begin
2513
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2514
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2515
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2516
    end
2517
    else
2518
        test_ok ;
2519
 
2520
    // clear
2521
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2522
 
2523
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2524
 
2525
    $display("Introducing master abort error to CAB write!") ;
2526
    // now enable error reporting mechanism
2527
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2528
    // enable error interrupts
2529
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2530
 
2531
    // configure flags for CAB transfer
2532
    write_flags`WB_TRANSFER_CAB = 1 ;
2533
    write_flags`WB_TRANSFER_SIZE = 3 ;
2534
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2535
 
2536
    // prepare data for erroneous write
2537
    for ( i = 0 ; i < 3 ; i = i + 1 )
2538
    begin
2539
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2540
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2541
        write_data`WRITE_SEL     = 4'hF ;
2542
        wishbone_master.blk_write_data[i] = write_data ;
2543
    end
2544
 
2545
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2546
    fork
2547
    begin
2548
        wishbone_master.wb_block_write(write_flags, write_status) ;
2549
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2550
        begin
2551
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2552
            $display("Complete burst write through WB slave didn't succeed!") ;
2553
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2554
            disable main ;
2555
        end
2556
    end
2557
    begin
2558
        musnt_respond(ok) ;
2559
        if ( ok !== 1 )
2560
        begin
2561
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2562
            $display("Testbench is configured wrong!") ;
2563
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2564
        end
2565
        else
2566
            test_ok ;
2567
    end
2568
    join
2569
 
2570
    // check error status address, data, byte enables and bus command
2571
    // error status bit is signalled on PCI clock and synchronized to WB clock
2572
    // wait one PCI clock cycle
2573
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2574
    ok = 1 ;
2575
    @(posedge pci_clock) ;
2576
 
2577
    // wait for two WB clocks for synchronization to be finished
2578
    repeat (2)
2579
        @(posedge wb_clock) ;
2580
 
2581
    // read registers
2582
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2583
    if ( temp_val1[8] !== 1 )
2584
    begin
2585
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2586
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2587
        ok = 0 ;
2588
    end
2589
 
2590
    if ( temp_val1[9] !== 1 )
2591
    begin
2592
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2593
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2594
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2595
        ok = 0 ;
2596
    end
2597
 
2598
    if ( temp_val1[31:28] !== 0 )
2599
    begin
2600
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2601
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2602
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2603
        ok = 0 ;
2604
    end
2605
 
2606
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2607
    begin
2608
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2609
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2610
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2611
        ok = 0 ;
2612
    end
2613
 
2614
    // read error address register
2615
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2616
    if ( temp_val1 !== target_address )
2617
    begin
2618
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2619
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2620
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2621
        ok = 0 ;
2622
    end
2623
 
2624
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2625
    if ( temp_val1 !== wmem_data[110] )
2626
    begin
2627
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2628
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2629
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2630
        ok = 0 ;
2631
    end
2632
 
2633
    // check PCI status register
2634
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2635
    if ( temp_val1[29] !== 1 )
2636
    begin
2637
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2638
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2639
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2640
        ok = 0 ;
2641
    end
2642
 
2643
    if ( temp_val1[28] !== 0 )
2644
    begin
2645
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2646
        $display("Received Target Abort bit was set for no reason!") ;
2647
        test_fail("Received Target Abort bit was set for no reason") ;
2648
        ok = 0 ;
2649
    end
2650
 
2651
    if ( ok )
2652
        test_ok ;
2653
 
2654
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2655
 
2656
    // clear error status bit
2657
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2658
 
2659
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2660
 
2661
    ok = 1 ;
2662
 
2663
    `ifdef HOST
2664
        repeat(4)
2665
        @(posedge wb_clock) ;
2666
        if ( INT_O !== 1 )
2667
        begin
2668
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2669
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2670
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2671
            ok = 0 ;
2672
        end
2673
    `else
2674
    `ifdef GUEST
2675
        repeat(4)
2676
        @(posedge pci_clock) ;
2677
        if ( INTA !== 0 )
2678
        begin
2679
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2680
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2681
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2682
            ok = 0 ;
2683
        end
2684
    `endif
2685
    `endif
2686
 
2687
    // read interrupt status register
2688
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2689
    if ( temp_val1 !== 32'h0000_0002 )
2690
    begin
2691
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2692
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2693
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2694
        test_fail("Interrupt Status register returned wrong value") ;
2695
        ok = 0 ;
2696
    end
2697
 
2698
    if ( ok )
2699
        test_ok ;
2700
    // clear interrupt status bits
2701
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2702
 
2703
    ok = 1 ;
2704
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2705
    // wait for two clock cycles before checking interrupt request deassertion
2706
    `ifdef HOST
2707
        repeat (4)
2708
            @(posedge wb_clock) ;
2709
 
2710
        if ( INT_O !== 0 )
2711
        begin
2712
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2713
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2714
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2715
            ok = 0 ;
2716
        end
2717
    `else
2718
    `ifdef GUEST
2719
        repeat (4)
2720
            @(posedge pci_clock) ;
2721
 
2722
        if ( INTA !== 1 )
2723
        begin
2724
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2725
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2726
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2727
            ok = 0 ;
2728
        end
2729
    `endif
2730
    `endif
2731
 
2732
    if ( ok )
2733
        test_ok ;
2734
 
2735
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2736
    ok = 1 ;
2737
    // enable target
2738
    configuration_cycle_write(0,             // bus number
2739
                              1,             // device number
2740
                              0,             // function number
2741
                              1,             // register number
2742
                              0,             // type of configuration cycle
2743
                              4'b0001,       // byte enables
2744
                              32'h0000_0007  // data
2745
                             ) ;
2746
    // prepare data for ok write
2747
    for ( i = 0 ; i < 3 ; i = i + 1 )
2748
    begin
2749
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2750
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2751
        write_data`WRITE_SEL     = 4'hF ;
2752
        wishbone_master.blk_write_data[i] = write_data ;
2753
    end
2754
 
2755
    wishbone_master.wb_block_write(write_flags, write_status) ;
2756
 
2757
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2758
    begin
2759
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2760
        $display("Complete burst write through WB slave didn't succeed!") ;
2761
        test_fail("WB Slave state machine failed to post CAB write") ;
2762
        disable main ;
2763
    end
2764
 
2765
    // do a read
2766
    for ( i = 0 ; i < 3 ; i = i + 1 )
2767
    begin
2768
        read_data`READ_ADDRESS = target_address + 4*i ;
2769
        read_data`READ_SEL     = 4'hF ;
2770
        wishbone_master.blk_read_data_in[i] = read_data ;
2771
    end
2772
 
2773
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2774
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2775
    write_flags`WB_TRANSFER_CAB    = 1 ;
2776
 
2777
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2778
 
2779
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2780
    begin
2781
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2782
        $display("Complete burst read through WB slave didn't succeed!") ;
2783
        test_fail("Delayed CAB write was not processed as expected") ;
2784
        disable main ;
2785
    end
2786
 
2787
    for ( i = 0 ; i < 3 ; i = i + 1 )
2788
    begin
2789
        read_status = wishbone_master.blk_read_data_out[i] ;
2790
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2791
        begin
2792
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2793
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2794
        end
2795
    end
2796
 
2797
    $display("Introducing master abort error to single read!") ;
2798
    // disable target
2799
    configuration_cycle_write(0,             // bus number
2800
                              1,             // device number
2801
                              0,             // function number
2802
                              1,             // register number
2803
                              0,             // type of configuration cycle
2804
                              4'b0001,       // byte enables
2805
                              32'h0000_0000  // data
2806
                             ) ;
2807
    // set read data
2808
    read_data`READ_ADDRESS = target_address ;
2809
    read_data`READ_SEL     = 4'hF ;
2810
 
2811
    // enable automatic retry handling
2812
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2813
    write_flags`WB_TRANSFER_CAB    = 0 ;
2814
 
2815
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2816
    fork
2817
    begin
2818
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2819
    end
2820
    begin
2821
        musnt_respond(ok) ;
2822
        if ( ok !== 1 )
2823
        begin
2824
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2825
            $display("Testbench is configured wrong!") ;
2826
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2827
        end
2828
    end
2829
    join
2830
 
2831
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2832
    begin
2833
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2834
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2835
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
2836
        test_fail("read didn't finish on WB bus as expected") ;
2837
        disable main ;
2838
    end
2839
 
2840
    test_ok ;
2841
 
2842
 
2843
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2844
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2845
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2846
    if ( temp_val1[8] !== 0 )
2847
    begin
2848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2849
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2850
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2851
    end
2852
    else
2853
        test_ok ;
2854
 
2855
    // now check normal read operation
2856
    configuration_cycle_write(0,             // bus number
2857
                              1,             // device number
2858
                              0,             // function number
2859
                              1,             // register number
2860
                              0,             // type of configuration cycle
2861
                              4'b0001,       // byte enables
2862
                              32'h0000_0007  // data
2863
                             ) ;
2864
 
2865
    test_name = "CHECK NORMAL READ AFTER ERROR TERMINATED READ" ;
2866
    read_data`READ_ADDRESS = target_address ;
2867
    read_data`READ_SEL     = 4'hF ;
2868
 
2869
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2870
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2871
    begin
2872
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2873
        $display("WB slave failed to process single read!") ;
2874
        $display("Slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
2875
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2876
        disable main ;
2877
    end
2878
 
2879
    if ( read_status`READ_DATA !== wmem_data[113] )
2880
    begin
2881
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2882
        test_fail("when read finished on WB bus, wrong data was provided") ;
2883
    end
2884
    else
2885
        test_ok ;
2886
 
2887
    // check PCI status register
2888
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT ON DELAYED READ" ;
2889
    ok = 1 ;
2890
 
2891
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2892
    if ( temp_val1[29] !== 1 )
2893
    begin
2894
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2895
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2896
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2897
        ok = 0 ;
2898
    end
2899
 
2900
    if ( temp_val1[28] !== 0 )
2901
    begin
2902
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2903
        $display("Received Target Abort bit was set for no reason!") ;
2904
        test_fail("Received Target Abort bit was set for no reason") ;
2905
        ok = 0 ;
2906
    end
2907
    if ( ok )
2908
        test_ok ;
2909
 
2910
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2911
 
2912
    $display("Introducing master abort error to CAB read!") ;
2913
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2914
 
2915
    configuration_cycle_write(0,             // bus number
2916
                              1,             // device number
2917
                              0,             // function number
2918
                              1,             // register number
2919
                              0,             // type of configuration cycle
2920
                              4'b0001,       // byte enables
2921
                              32'h0000_0000  // data
2922
                             ) ;
2923
 
2924
    for ( i = 0 ; i < 3 ; i = i + 1 )
2925
    begin
2926
        read_data`READ_ADDRESS = target_address + 4*i ;
2927
        read_data`READ_SEL     = 4'hF ;
2928
        wishbone_master.blk_read_data_in[i] = read_data ;
2929
    end
2930
 
2931
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2932
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2933
    write_flags`WB_TRANSFER_CAB    = 1 ;
2934
 
2935
    fork
2936
    begin
2937
        wishbone_master.wb_block_read( write_flags, read_status ) ;
2938
    end
2939
    begin
2940
        musnt_respond(ok) ;
2941
        if ( ok !== 1 )
2942
        begin
2943
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2944
            $display("Testbench is configured wrong!") ;
2945
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2946
        end
2947
    end
2948
    join
2949
 
2950
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2951
    begin
2952
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2953
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2954
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
2955
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
2956
        disable main ;
2957
    end
2958
    else
2959
        test_ok ;
2960
 
2961
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
2962
    ok = 1 ;
2963
    // check PCI status register
2964
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2965
    if ( temp_val1[29] !== 1 )
2966
    begin
2967
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2968
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2969
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2970
        ok = 0 ;
2971
    end
2972
 
2973
    if ( temp_val1[28] !== 0 )
2974
    begin
2975
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2976
        $display("Received Target Abort bit was set for no reason!") ;
2977
        test_fail("Received Target Abort bit was set for no reason") ;
2978
        ok = 0 ;
2979
    end
2980
 
2981
    if ( ok )
2982
        test_ok ;
2983
 
2984
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2985
 
2986
    $display("Introducing target abort termination to single write!") ;
2987
 
2988
    // disable error reporting and interrupts
2989
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
2990
 
2991
    configuration_cycle_write(0,             // bus number
2992
                              1,             // device number
2993
                              0,             // function number
2994
                              1,             // register number
2995
                              0,             // type of configuration cycle
2996
                              4'b0001,       // byte enables
2997
                              32'h0000_0007  // data
2998
                             ) ;
2999
 
3000
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3001
    if ( ok !== 1 )
3002
    begin
3003
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3004
        test_fail("WB Error Control and Status register couldn't be written to") ;
3005
        disable main ;
3006
    end
3007
 
3008
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3009
    if ( ok !== 1 )
3010
    begin
3011
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3012
        test_fail("Interrupt Control register couldn't be written to") ;
3013
        disable main ;
3014
    end
3015
 
3016
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3017
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3018
 
3019
    write_data`WRITE_ADDRESS = target_address ;
3020
    write_data`WRITE_DATA    = wmem_data[0] ;
3021
    write_data`WRITE_SEL     = 4'hF ;
3022
 
3023
    wishbone_master.blk_write_data[0] = write_data ;
3024
 
3025
    write_data`WRITE_ADDRESS = target_address + 4;
3026
    write_data`WRITE_DATA    = wmem_data[1] ;
3027
    write_data`WRITE_SEL     = 4'hF ;
3028
 
3029
    wishbone_master.blk_write_data[1] = write_data ;
3030
 
3031
    write_flags`WB_TRANSFER_SIZE = 2 ;
3032
 
3033
    // don't handle retries
3034
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3035
    write_flags`WB_TRANSFER_CAB    = 0 ;
3036
 
3037
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3038
    fork
3039
    begin
3040
        wishbone_master.wb_block_write(write_flags, write_status) ;
3041
 
3042
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3043
        begin
3044
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3045
            $display("Image writes were not accepted as expected!") ;
3046
            $display("Slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACTUAL_TRANSFER, write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
3047
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3048
            disable main ;
3049
        end
3050
 
3051
        // read data back to see, if it was written OK
3052
        read_data`READ_ADDRESS         = target_address + 4;
3053
        read_data`READ_SEL             = 4'hF ;
3054
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3055
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3056
    end
3057
    begin
3058
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3059
        if ( ok !== 1 )
3060
        begin
3061
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3062
        end
3063
        else
3064
            test_ok ;
3065
 
3066
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3067
 
3068
        // when first transaction finishes - enable normal target response!
3069
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3070
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3071
 
3072
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3073
        if ( ok !== 1 )
3074
        begin
3075
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3076
        end
3077
        else
3078
            test_ok ;
3079
 
3080
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3081
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3082
        if ( ok !== 1 )
3083
        begin
3084
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3085
        end
3086
    end
3087
    join
3088
 
3089
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3090
    begin
3091
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3092
        $display("Bridge failed to process single read after target abort terminated write!") ;
3093
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3094
        disable main ;
3095
    end
3096
 
3097
    if ( read_status`READ_DATA !== wmem_data[1] )
3098
    begin
3099
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3100
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3101
    end
3102
    else
3103
        test_ok ;
3104
 
3105
    // check interrupt and error statuses!
3106
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3107
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3108
    if ( temp_val1[8] !== 0 )
3109
    begin
3110
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3111
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3112
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3113
    end
3114
    else
3115
        test_ok ;
3116
 
3117
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3118
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3119
    if ( temp_val1[1] !== 0 )
3120
    begin
3121
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3122
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3123
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3124
    end
3125
    else
3126
        test_ok ;
3127
 
3128
    // check PCI status register
3129
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3130
    ok = 1 ;
3131
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3132
    if ( temp_val1[29] !== 0 )
3133
    begin
3134
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3135
        $display("Received Master Abort bit was set with no reason!") ;
3136
        test_fail("Received Master Abort bit was set with no reason") ;
3137
        ok = 0 ;
3138
    end
3139
 
3140
    if ( temp_val1[28] !== 1 )
3141
    begin
3142
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3143
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3144
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3145
        ok = 0 ;
3146
    end
3147
 
3148
    if ( ok )
3149
        test_ok ;
3150
 
3151
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3152
 
3153
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3154
 
3155
    $display("Introducing target abort termination to CAB write!") ;
3156
    // enable error reporting mechanism
3157
 
3158
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3159
    if ( ok !== 1 )
3160
    begin
3161
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3162
        test_fail("WB Error Control and Status register could not be written to") ;
3163
        disable main ;
3164
    end
3165
 
3166
    for ( i = 0 ; i < 3 ; i = i + 1 )
3167
    begin
3168
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3169
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3170
        write_data`WRITE_SEL     = 4'b1010 ;
3171
        wishbone_master.blk_write_data[i] = write_data ;
3172
    end
3173
 
3174
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3175
    write_flags`WB_TRANSFER_CAB    = 1 ;
3176
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3177
 
3178
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3179
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3180
 
3181
    fork
3182
    begin
3183
        wishbone_master.wb_block_write(write_flags, write_status) ;
3184
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3185
        begin
3186
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3187
            $display("Bridge failed to process complete CAB write!") ;
3188
            test_fail("bridge failed to post CAB Memory Write") ;
3189
            disable main ;
3190
        end
3191
    end
3192
    begin
3193
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3194
        if ( ok !== 1 )
3195
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3196
        else
3197
            test_ok ;
3198
    end
3199
    join
3200
 
3201
    // check statuses and data from error
3202
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3203
    ok = 1 ;
3204
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3205
    if ( temp_val1[8] !== 1 )
3206
    begin
3207
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3208
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3209
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3210
        ok = 0 ;
3211
    end
3212
 
3213
    if ( temp_val1[9] !== 0 )
3214
    begin
3215
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3216
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3217
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3218
        ok = 0 ;
3219
    end
3220
 
3221
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3222
    begin
3223
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3224
        $display("Value in W_ERR_CS register was wrong!") ;
3225
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3226
        test_fail("BE Field didn't provided expected value") ;
3227
        ok = 0 ;
3228
    end
3229
 
3230
    if ( ok )
3231
        test_ok ;
3232
 
3233
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3234
    ok = 1 ;
3235
    // check erroneous address and data
3236
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3237
    if ( temp_val1 !== (target_address + 8) )
3238
    begin
3239
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3240
        $display("Value in W_ERR_ADDR register was wrong!") ;
3241
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3242
        test_fail("Value in WB Erroneous Address register was wrong") ;
3243
        ok = 0 ;
3244
    end
3245
 
3246
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3247
    if ( temp_val1 !== wmem_data[120] )
3248
    begin
3249
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3250
        $display("Value in W_ERR_DATA register was wrong!") ;
3251
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3252
        test_fail("Value in WB Erroneous Data register was wrong") ;
3253
        ok = 0 ;
3254
    end
3255
 
3256
    if ( ok )
3257
        test_ok ;
3258
 
3259
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3260
    ok = 1 ;
3261
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3262
    if ( temp_val1[29] !== 0 )
3263
    begin
3264
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3265
        $display("Received Master Abort bit was set with no reason!") ;
3266
        test_fail("Received Master Abort bit was set for no reason") ;
3267
        ok = 0 ;
3268
    end
3269
 
3270
    if ( temp_val1[28] !== 1 )
3271
    begin
3272
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3273
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3274
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3275
        ok = 0 ;
3276
    end
3277
 
3278
    if ( ok )
3279
        test_ok ;
3280
 
3281
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3282
 
3283
    // clear error status bit and enable error interrupts
3284
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3285
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3286
 
3287
    // check if error bit was cleared
3288
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3289
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3290
    if ( temp_val1[8] !== 0 )
3291
    begin
3292
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3293
        $display("Error bit was not cleared even though one was written to its location!") ;
3294
        test_fail("Error bit was not cleared even though one was written to its location") ;
3295
    end
3296
 
3297
    // repeat same write with different target configuration
3298
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3299
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3300
 
3301
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3302
    fork
3303
    begin
3304
        write_flags`WB_TRANSFER_SIZE = 2 ;
3305
        wishbone_master.wb_block_write(write_flags, write_status) ;
3306
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3307
        begin
3308
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3309
            $display("Bridge failed to process complete CAB write!") ;
3310
            test_fail("bridge failed to post CAB Memory Write") ;
3311
            disable main ;
3312
        end
3313
 
3314
        write_flags`WB_TRANSFER_SIZE = 3 ;
3315
        wishbone_master.wb_block_write(write_flags, write_status) ;
3316
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3317
        begin
3318
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3319
            $display("Bridge failed to process complete CAB write!") ;
3320
            test_fail("bridge failed to post CAB Memory Write") ;
3321
            disable main ;
3322
        end
3323
    end
3324
    begin
3325
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3326
        if ( ok !== 1 )
3327
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3328
        else
3329
        begin
3330
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3331
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3332
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3333
            if ( ok !== 1 )
3334
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3335
            else
3336
                test_ok ;
3337
        end
3338
    end
3339
    join
3340
 
3341
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3342
    ok = 1 ;
3343
    // check statuses and data from error
3344
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3345
    if ( temp_val1[8] !== 1 )
3346
    begin
3347
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3348
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3349
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3350
        ok = 0 ;
3351
    end
3352
 
3353
    if ( temp_val1[9] !== 0 )
3354
    begin
3355
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3356
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3357
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3358
        ok = 0 ;
3359
    end
3360
 
3361
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3362
    begin
3363
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3364
        $display("Value in W_ERR_CS register was wrong!") ;
3365
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3366
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3367
        ok = 0 ;
3368
    end
3369
 
3370
    if ( ok )
3371
        test_ok ;
3372
 
3373
    // check erroneous address and data
3374
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3375
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3376
    ok = 1 ;
3377
    if ( temp_val1 !== (target_address + 8 + 4) )
3378
    begin
3379
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3380
        $display("Value in W_ERR_ADDR register was wrong!") ;
3381
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3382
        test_fail("Value in WB Erroneous Address register was wrong") ;
3383
        ok = 0 ;
3384
 
3385
    end
3386
 
3387
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3388
    if ( temp_val1 !== wmem_data[121] )
3389
    begin
3390
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3391
        $display("Value in W_ERR_DATA register was wrong!") ;
3392
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3393
        test_fail("Value in WB Erroneous Data register was wrong") ;
3394
        ok = 0 ;
3395
    end
3396
 
3397
    if ( ok )
3398
        test_ok ;
3399
 
3400
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3401
    `ifdef HOST
3402
        repeat(4)
3403
            @(posedge wb_clock) ;
3404
        if ( INT_O !== 1 )
3405
        begin
3406
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3407
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3408
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3409
        end
3410
        else
3411
            test_ok ;
3412
    `else
3413
    `ifdef GUEST
3414
        repeat(4)
3415
            @(posedge pci_clock) ;
3416
        if ( INTA !== 0 )
3417
        begin
3418
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3419
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3420
            test_fail("interrupt request was not presented on PCI bus") ;
3421
        end
3422
        else
3423
            test_ok ;
3424
    `endif
3425
    `endif
3426
 
3427
    // read interrupt status register
3428
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3429
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3430
    if ( temp_val1[1] !== 1 )
3431
    begin
3432
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3433
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3434
        test_fail("Expected Interrupt status bit wasn't set") ;
3435
    end
3436
 
3437
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3438
 
3439
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3440
    ok = 1 ;
3441
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3442
    if ( temp_val1[29] !== 0 )
3443
    begin
3444
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3445
        $display("Received Master Abort bit was set with no reason!") ;
3446
        test_fail("Received Master Abort bit was set with no reason") ;
3447
        ok = 0 ;
3448
    end
3449
 
3450
    if ( temp_val1[28] !== 1 )
3451
    begin
3452
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3453
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3454
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3455
        ok = 0 ;
3456
    end
3457
 
3458
    if ( ok )
3459
        test_ok ;
3460
 
3461
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3462
 
3463
    // clear interrupts and errors
3464
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3465
    repeat( 3 )
3466
        @(posedge pci_clock) ;
3467
 
3468
    repeat( 2 )
3469
        @(posedge wb_clock) ;
3470
 
3471
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3472
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3473
    if ( temp_val1[1] !== 0 )
3474
    begin
3475
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3476
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3477
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3478
    end
3479
    else
3480
        test_ok ;
3481
 
3482
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3483
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3484
    if ( temp_val1[8] !== 0 )
3485
    begin
3486
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3487
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3488
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3489
    end
3490
 
3491
 
3492
    $display("Introducing Target Abort error to single read!") ;
3493
    // set read data
3494
    read_data`READ_ADDRESS = target_address + 8 ;
3495
    read_data`READ_SEL     = 4'hF ;
3496
 
3497
    // enable automatic retry handling
3498
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3499
    write_flags`WB_TRANSFER_CAB    = 0 ;
3500
 
3501
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3502
 
3503
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3504
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3505
 
3506
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3507
 
3508
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3509
    begin
3510
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3511
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3512
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3513
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3514
        disable main ;
3515
    end
3516
    else
3517
        test_ok ;
3518
 
3519
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3520
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3521
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3522
    if ( temp_val1[8] !== 0 )
3523
    begin
3524
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3525
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3526
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3527
    end
3528
    else
3529
        test_ok ;
3530
 
3531
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3532
    ok = 1 ;
3533
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3534
    if ( temp_val1[29] !== 0 )
3535
    begin
3536
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3537
        $display("Received Master Abort bit was set with no reason!") ;
3538
        test_fail("Received Master Abort bit was set with no reason") ;
3539
        ok = 0 ;
3540
    end
3541
 
3542
    if ( temp_val1[28] !== 1 )
3543
    begin
3544
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3545
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3546
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3547
        ok = 0 ;
3548
    end
3549
 
3550
    if ( ok )
3551
        test_ok ;
3552
 
3553
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3554
 
3555
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3556
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3557
    if ( temp_val1[1] !== 0 )
3558
    begin
3559
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3560
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3561
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3562
    end
3563
    else
3564
        test_ok ;
3565
 
3566
    $display("Introducing Target Abort error to CAB read!") ;
3567
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3568
 
3569
    for ( i = 0 ; i < 4 ; i = i + 1 )
3570
    begin
3571
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3572
        read_data`READ_SEL     = 4'b1010 ;
3573
        wishbone_master.blk_read_data_in[i] = read_data ;
3574
    end
3575
 
3576
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3577
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3578
    write_flags`WB_TRANSFER_CAB    = 1 ;
3579
 
3580
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3581
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3582
 
3583
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3584
 
3585
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3586
    begin
3587
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3588
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3589
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3590
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3591
        disable main ;
3592
    end
3593
 
3594
    read_status = wishbone_master.blk_read_data_out[0] ;
3595
    temp_val1 = read_status`READ_DATA ;
3596
    temp_val2 = wmem_data[120] ;
3597
 
3598
    // last write to this address was with only two byte enables - check only those
3599
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3600
    begin
3601
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3602
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3603
    end
3604
    else
3605
        test_ok ;
3606
 
3607
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3608
    ok = 1 ;
3609
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3610
    if ( temp_val1[29] !== 0 )
3611
    begin
3612
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3613
        $display("Received Master Abort bit was set with no reason!") ;
3614
        test_fail("Received Master Abort bit was set with no reason") ;
3615
        ok = 0 ;
3616
    end
3617
 
3618
    if ( temp_val1[28] !== 1 )
3619
    begin
3620
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3621
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3622
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3623
        ok = 0 ;
3624
    end
3625
 
3626
    if ( ok )
3627
       test_ok ;
3628
 
3629
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3630
 
3631
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3632
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3633
 
3634
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3635
    for ( i = 0 ; i < 3 ; i = i + 1 )
3636
    begin
3637
        read_data`READ_ADDRESS = target_address + 4*i ;
3638
        read_data`READ_SEL     = 4'b1111 ;
3639
        wishbone_master.blk_read_data_in[i] = read_data ;
3640
    end
3641
 
3642
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3643
 
3644
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3645
 
3646
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3647
    begin
3648
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3649
        $display("Complete burst read through WB slave didn't succeed!") ;
3650
        test_fail("bridge didn't process Burst Read in an expected way") ;
3651
        disable main ;
3652
    end
3653
    else
3654
        test_ok ;
3655
 
3656
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3657
 
3658
    for ( i = 0 ; i < 3 ; i = i + 1 )
3659
    begin
3660
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3661
        read_data`READ_SEL     = 4'b1111 ;
3662
        wishbone_master.blk_read_data_in[i] = read_data ;
3663
    end
3664
 
3665
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3666
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3667
    write_flags`WB_TRANSFER_CAB    = 1 ;
3668
 
3669
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3670
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3671
 
3672
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3673
 
3674
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3675
    begin
3676
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3677
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3678
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3679
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3680
        disable main ;
3681
    end
3682
 
3683
    for ( i = 0 ; i < 3 ; i = i + 1 )
3684
    begin
3685
        ok = 1 ;
3686
        read_status = wishbone_master.blk_read_data_out[i] ;
3687
        temp_val1 = read_status`READ_DATA ;
3688
        temp_val2 = wmem_data[120 + i] ;
3689
 
3690
        // last write to this address was with only two byte enables - check only those
3691
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3692
        begin
3693
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3694
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3695
            ok = 0 ;
3696
        end
3697
    end
3698
 
3699
    if ( ok )
3700
        test_ok ;
3701
 
3702
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3703
    ok = 1 ;
3704
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3705
    if ( temp_val1[29] !== 0 )
3706
    begin
3707
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3708
        $display("Received Master Abort bit was set with no reason!") ;
3709
        test_fail("Received Master Abort bit was set with no reason") ;
3710
        ok = 0 ;
3711
    end
3712
 
3713
    if ( temp_val1[28] !== 1 )
3714
    begin
3715
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3716
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3717
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3718
        ok = 0 ;
3719
    end
3720
 
3721
    if ( ok )
3722
       test_ok ;
3723
 
3724
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3725
 
3726
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3727
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3728
 
3729
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3730
    for ( i = 0 ; i < 3 ; i = i + 1 )
3731
    begin
3732
        read_data`READ_ADDRESS = target_address + 4*i ;
3733
        read_data`READ_SEL     = 4'b1111 ;
3734
        wishbone_master.blk_read_data_in[i] = read_data ;
3735
    end
3736
 
3737
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3738
 
3739
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3740
 
3741
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3742
    begin
3743
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3744
        $display("Complete burst read through WB slave didn't succeed!") ;
3745
        test_fail("bridge didn't process Burst Read in an expected way") ;
3746
        disable main ;
3747
    end
3748
    else
3749
        test_ok ;
3750
 
3751
    // test error on IO write
3752
    // change base address
3753
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3754
    write_data`WRITE_SEL     = 4'b0101 ;
3755
    write_data`WRITE_ADDRESS = target_address ;
3756
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3757
 
3758
    write_flags`WB_TRANSFER_CAB    = 0 ;
3759
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3760
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3761
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3762
    fork
3763
    begin
3764
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3765
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3766
        begin
3767
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3768
            $display("WB slave failed to accept IO write!") ;
3769
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3770
            disable main ;
3771
        end
3772
    end
3773
    begin
3774
        musnt_respond(ok) ;
3775
        if ( ok !== 1 )
3776
        begin
3777
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3778
            $display("Testbench is configured wrong!") ;
3779
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3780
        end
3781
        else
3782
            test_ok ;
3783
    end
3784
    join
3785
 
3786
    // check statuses and everything else
3787
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3788
    ok = 1 ;
3789
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3790
    if ( temp_val1[8] !== 1 )
3791
    begin
3792
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3793
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3794
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3795
        ok = 0 ;
3796
    end
3797
 
3798
    if ( temp_val1[9] !== 1 )
3799
    begin
3800
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3801
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3802
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3803
        ok = 0 ;
3804
    end
3805
 
3806
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3807
    begin
3808
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3809
        $display("Value in W_ERR_CS register was wrong!") ;
3810
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3811
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3812
        ok = 0 ;
3813
    end
3814
 
3815
    if ( ok )
3816
        test_ok ;
3817
 
3818
    // check erroneous address and data
3819
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3820
    ok = 1 ;
3821
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3822
    if ( temp_val1 !== target_address )
3823
    begin
3824
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3825
        $display("Value in W_ERR_ADDR register was wrong!") ;
3826
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3827
        test_fail("WB Erroneous Address register didn't provide right value") ;
3828
        ok = 0 ;
3829
    end
3830
 
3831
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3832
    if ( temp_val1 !== 32'hAAAA_AAAA )
3833
    begin
3834
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3835
        $display("Value in W_ERR_DATA register was wrong!") ;
3836
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3837
        test_fail("WB Erroneous Data register didn't provide right value") ;
3838
        ok = 0 ;
3839
    end
3840
 
3841
    if ( ok )
3842
        test_ok ;
3843
 
3844
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3845
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3846
    if ( temp_val1[1] !== 1 )
3847
    begin
3848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3849
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3850
        test_fail("expected interrupt status bit was not set") ;
3851
    end
3852
    else
3853
        test_ok ;
3854
 
3855
    // clear interrupts and errors
3856
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3857
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3858
 
3859
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3860
    ok = 1 ;
3861
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3862
    if ( temp_val1[29] !== 1 )
3863
    begin
3864
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3865
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3866
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3867
        ok = 0 ;
3868
    end
3869
 
3870
    if ( temp_val1[28] !== 0 )
3871
    begin
3872
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3873
        $display("Received Target Abort bit was set for no reason!") ;
3874
        test_fail("Received Target Abort bit was set for no reason") ;
3875
        ok = 0 ;
3876
    end
3877
 
3878
    if ( ok )
3879
        test_ok ;
3880
 
3881
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3882
 
3883
    // disable image
3884
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3885
    if ( ok !== 1 )
3886
    begin
3887
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3888
        test_fail("WB Image Address Mask register couldn't be written") ;
3889
        disable main ;
3890
    end
3891
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3892
 
3893
end
3894
endtask
3895
 
3896
task parity_checking ;
3897
    reg   [11:0] ctrl_offset ;
3898
    reg   [11:0] ba_offset ;
3899
    reg   [11:0] am_offset ;
3900
    reg   [11:0] ta_offset ;
3901
    reg `WRITE_STIM_TYPE write_data ;
3902
    reg `READ_STIM_TYPE  read_data ;
3903
    reg `READ_RETURN_TYPE read_status ;
3904
 
3905
    reg `WRITE_RETURN_TYPE write_status ;
3906
    reg `WB_TRANSFER_FLAGS write_flags ;
3907
    reg [31:0] temp_val1 ;
3908
    reg [31:0] temp_val2 ;
3909
    reg        ok   ;
3910
    reg [11:0] pci_ctrl_offset ;
3911
    reg [31:0] image_base ;
3912
    reg [31:0] target_address ;
3913
    reg [11:0] icr_offset ;
3914
    reg [11:0] isr_offset ;
3915
    reg [11:0] p_ba_offset ;
3916
    reg [11:0] p_am_offset ;
3917
    reg [11:0] p_ctrl_offset ;
3918
    integer    i ;
3919
    reg        perr_asserted ;
3920
begin:main
3921
    $display("******************************* Testing Parity Checker functions ********************************") ;
3922
    $display("Testing Parity Errors during Master Transactions!") ;
3923
    $display("Introducing Parity Erros to Master Writes!") ;
3924
    $fdisplay(pci_mon_log_file_desc,
3925
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
3926
 
3927
    // image 1 is used for error testing, since it is always implemented
3928
    pci_ctrl_offset = 12'h004 ;
3929
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
3930
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
3931
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
3932
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
3933
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
3934
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
3935
 
3936
    // image 1 for PCI target
3937
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
3938
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
3939
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
3940
 
3941
    target_address  = `BEH_TAR1_MEM_START ;
3942
    image_base      = 0 ;
3943
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
3944
 
3945
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
3946
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
3947
    write_flags                    = 0 ;
3948
    write_flags`INIT_WAITS         = tb_init_waits ;
3949
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
3950
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3951
 
3952
    // enable master & target operation and disable parity functions
3953
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
3954
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
3955
    if ( ok !== 1 )
3956
    begin
3957
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
3958
        test_fail("PCI Device Control register could not be written to") ;
3959
        disable main ;
3960
    end
3961
 
3962
    // prepare image control register
3963
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
3964
    if ( ok !== 1 )
3965
    begin
3966
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
3967
        test_fail("WB Image Control register could not be written to") ;
3968
        disable main ;
3969
    end
3970
 
3971
    // prepare base address register
3972
    config_write( ba_offset, image_base, 4'hF, ok ) ;
3973
    if ( ok !== 1 )
3974
    begin
3975
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
3976
        test_fail("WB Image Base Address register could not be written to") ;
3977
        disable main ;
3978
    end
3979
 
3980
    // write address mask register
3981
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
3982
    if ( ok !== 1 )
3983
    begin
3984
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3985
        test_fail("WB Image Address Mask register could not be written to") ;
3986
        disable main ;
3987
    end
3988
 
3989
    // disable parity interrupts
3990
    config_write( icr_offset, 0, 4'hF, ok ) ;
3991
    if ( ok !== 1 )
3992
    begin
3993
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
3994
        test_fail("Interrupt Control register could not be written to") ;
3995
        disable main ;
3996
    end
3997
 
3998
    write_data`WRITE_ADDRESS = target_address ;
3999
    write_data`WRITE_DATA    = wmem_data[0] ;
4000
    write_data`WRITE_SEL     = 4'b1111 ;
4001
 
4002
    // enable target's 1 response to parity errors
4003
    configuration_cycle_write(0,             // bus number
4004
                              1,             // device number
4005
                              0,             // function number
4006
                              1,             // register number
4007
                              0,             // type of configuration cycle
4008
                              4'b0001,       // byte enables
4009
                              32'h0000_0047  // data
4010
                             ) ;
4011
 
4012
    // disable target's 2 response to parity errors
4013
    configuration_cycle_write(0,             // bus number
4014
                              2,             // device number
4015
                              0,             // function number
4016
                              1,             // register number
4017
                              0,             // type of configuration cycle
4018
                              4'b0001,       // byte enables
4019
                              32'h0000_0007  // data
4020
                             ) ;
4021
 
4022
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4023
 
4024
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4025
    fork
4026
    begin
4027
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4028
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4029
        begin
4030
            $display("Parity checker testing failed! Time %t ", $time) ;
4031
            $display("Bridge failed to process single memory write!") ;
4032
            test_fail("bridge failed to post single WB memory write") ;
4033
            disable main ;
4034
        end
4035
    end
4036
    begin:wait_perr1
4037
        perr_asserted = 0 ;
4038
        @(posedge pci_clock) ;
4039
 
4040
        while ( PERR === 1 )
4041
            @(posedge pci_clock) ;
4042
 
4043
        if ( PERR === 0 )
4044
            perr_asserted = 1 ;
4045
 
4046
    end
4047
    begin
4048
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4049
 
4050
        if ( ok !== 1 )
4051
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4052
 
4053
        repeat(3)
4054
            @(posedge pci_clock) ;
4055
 
4056
        disable wait_perr1 ;
4057
    end
4058
    join
4059
 
4060
    if ( perr_asserted && ok )
4061
    begin
4062
        test_ok ;
4063
    end
4064
    else
4065
    if ( ~perr_asserted )
4066
    begin
4067
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4068
        disable main ;
4069
    end
4070
 
4071
    // check all the statuses - if HOST is defined, wait for them to be synced
4072
    `ifdef HOST
4073
    repeat(4)
4074
        @(posedge wb_clock) ;
4075
    `endif
4076
 
4077
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4078
    ok = 1 ;
4079
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4080
    if ( temp_val1[31] !== 1 )
4081
    begin
4082
        $display("Parity checker testing failed! Time %t ", $time) ;
4083
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4084
        test_fail("Detected Parity Error bit was not set after Write Master Data Parity Error") ;
4085
        ok = 0 ;
4086
    end
4087
 
4088
    if ( temp_val1[30] !== 0 )
4089
    begin
4090
        $display("Parity checker testing failed! Time %t ", $time) ;
4091
        $display("Signalled System Error bit was set for no reason!") ;
4092
        test_fail("Signalled System Error bit was set for no reason") ;
4093
        ok = 0 ;
4094
    end
4095
 
4096
    if ( temp_val1[24] !== 0 )
4097
    begin
4098
        $display("Parity checker testing failed! Time %t ", $time) ;
4099
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4100
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4101
        ok = 0 ;
4102
    end
4103
 
4104
    if ( ok )
4105
        test_ok ;
4106
 
4107
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4108
    // clear parity bits and enable parity response
4109
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4110
    if ( ok !== 1 )
4111
    begin
4112
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4113
        test_fail("write to PCI Status Register failed") ;
4114
        disable main ;
4115
    end
4116
 
4117
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4118
    fork
4119
    begin
4120
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4121
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4122
        begin
4123
            $display("Parity checker testing failed! Time %t ", $time) ;
4124
            $display("Bridge failed to process single memory write!") ;
4125
            test_fail("bridge failed to post single memory write") ;
4126
            disable main ;
4127
        end
4128
    end
4129
    begin:wait_perr2
4130
        perr_asserted = 0 ;
4131
        @(posedge pci_clock) ;
4132
 
4133
        while ( PERR === 1 )
4134
            @(posedge pci_clock) ;
4135
 
4136
        if ( PERR === 0 )
4137
            perr_asserted = 1 ;
4138
 
4139
    end
4140
    begin
4141
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4142
 
4143
        if ( ok !== 1 )
4144
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4145
 
4146
        repeat(3)
4147
            @(posedge pci_clock) ;
4148
 
4149
        disable wait_perr2 ;
4150
    end
4151
    join
4152
 
4153
    if ( perr_asserted && ok )
4154
    begin
4155
        test_ok ;
4156
    end
4157
    else
4158
    if ( ~perr_asserted )
4159
    begin
4160
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4161
        disable main ;
4162
    end
4163
 
4164
    // check all the statuses - if HOST is defined, wait for them to be synced
4165
    `ifdef HOST
4166
    repeat(4)
4167
        @(posedge wb_clock) ;
4168
    `endif
4169
 
4170
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4171
    ok = 1 ;
4172
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4173
    if ( temp_val1[31] !== 1 )
4174
    begin
4175
        $display("Parity checker testing failed! Time %t ", $time) ;
4176
        $display("Detected Parity Error bit was not set after parity error on PCI bus!") ;
4177
        test_fail("Detected Parity Error bit was not set after parity error on PCI bus") ;
4178
        ok = 0 ;
4179
    end
4180
 
4181
    if ( temp_val1[30] !== 0 )
4182
    begin
4183
        $display("Parity checker testing failed! Time %t ", $time) ;
4184
        $display("Signalled System Error bit was set for no reason!") ;
4185
        test_fail("Signalled System Error bit was set for no reason") ;
4186
        ok = 0 ;
4187
    end
4188
 
4189
    if ( temp_val1[24] !== 1 )
4190
    begin
4191
        $display("Parity checker testing failed! Time %t ", $time) ;
4192
        $display("Master Data Parity Error bit wasn't set even though Parity Error Response bit was set!") ;
4193
        test_fail("Master Data Parity Error bit wasn't set after Parity Error on PCI bus, even though Parity Error Response bit was set") ;
4194
        ok = 0 ;
4195
    end
4196
 
4197
    if ( ok )
4198
        test_ok ;
4199
 
4200
    // clear status bits and disable parity error response
4201
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4202
 
4203
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4204
 
4205
    // disable perr generation and perform a write - no bits should be set
4206
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4207
    fork
4208
    begin
4209
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4210
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4211
        begin
4212
            $display("Parity checker testing failed! Time %t ", $time) ;
4213
            $display("Bridge failed to process single memory write!") ;
4214
            test_fail("bridge failed to post single memory write") ;
4215
            disable main ;
4216
        end
4217
    end
4218
    begin
4219
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4220
 
4221
        if ( ok !== 1 )
4222
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4223
        else
4224
            test_ok ;
4225
 
4226
        repeat(3)
4227
            @(posedge pci_clock) ;
4228
    end
4229
    join
4230
 
4231
    `ifdef HOST
4232
    repeat(4)
4233
        @(posedge wb_clock) ;
4234
    `endif
4235
 
4236
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4237
    ok = 1 ;
4238
 
4239
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4240
    if ( temp_val1[31] !== 0 )
4241
    begin
4242
        $display("Parity checker testing failed! Time %t ", $time) ;
4243
        $display("Detected Parity Error bit was set for no reason!") ;
4244
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4245
        ok = 0 ;
4246
    end
4247
 
4248
    if ( temp_val1[30] !== 0 )
4249
    begin
4250
        $display("Parity checker testing failed! Time %t ", $time) ;
4251
        $display("Signalled System Error bit was set for no reason!") ;
4252
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4253
        ok = 0 ;
4254
    end
4255
 
4256
    if ( temp_val1[24] !== 0 )
4257
    begin
4258
        $display("Parity checker testing failed! Time %t ", $time) ;
4259
        $display("Master Data Parity Error bit was set for no reason!") ;
4260
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4261
        ok = 0 ;
4262
    end
4263
 
4264
    if ( ok )
4265
        test_ok ;
4266
 
4267
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4268
 
4269
    read_data = 0 ;
4270
    read_data`READ_ADDRESS  = target_address ;
4271
    read_data`READ_SEL      = 4'hF ;
4272
    read_data`READ_TAG_STIM = 0 ;
4273
 
4274
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4275
 
4276
    // enable parity and system error interrupts
4277
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4278
 
4279
    // enable parity error response
4280
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4281
 
4282
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4283
 
4284
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4285
    fork
4286
    begin
4287
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4288
    end
4289
    begin:wait_perr4
4290
        perr_asserted = 0 ;
4291
        @(posedge pci_clock) ;
4292
        while ( PERR === 1 )
4293
            @(posedge pci_clock) ;
4294
 
4295
        if ( PERR === 0 )
4296
            perr_asserted = 1 ;
4297
 
4298
    end
4299
    begin
4300
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4301
 
4302
        if ( ok !== 1 )
4303
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4304
 
4305
        repeat(2)
4306
            @(posedge pci_clock) ;
4307
 
4308
        disable wait_perr4 ;
4309
    end
4310
    join
4311
 
4312
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4313
    begin
4314
        $display("Parity checker testing failed! Time %t ", $time) ;
4315
        $display("Bridge failed to process single memory read!") ;
4316
        test_fail("bridge didn't process single memory read correctly") ;
4317
        ok = 0 ;
4318
    end
4319
 
4320
    if ( perr_asserted && ok )
4321
    begin
4322
        test_ok ;
4323
    end
4324
    else
4325
    if ( ~perr_asserted )
4326
    begin
4327
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4328
        disable main ;
4329
    end
4330
 
4331
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4332
    // interrupt should also be present
4333
    `ifdef HOST
4334
        repeat(4)
4335 26 mihad
            @(posedge pci_clock) ;
4336
        repeat(4)
4337 15 mihad
            @(posedge wb_clock) ;
4338
 
4339
        if ( INT_O !== 1 )
4340
        begin
4341
            $display("Parity checker testing failed! Time %t ", $time) ;
4342
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4343
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4344
        end
4345
        else
4346
            test_ok ;
4347
    `else
4348
    `ifdef GUEST
4349 26 mihad
        repeat(4)
4350
            @(posedge wb_clock) ;
4351
        repeat(4)
4352 15 mihad
            @(posedge pci_clock) ;
4353
 
4354
        if ( INTA !== 1 )
4355
        begin
4356
            $display("Parity checker testing failed! Time %t ", $time) ;
4357
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4358
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4359
        end
4360
        else
4361
            test_ok ;
4362
    `endif
4363
    `endif
4364
 
4365
    // check statuses!
4366
 
4367
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4368
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4369
    ok = 1 ;
4370
 
4371
    if ( temp_val1[31] !== 1 )
4372
    begin
4373
        $display("Parity checker testing failed! Time %t ", $time) ;
4374
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4375
        test_fail("Detected Parity Error bit was not set when parity error was presented on Read transaction") ;
4376
        ok = 0 ;
4377
    end
4378
 
4379
    if ( temp_val1[30] !== 0 )
4380
    begin
4381
        $display("Parity checker testing failed! Time %t ", $time) ;
4382
        $display("Signalled System Error bit was set for no reason!") ;
4383
        test_fail("Signalled System Error bit was set for no reason") ;
4384
        ok = 0 ;
4385
    end
4386
 
4387
    if ( temp_val1[24] !== 1 )
4388
    begin
4389
        $display("Parity checker testing failed! Time %t ", $time) ;
4390
        $display("Master Data Parity Error bit was not set when parity error was presented during read transaction!") ;
4391
        test_fail("Master Data Parity Error bit was not set when parity error was presented during read transaction and Parity Error Response was enabled") ;
4392
        ok = 0 ;
4393
    end
4394
 
4395
    if ( ok )
4396
        test_ok ;
4397
 
4398
    // clear statuses and disable parity error response
4399
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4400
 
4401
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4402
    ok = 1 ;
4403
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4404
 
4405
    if ( temp_val1[4] !== 0 )
4406
    begin
4407
        $display("Parity checker testing failed! Time %t ", $time) ;
4408
        $display("System error interrupt status bit set for no reason!") ;
4409
        test_fail("System error interrupt status bit set for no reason") ;
4410
        ok = 0 ;
4411
    end
4412
 
4413
    `ifdef HOST
4414
    if ( temp_val1[3] !== 1 )
4415
    begin
4416
        $display("Parity checker testing failed! Time %t ", $time) ;
4417
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4418
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4419
        ok = 0 ;
4420
    end
4421
    `else
4422
    if ( temp_val1[3] !== 0 )
4423
    begin
4424
        $display("Parity checker testing failed! Time %t ", $time) ;
4425
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4426
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4427
        ok = 0 ;
4428
    end
4429
    `endif
4430
 
4431
    if ( ok )
4432
        test_ok ;
4433
 
4434
    // clear int statuses
4435
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4436
 
4437
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4438
 
4439
    `ifdef HOST
4440
        repeat(4)
4441 26 mihad
            @(posedge pci_clock) ;
4442
        repeat(4)
4443 15 mihad
            @(posedge wb_clock) ;
4444
 
4445
        if ( INT_O !== 0 )
4446
        begin
4447
            $display("Parity checker testing failed! Time %t ", $time) ;
4448
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4449
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4450
        end
4451
        else
4452
            test_ok ;
4453
    `else
4454
    `ifdef GUEST
4455 26 mihad
        repeat(4)
4456
            @(posedge wb_clock) ;
4457
        repeat(4)
4458 15 mihad
            @(posedge pci_clock) ;
4459
 
4460
        if ( INTA !== 1 )
4461
        begin
4462
            $display("Parity checker testing failed! Time %t ", $time) ;
4463
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4464
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4465
        end
4466
        else
4467
            test_ok ;
4468
    `endif
4469
    `endif
4470
 
4471
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4472
 
4473
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4474
    fork
4475
    begin
4476
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4477
    end
4478
    begin:wait_perr5
4479
        perr_asserted = 0 ;
4480
        @(posedge pci_clock) ;
4481
        while ( PERR === 1 )
4482
            @(posedge pci_clock) ;
4483
 
4484
        perr_asserted = 1 ;
4485
        $display("Parity checker testing failed! Time %t ", $time) ;
4486
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4487
        test_fail("Bridge asserted PERR during read transaction when Parity Error response was disabled") ;
4488
    end
4489
    begin
4490
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4491
        if ( ok !== 1 )
4492
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4493
 
4494
        // perr can be asserted on idle or next PCI address phase
4495
        repeat(2)
4496
            @(posedge pci_clock) ;
4497
 
4498
        disable wait_perr5 ;
4499
    end
4500
    join
4501
 
4502
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4503
    begin
4504
        $display("Parity checker testing failed! Time %t ", $time) ;
4505
        $display("Bridge failed to process single memory read!") ;
4506
        test_fail("bridge failed to process single memory read correctly") ;
4507
        ok = 0 ;
4508
    end
4509
 
4510
    if ( ok && !perr_asserted)
4511
        test_ok ;
4512
 
4513
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4514
 
4515
    // interrupts should not be present
4516
    `ifdef HOST
4517
        repeat( 4 )
4518 26 mihad
            @(posedge pci_clock) ;
4519
        repeat( 4 )
4520 15 mihad
            @(posedge wb_clock) ;
4521
        if ( INT_O !== 0 )
4522
        begin
4523
            $display("Parity checker testing failed! Time %t ", $time) ;
4524
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4525
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4526
        end
4527
        else
4528
            test_ok ;
4529
    `else
4530
    `ifdef GUEST
4531
        repeat( 4 )
4532 26 mihad
            @(posedge wb_clock) ;
4533
        repeat( 4 )
4534 15 mihad
            @(posedge pci_clock) ;
4535
        if ( INTA !== 1 )
4536
        begin
4537
            $display("Parity checker testing failed! Time %t ", $time) ;
4538
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4539
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4540
        end
4541
        else
4542
            test_ok ;
4543
    `endif
4544
    `endif
4545
 
4546
    // check statuses!
4547
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4548
    ok = 1 ;
4549
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4550
    if ( temp_val1[31] !== 1 )
4551
    begin
4552
        $display("Parity checker testing failed! Time %t ", $time) ;
4553
        $display("Detected Parity Error bit was not set when parity error was presented on Read transaction!") ;
4554
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4555
        ok = 0 ;
4556
    end
4557
 
4558
    if ( temp_val1[30] !== 0 )
4559
    begin
4560
        $display("Parity checker testing failed! Time %t ", $time) ;
4561
        $display("Signalled System Error bit was set for no reason!") ;
4562
        test_fail("Signalled System Error bit was set for no reason") ;
4563
        ok = 0 ;
4564
    end
4565
 
4566
    if ( temp_val1[24] !== 0 )
4567
    begin
4568
        $display("Parity checker testing failed! Time %t ", $time) ;
4569
        $display("Master Data Parity Error bit was set when parity error was presented during read transaction, but Parity Response was disabled!") ;
4570
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4571
        ok = 0 ;
4572
    end
4573
 
4574
    if ( ok )
4575
        test_ok ;
4576
 
4577
    // clear statuses
4578
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4579
 
4580
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4581
    ok = 1 ;
4582
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4583
 
4584
    if ( temp_val1[4] !== 0 )
4585
    begin
4586
        $display("Parity checker testing failed! Time %t ", $time) ;
4587
        $display("System error interrupt status bit set for no reason!") ;
4588
        test_fail("System error interrupt status bit set for no reason") ;
4589
        ok = 0 ;
4590
    end
4591
 
4592
    if ( temp_val1[3] !== 0 )
4593
    begin
4594
        $display("Parity checker testing failed! Time %t ", $time) ;
4595
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4596
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4597
        ok = 0 ;
4598
    end
4599
 
4600
    if ( ok )
4601
        test_ok ;
4602
 
4603
    // enable all responses to parity errors!
4604
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4605
 
4606
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4607
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4608
 
4609
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4610
 
4611
    // repeat a read
4612
    fork
4613
    begin
4614
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4615
    end
4616
    begin:wait_perr6
4617
        perr_asserted = 0 ;
4618
        @(posedge pci_clock) ;
4619
        while ( PERR === 1 )
4620
            @(posedge pci_clock) ;
4621
 
4622
        perr_asserted = 1 ;
4623
        $display("Parity checker testing failed! Time %t ", $time) ;
4624
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4625
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4626
    end
4627
    begin
4628
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4629
        if ( ok !== 1 )
4630
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4631
 
4632
        repeat(2)
4633
            @(posedge pci_clock) ;
4634
 
4635
        disable wait_perr6 ;
4636
    end
4637
    join
4638
 
4639
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4640
    begin
4641
        $display("Parity checker testing failed! Time %t ", $time) ;
4642
        $display("Bridge failed to process single memory read!") ;
4643
        test_fail("bridge didn't process single memory read as expected") ;
4644
        ok = 0 ;
4645
    end
4646
 
4647
    if ( ok && !perr_asserted)
4648
        test_ok ;
4649
 
4650
    // check statuses!
4651
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4652
    ok = 1 ;
4653
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4654
    if ( temp_val1[31] !== 0 )
4655
    begin
4656
        $display("Parity checker testing failed! Time %t ", $time) ;
4657
        $display("Detected Parity Error bit was set for no reason!") ;
4658
        test_fail("Detected Parity Error bit was set for no reason") ;
4659
        ok = 0 ;
4660
    end
4661
 
4662
    if ( temp_val1[30] !== 0 )
4663
    begin
4664
        $display("Parity checker testing failed! Time %t ", $time) ;
4665
        $display("Signalled System Error bit was set for no reason!") ;
4666
        test_fail("Signalled System Error bit was set for no reason") ;
4667
        ok = 0 ;
4668
    end
4669
 
4670
    if ( temp_val1[24] !== 0 )
4671
    begin
4672
        $display("Parity checker testing failed! Time %t ", $time) ;
4673
        $display("Master Data Parity Error bit was set for no reason!") ;
4674
        test_fail("Master Data Parity Error bit was set for no reason") ;
4675
        ok = 0 ;
4676
    end
4677
 
4678
    if ( ok )
4679
        test_ok ;
4680
 
4681
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4682
    ok = 1 ;
4683
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4684
 
4685
    if ( temp_val1[4] !== 0 )
4686
    begin
4687
        $display("Parity checker testing failed! Time %t ", $time) ;
4688
        $display("System error interrupt status bit set for no reason!") ;
4689
        test_fail("System error interrupt status bit set for no reason") ;
4690
        ok = 0 ;
4691
    end
4692
 
4693
    if ( temp_val1[3] !== 0 )
4694
    begin
4695
        $display("Parity checker testing failed! Time %t ", $time) ;
4696
        $display("Parity error interrupt status bit set for no reason!") ;
4697
        test_fail("Parity error interrupt status bit set for no reason") ;
4698
        ok = 0 ;
4699
    end
4700
 
4701
    if ( ok )
4702
        test_ok ;
4703
 
4704
    $display("Presenting address parity error on PCI bus!") ;
4705
    // enable parity errors - this should not affect system errors
4706
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4707
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4708
 
4709
    // perform PCI write
4710
    // check transaction progress
4711
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4712
    fork
4713
    begin
4714
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4715
               target_address, 32'h1234_5678,
4716
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4717
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4718
        do_pause( 1 ) ;
4719
    end
4720
    begin:wait_serr7
4721
        perr_asserted = 0 ;
4722
        @(posedge pci_clock) ;
4723
        while( SERR === 1 )
4724
            @(posedge pci_clock) ;
4725
 
4726
        perr_asserted = 1 ;
4727
        $display("Parity checker testing failed! Time %t ", $time) ;
4728
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4729
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4730
    end
4731
    begin
4732
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4733
        if ( ok !== 1 )
4734
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4735
 
4736
        disable wait_serr7 ;
4737
    end
4738
    join
4739
 
4740
    if ( ok && !perr_asserted)
4741
        test_ok ;
4742
 
4743
    // check statuses!
4744
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4745
    ok = 1 ;
4746
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4747
    if ( temp_val1[31] !== 1 )
4748
    begin
4749
        $display("Parity checker testing failed! Time %t ", $time) ;
4750
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4751
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4752
        ok = 0 ;
4753
    end
4754
 
4755
    if ( temp_val1[30] !== 0 )
4756
    begin
4757
        $display("Parity checker testing failed! Time %t ", $time) ;
4758
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4759
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4760
        ok = 0 ;
4761
    end
4762
 
4763
    if ( temp_val1[24] !== 0 )
4764
    begin
4765
        $display("Parity checker testing failed! Time %t ", $time) ;
4766
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4767
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4768
        ok = 0 ;
4769
    end
4770
 
4771
    if ( ok )
4772
        test_ok ;
4773
 
4774
    // clear statuses
4775
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4776
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4777
    fork
4778
    begin
4779
        ipci_unsupported_commands_master.master_reference
4780
        (
4781
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4782
            32'h5555_5555,      // second part of address in dual address cycle
4783
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4784
            `BC_MEM_WRITE,      // normal command
4785
            4'h0,               // byte enables
4786
            32'h1234_5678,      // data
4787
            1'b1,               // make address parity error on first phase of dual address
4788
            1'b0,               // make address parity error on second phase of dual address
4789
            ok                  // result of operation
4790
        ) ;
4791
        disable wait_serr8 ;
4792
    end
4793
    begin:wait_serr8
4794
        perr_asserted = 0 ;
4795
        @(posedge pci_clock) ;
4796
        while( SERR === 1 )
4797
            @(posedge pci_clock) ;
4798
 
4799
        perr_asserted = 1 ;
4800
        $display("Parity checker testing failed! Time %t ", $time) ;
4801
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4802
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4803
    end
4804
    join
4805
 
4806
    if ( ok && !perr_asserted)
4807
        test_ok ;
4808
 
4809
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4810
    fork
4811
    begin
4812
        ipci_unsupported_commands_master.master_reference
4813
        (
4814
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4815
            32'h5555_5555,      // second part of address in dual address cycle
4816
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4817
            `BC_MEM_WRITE,      // normal command
4818
            4'h0,               // byte enables
4819
            32'h1234_5678,      // data
4820
            1'b0,               // make address parity error on first phase of dual address
4821
            1'b1,               // make address parity error on second phase of dual address
4822
            ok                  // result of operation
4823
        ) ;
4824
        disable wait_serr9 ;
4825
    end
4826
    begin:wait_serr9
4827
        perr_asserted = 0 ;
4828
        @(posedge pci_clock) ;
4829
        while( SERR === 1 )
4830
            @(posedge pci_clock) ;
4831
 
4832
        perr_asserted = 1 ;
4833
        $display("Parity checker testing failed! Time %t ", $time) ;
4834
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4835
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4836
    end
4837
    join
4838
 
4839
    if ( ok && !perr_asserted)
4840
        test_ok ;
4841
 
4842
    // check statuses!
4843
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4844
    ok = 1 ;
4845
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4846
    if ( temp_val1[31] !== 1 )
4847
    begin
4848
        $display("Parity checker testing failed! Time %t ", $time) ;
4849
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4850
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4851
        ok = 0 ;
4852
    end
4853
 
4854
    if ( temp_val1[30] !== 0 )
4855
    begin
4856
        $display("Parity checker testing failed! Time %t ", $time) ;
4857
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4858
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4859
        ok = 0 ;
4860
    end
4861
 
4862
    if ( temp_val1[24] !== 0 )
4863
    begin
4864
        $display("Parity checker testing failed! Time %t ", $time) ;
4865
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4866
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4867
        ok = 0 ;
4868
    end
4869
 
4870
    if ( ok )
4871
        test_ok ;
4872
 
4873
    // clear statuses
4874
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4875
 
4876
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4877
    fork
4878
    begin
4879
        ipci_unsupported_commands_master.master_reference
4880
        (
4881
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4882
            32'h5555_5555,      // second part of address in dual address cycle
4883
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4884
            `BC_MEM_WRITE,      // normal command
4885
            4'h0,               // byte enables
4886
            32'h1234_5678,      // data
4887
            1'b1,               // make address parity error on first phase of dual address
4888
            1'b1,               // make address parity error on second phase of dual address
4889
            ok                  // result of operation
4890
        ) ;
4891
        disable wait_serr10 ;
4892
    end
4893
    begin:wait_serr10
4894
        perr_asserted = 0 ;
4895
        @(posedge pci_clock) ;
4896
        while( SERR === 1 )
4897
            @(posedge pci_clock) ;
4898
 
4899
        perr_asserted = 1 ;
4900
        $display("Parity checker testing failed! Time %t ", $time) ;
4901
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4902
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4903
    end
4904
    join
4905
 
4906
    if ( ok && !perr_asserted)
4907
        test_ok ;
4908
 
4909
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
4910
 
4911
    `ifdef HOST
4912
        repeat(4)
4913 26 mihad
            @(posedge pci_clock) ;
4914
        repeat(4)
4915 15 mihad
            @(posedge wb_clock) ;
4916
        if ( INT_O !== 0 )
4917
        begin
4918
            $display("Parity checker testing failed! Time %t ", $time) ;
4919
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
4920
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
4921
        end
4922
        else
4923
            test_ok ;
4924
    `else
4925
    `ifdef GUEST
4926 26 mihad
        repeat(4)
4927
            @(posedge wb_clock) ;
4928
        repeat(4)
4929 15 mihad
            @(posedge pci_clock) ;
4930
 
4931
        if ( INTA !== 1 )
4932
        begin
4933
            $display("Parity checker testing failed! Time %t ", $time) ;
4934
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
4935
            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") ;
4936
        end
4937
        else
4938
            test_ok ;
4939
    `endif
4940
    `endif
4941
 
4942
    // check statuses!
4943
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4944
    ok = 1 ;
4945
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4946
    if ( temp_val1[31] !== 1 )
4947
    begin
4948
        $display("Parity checker testing failed! Time %t ", $time) ;
4949
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4950
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4951
        ok = 0 ;
4952
    end
4953
 
4954
    if ( temp_val1[30] !== 0 )
4955
    begin
4956
        $display("Parity checker testing failed! Time %t ", $time) ;
4957
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4958
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4959
        ok = 0 ;
4960
    end
4961
 
4962
    if ( temp_val1[24] !== 0 )
4963
    begin
4964
        $display("Parity checker testing failed! Time %t ", $time) ;
4965
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4966
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4967
        ok = 0 ;
4968
    end
4969
 
4970
    if ( ok )
4971
        test_ok ;
4972
 
4973
    // clear statuses
4974
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4975
 
4976
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4977
    ok = 1 ;
4978
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4979
 
4980
    if ( temp_val1[4] !== 0 )
4981
    begin
4982
        $display("Parity checker testing failed! Time %t ", $time) ;
4983
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
4984
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
4985
        ok = 0 ;
4986
    end
4987
 
4988
    if ( temp_val1[3] !== 0 )
4989
    begin
4990
        $display("Parity checker testing failed! Time %t ", $time) ;
4991
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
4992
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
4993
        ok = 0 ;
4994
    end
4995
 
4996
    if ( ok )
4997
        test_ok ;
4998
 
4999
    // now enable system error signaling and test response
5000
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5001
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5002
 
5003
    fork
5004
    begin
5005
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5006
               target_address, 32'h1234_5678,
5007
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5008
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5009
        do_pause( 1 ) ;
5010
    end
5011
    begin:wait_serr11
5012
        perr_asserted = 0 ;
5013
        @(posedge pci_clock) ;
5014
        while( SERR === 1 )
5015
            @(posedge pci_clock) ;
5016
 
5017
        if ( SERR === 0 )
5018
            perr_asserted = 1 ;
5019
    end
5020
    begin
5021
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5022
        if ( ok !== 1 )
5023
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5024
 
5025
        @(posedge pci_clock) ;
5026
        #2 ;
5027
        disable wait_serr11 ;
5028
    end
5029
    join
5030
 
5031
    if ( ok && perr_asserted)
5032
        test_ok ;
5033
    else
5034
    if ( !perr_asserted )
5035
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5036
 
5037
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5038
 
5039
    `ifdef HOST
5040
        repeat(4)
5041 26 mihad
            @(posedge pci_clock) ;
5042
        repeat(4)
5043 15 mihad
            @(posedge wb_clock) ;
5044
        if ( INT_O !== 1 )
5045
        begin
5046
            $display("Parity checker testing failed! Time %t ", $time) ;
5047
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5048
            test_fail("Interrupt Request was not triggered as expected") ;
5049
        end
5050
        else
5051
            test_ok ;
5052
    `else
5053
    `ifdef GUEST
5054 26 mihad
        repeat(4)
5055
            @(posedge wb_clock) ;
5056
        repeat(4)
5057 15 mihad
            @(posedge pci_clock) ;
5058
 
5059
        if ( INTA !== 1 )
5060
        begin
5061
            $display("Parity checker testing failed! Time %t ", $time) ;
5062
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5063
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5064
        end
5065
        else
5066
            test_ok ;
5067
    `endif
5068
    `endif
5069
 
5070
    // check statuses!
5071
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5072
    ok = 1 ;
5073
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5074
    if ( temp_val1[31] !== 1 )
5075
    begin
5076
        $display("Parity checker testing failed! Time %t ", $time) ;
5077
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5078
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5079
        ok = 0 ;
5080
    end
5081
 
5082
    if ( temp_val1[30] !== 1 )
5083
    begin
5084
        $display("Parity checker testing failed! Time %t ", $time) ;
5085
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5086
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5087
        ok = 0 ;
5088
    end
5089
 
5090
    if ( temp_val1[24] !== 0 )
5091
    begin
5092
        $display("Parity checker testing failed! Time %t ", $time) ;
5093
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5094
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5095
        ok = 0 ;
5096
    end
5097
 
5098
    if ( ok )
5099
        test_ok ;
5100
 
5101
    // clear statuses
5102
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5103
 
5104
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5105
 
5106
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5107
    ok = 1 ;
5108
 
5109
    `ifdef HOST
5110
    if ( temp_val1[4] !== 1 )
5111
    begin
5112
        $display("Parity checker testing failed! Time %t ", $time) ;
5113
        $display("System error interrupt status bit not set when expected!") ;
5114
        test_fail("System error interrupt status bit not set when expected") ;
5115
        ok = 0 ;
5116
    end
5117
    `else
5118
    if ( temp_val1[4] !== 0 )
5119
    begin
5120
        $display("Parity checker testing failed! Time %t ", $time) ;
5121
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5122
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5123
        ok = 0 ;
5124
    end
5125
    `endif
5126
 
5127
    if ( temp_val1[3] !== 0 )
5128
    begin
5129
        $display("Parity checker testing failed! Time %t ", $time) ;
5130
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5131
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5132
        ok = 0 ;
5133
    end
5134
 
5135
    if ( ok )
5136
        test_ok ;
5137
 
5138
    // clear statuses
5139
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5140
 
5141
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5142
    fork
5143
    begin
5144
        ipci_unsupported_commands_master.master_reference
5145
        (
5146
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5147
            32'h5555_5555,      // second part of address in dual address cycle
5148
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5149
            `BC_MEM_WRITE,      // normal command
5150
            4'h0,               // byte enables
5151
            32'h1234_5678,      // data
5152
            1'b1,               // make address parity error on first phase of dual address
5153
            1'b0,               // make address parity error on second phase of dual address
5154
            ok                  // result of operation
5155
        ) ;
5156
        disable wait_serr14 ;
5157
    end
5158
    begin:wait_serr14
5159
        perr_asserted = 0 ;
5160
        @(posedge pci_clock) ;
5161
        while( SERR === 1 )
5162
            @(posedge pci_clock) ;
5163
 
5164
        if ( SERR === 0 )
5165
            perr_asserted = 1 ;
5166
    end
5167
    join
5168
 
5169
    if ( ok && perr_asserted)
5170
        test_ok ;
5171
    else
5172
    if ( !perr_asserted )
5173
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5174
 
5175
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5176
 
5177
    `ifdef HOST
5178
        repeat(4)
5179 26 mihad
            @(posedge pci_clock) ;
5180
        repeat(4)
5181 15 mihad
            @(posedge wb_clock) ;
5182
        if ( INT_O !== 1 )
5183
        begin
5184
            $display("Parity checker testing failed! Time %t ", $time) ;
5185
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5186
            test_fail("Interrupt Request was not triggered as expected") ;
5187
        end
5188
        else
5189
            test_ok ;
5190
    `else
5191
    `ifdef GUEST
5192 26 mihad
        repeat(4)
5193
            @(posedge wb_clock) ;
5194
        repeat(4)
5195 15 mihad
            @(posedge pci_clock) ;
5196
 
5197
        if ( INTA !== 1 )
5198
        begin
5199
            $display("Parity checker testing failed! Time %t ", $time) ;
5200
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5201
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5202
        end
5203
        else
5204
            test_ok ;
5205
    `endif
5206
    `endif
5207
 
5208
    // check statuses!
5209
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5210
    ok = 1 ;
5211
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5212
    if ( temp_val1[31] !== 1 )
5213
    begin
5214
        $display("Parity checker testing failed! Time %t ", $time) ;
5215
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5216
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5217
        ok = 0 ;
5218
    end
5219
 
5220
    if ( temp_val1[30] !== 1 )
5221
    begin
5222
        $display("Parity checker testing failed! Time %t ", $time) ;
5223
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5224
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5225
        ok = 0 ;
5226
    end
5227
 
5228
    if ( temp_val1[24] !== 0 )
5229
    begin
5230
        $display("Parity checker testing failed! Time %t ", $time) ;
5231
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5232
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5233
        ok = 0 ;
5234
    end
5235
 
5236
    if ( ok )
5237
        test_ok ;
5238
 
5239
    // clear statuses
5240
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5241
 
5242
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5243
 
5244
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5245
    ok = 1 ;
5246
 
5247
    `ifdef HOST
5248
    if ( temp_val1[4] !== 1 )
5249
    begin
5250
        $display("Parity checker testing failed! Time %t ", $time) ;
5251
        $display("System error interrupt status bit not set when expected!") ;
5252
        test_fail("System error interrupt status bit not set when expected") ;
5253
        ok = 0 ;
5254
    end
5255
    `else
5256
    if ( temp_val1[4] !== 0 )
5257
    begin
5258
        $display("Parity checker testing failed! Time %t ", $time) ;
5259
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5260
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5261
        ok = 0 ;
5262
    end
5263
    `endif
5264
 
5265
    if ( temp_val1[3] !== 0 )
5266
    begin
5267
        $display("Parity checker testing failed! Time %t ", $time) ;
5268
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5269
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5270
        ok = 0 ;
5271
    end
5272
 
5273
    if ( ok )
5274
        test_ok ;
5275
 
5276
    // clear statuses
5277
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5278
 
5279
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5280
    fork
5281
    begin
5282
        ipci_unsupported_commands_master.master_reference
5283
        (
5284
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5285
            32'h5555_5555,      // second part of address in dual address cycle
5286
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5287
            `BC_MEM_WRITE,      // normal command
5288
            4'h0,               // byte enables
5289
            32'h1234_5678,      // data
5290
            1'b0,               // make address parity error on first phase of dual address
5291
            1'b1,               // make address parity error on second phase of dual address
5292
            ok                  // result of operation
5293
        ) ;
5294
        disable wait_serr15 ;
5295
    end
5296
    begin:wait_serr15
5297
        perr_asserted = 0 ;
5298
        @(posedge pci_clock) ;
5299
        while( SERR === 1 )
5300
            @(posedge pci_clock) ;
5301
 
5302
        if ( SERR === 0 )
5303
            perr_asserted = 1 ;
5304
    end
5305
    join
5306
 
5307
    if ( ok && perr_asserted)
5308
        test_ok ;
5309
    else
5310
    if ( !perr_asserted )
5311
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5312
 
5313
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5314
 
5315
    `ifdef HOST
5316
        repeat(4)
5317 26 mihad
            @(posedge pci_clock) ;
5318
        repeat(4)
5319 15 mihad
            @(posedge wb_clock) ;
5320
        if ( INT_O !== 1 )
5321
        begin
5322
            $display("Parity checker testing failed! Time %t ", $time) ;
5323
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5324
            test_fail("Interrupt Request was not triggered as expected") ;
5325
        end
5326
        else
5327
            test_ok ;
5328
    `else
5329
    `ifdef GUEST
5330 26 mihad
        repeat(4)
5331
            @(posedge wb_clock) ;
5332
        repeat(4)
5333 15 mihad
            @(posedge pci_clock) ;
5334
 
5335
        if ( INTA !== 1 )
5336
        begin
5337
            $display("Parity checker testing failed! Time %t ", $time) ;
5338
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5339
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5340
        end
5341
        else
5342
            test_ok ;
5343
    `endif
5344
    `endif
5345
 
5346
    // check statuses!
5347
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5348
    ok = 1 ;
5349
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5350
    if ( temp_val1[31] !== 1 )
5351
    begin
5352
        $display("Parity checker testing failed! Time %t ", $time) ;
5353
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5354
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5355
        ok = 0 ;
5356
    end
5357
 
5358
    if ( temp_val1[30] !== 1 )
5359
    begin
5360
        $display("Parity checker testing failed! Time %t ", $time) ;
5361
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5362
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5363
        ok = 0 ;
5364
    end
5365
 
5366
    if ( temp_val1[24] !== 0 )
5367
    begin
5368
        $display("Parity checker testing failed! Time %t ", $time) ;
5369
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5370
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5371
        ok = 0 ;
5372
    end
5373
 
5374
    if ( ok )
5375
        test_ok ;
5376
 
5377
    // clear statuses
5378
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5379
 
5380
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5381
 
5382
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5383
    ok = 1 ;
5384
 
5385
    `ifdef HOST
5386
    if ( temp_val1[4] !== 1 )
5387
    begin
5388
        $display("Parity checker testing failed! Time %t ", $time) ;
5389
        $display("System error interrupt status bit not set when expected!") ;
5390
        test_fail("System error interrupt status bit not set when expected") ;
5391
        ok = 0 ;
5392
    end
5393
    `else
5394
    if ( temp_val1[4] !== 0 )
5395
    begin
5396
        $display("Parity checker testing failed! Time %t ", $time) ;
5397
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5398
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5399
        ok = 0 ;
5400
    end
5401
    `endif
5402
 
5403
    if ( temp_val1[3] !== 0 )
5404
    begin
5405
        $display("Parity checker testing failed! Time %t ", $time) ;
5406
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5407
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5408
        ok = 0 ;
5409
    end
5410
 
5411
    if ( ok )
5412
        test_ok ;
5413
 
5414
    // clear statuses
5415
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5416
 
5417
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5418
    fork
5419
    begin
5420
        ipci_unsupported_commands_master.master_reference
5421
        (
5422
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5423
            32'h5555_5555,      // second part of address in dual address cycle
5424
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5425
            `BC_MEM_WRITE,      // normal command
5426
            4'h0,               // byte enables
5427
            32'h1234_5678,      // data
5428
            1'b1,               // make address parity error on first phase of dual address
5429
            1'b1,               // make address parity error on second phase of dual address
5430
            ok                  // result of operation
5431
        ) ;
5432
        disable wait_serr16 ;
5433
    end
5434
    begin:wait_serr16
5435
        perr_asserted = 0 ;
5436
        @(posedge pci_clock) ;
5437
        while( SERR === 1 )
5438
            @(posedge pci_clock) ;
5439
 
5440
        if ( SERR === 0 )
5441
            perr_asserted = 1 ;
5442
    end
5443
    join
5444
 
5445
    if ( ok && perr_asserted)
5446
        test_ok ;
5447
    else
5448
    if ( !perr_asserted )
5449
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5450
 
5451
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5452
 
5453
    `ifdef HOST
5454
        repeat(4)
5455 26 mihad
            @(posedge pci_clock) ;
5456
        repeat(4)
5457 15 mihad
            @(posedge wb_clock) ;
5458
        if ( INT_O !== 1 )
5459
        begin
5460
            $display("Parity checker testing failed! Time %t ", $time) ;
5461
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5462
            test_fail("Interrupt Request was not triggered as expected") ;
5463
        end
5464
        else
5465
            test_ok ;
5466
    `else
5467
    `ifdef GUEST
5468 26 mihad
        repeat(4)
5469
            @(posedge wb_clock) ;
5470
        repeat(4)
5471 15 mihad
            @(posedge pci_clock) ;
5472
 
5473
        if ( INTA !== 1 )
5474
        begin
5475
            $display("Parity checker testing failed! Time %t ", $time) ;
5476
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5477
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5478
        end
5479
        else
5480
            test_ok ;
5481
    `endif
5482
    `endif
5483
 
5484
    // check statuses!
5485
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5486
    ok = 1 ;
5487
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5488
    if ( temp_val1[31] !== 1 )
5489
    begin
5490
        $display("Parity checker testing failed! Time %t ", $time) ;
5491
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5492
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5493
        ok = 0 ;
5494
    end
5495
 
5496
    if ( temp_val1[30] !== 1 )
5497
    begin
5498
        $display("Parity checker testing failed! Time %t ", $time) ;
5499
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5500
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5501
        ok = 0 ;
5502
    end
5503
 
5504
    if ( temp_val1[24] !== 0 )
5505
    begin
5506
        $display("Parity checker testing failed! Time %t ", $time) ;
5507
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5508
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5509
        ok = 0 ;
5510
    end
5511
 
5512
    if ( ok )
5513
        test_ok ;
5514
 
5515
    // clear statuses
5516
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5517
 
5518
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5519
 
5520
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5521
    ok = 1 ;
5522
 
5523
    `ifdef HOST
5524
    if ( temp_val1[4] !== 1 )
5525
    begin
5526
        $display("Parity checker testing failed! Time %t ", $time) ;
5527
        $display("System error interrupt status bit not set when expected!") ;
5528
        test_fail("System error interrupt status bit not set when expected") ;
5529
        ok = 0 ;
5530
    end
5531
    `else
5532
    if ( temp_val1[4] !== 0 )
5533
    begin
5534
        $display("Parity checker testing failed! Time %t ", $time) ;
5535
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5536
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5537
        ok = 0 ;
5538
    end
5539
    `endif
5540
 
5541
    if ( temp_val1[3] !== 0 )
5542
    begin
5543
        $display("Parity checker testing failed! Time %t ", $time) ;
5544
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5545
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5546
        ok = 0 ;
5547
    end
5548
 
5549
    if ( ok )
5550
        test_ok ;
5551
 
5552
    // clear statuses
5553
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5554
 
5555
    // now just disable Parity Error response - on Address par errors nothing should happen
5556
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5557
 
5558
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5559
    fork
5560
    begin
5561
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5562
               target_address, 32'h1234_5678,
5563
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5564
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5565
        do_pause( 1 ) ;
5566
    end
5567
    begin:wait_serr12
5568
        perr_asserted = 0 ;
5569
        @(posedge pci_clock) ;
5570
        while( SERR === 1 )
5571
            @(posedge pci_clock) ;
5572
 
5573
        perr_asserted = 1 ;
5574
        $display("Parity checker testing failed! Time %t ", $time) ;
5575
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5576
        test_fail("SERR asserted when parity error response was disabled") ;
5577
    end
5578
    begin
5579
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5580
        if ( ok !== 1 )
5581
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5582
 
5583
        disable wait_serr12 ;
5584
    end
5585
    join
5586
 
5587
    if ( ok && !perr_asserted )
5588
        test_ok ;
5589
 
5590
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5591
    `ifdef HOST
5592 26 mihad
        repeat (4)
5593
            @(posedge pci_clock) ;
5594 15 mihad
        repeat(4)
5595
            @(posedge wb_clock) ;
5596
        if ( INT_O !== 0 )
5597
        begin
5598
            $display("Parity checker testing failed! Time %t ", $time) ;
5599
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5600
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5601
        end
5602
        else
5603
            test_ok ;
5604
    `else
5605
    `ifdef GUEST
5606 26 mihad
        repeat(4)
5607
            @(posedge wb_clock) ;
5608
        repeat (4)
5609 15 mihad
            @(posedge pci_clock) ;
5610
 
5611
        if ( INTA !== 1 )
5612
        begin
5613
            $display("Parity checker testing failed! Time %t ", $time) ;
5614
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5615
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5616
        end
5617
        else
5618
            test_ok ;
5619
    `endif
5620
    `endif
5621
 
5622
    // check statuses!
5623
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5624
    ok = 1 ;
5625
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5626
    if ( temp_val1[31] !== 1 )
5627
    begin
5628
        $display("Parity checker testing failed! Time %t ", $time) ;
5629
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5630
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5631
        ok = 0 ;
5632
    end
5633
 
5634
    if ( temp_val1[30] !== 0 )
5635
    begin
5636
        $display("Parity checker testing failed! Time %t ", $time) ;
5637
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5638
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5639
        ok = 0 ;
5640
    end
5641
 
5642
    if ( temp_val1[24] !== 0 )
5643
    begin
5644
        $display("Parity checker testing failed! Time %t ", $time) ;
5645
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5646
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5647
        ok = 0 ;
5648
    end
5649
 
5650
    if ( ok )
5651
        test_ok ;
5652
 
5653
    // clear statuses
5654
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5655
 
5656
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5657
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5658
    ok = 1 ;
5659
    if ( temp_val1[4] !== 0 )
5660
    begin
5661
        $display("Parity checker testing failed! Time %t ", $time) ;
5662
        $display("System error interrupt status bit set when not expected!") ;
5663
        test_fail("System error interrupt status bit set when not expected") ;
5664
        ok = 0 ;
5665
    end
5666
 
5667
    if ( temp_val1[3] !== 0 )
5668
    begin
5669
        $display("Parity checker testing failed! Time %t ", $time) ;
5670
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5671
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5672
        ok = 0 ;
5673
    end
5674
 
5675
    if ( ok )
5676
        test_ok ;
5677
 
5678
    // clear statuses
5679
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5680
 
5681
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5682
    fork
5683
    begin
5684
        ipci_unsupported_commands_master.master_reference
5685
        (
5686
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5687
            32'h5555_5555,      // second part of address in dual address cycle
5688
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5689
            `BC_MEM_WRITE,      // normal command
5690
            4'h0,               // byte enables
5691
            32'h1234_5678,      // data
5692
            1'b1,               // make address parity error on first phase of dual address
5693
            1'b0,               // make address parity error on second phase of dual address
5694
            ok                  // result of operation
5695
        ) ;
5696
        disable wait_serr17 ;
5697
    end
5698
    begin:wait_serr17
5699
        perr_asserted = 0 ;
5700
        @(posedge pci_clock) ;
5701
        while( SERR === 1 )
5702
            @(posedge pci_clock) ;
5703
 
5704
        perr_asserted = 1 ;
5705
        $display("Parity checker testing failed! Time %t ", $time) ;
5706
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5707
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5708
    end
5709
    join
5710
 
5711
    if ( ok && !perr_asserted)
5712
        test_ok ;
5713
 
5714
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5715
    fork
5716
    begin
5717
        ipci_unsupported_commands_master.master_reference
5718
        (
5719
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5720
            32'h5555_5555,      // second part of address in dual address cycle
5721
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5722
            `BC_MEM_WRITE,      // normal command
5723
            4'h0,               // byte enables
5724
            32'h1234_5678,      // data
5725
            1'b0,               // make address parity error on first phase of dual address
5726
            1'b1,               // make address parity error on second phase of dual address
5727
            ok                  // result of operation
5728
        ) ;
5729
        disable wait_serr18 ;
5730
    end
5731
    begin:wait_serr18
5732
        perr_asserted = 0 ;
5733
        @(posedge pci_clock) ;
5734
        while( SERR === 1 )
5735
            @(posedge pci_clock) ;
5736
 
5737
        perr_asserted = 1 ;
5738
        $display("Parity checker testing failed! Time %t ", $time) ;
5739
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5740
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5741
    end
5742
    join
5743
 
5744
    if ( ok && !perr_asserted)
5745
        test_ok ;
5746
 
5747
    // check statuses!
5748
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5749
    ok = 1 ;
5750
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5751
    if ( temp_val1[31] !== 1 )
5752
    begin
5753
        $display("Parity checker testing failed! Time %t ", $time) ;
5754
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5755
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5756
        ok = 0 ;
5757
    end
5758
 
5759
    if ( temp_val1[30] !== 0 )
5760
    begin
5761
        $display("Parity checker testing failed! Time %t ", $time) ;
5762
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5763
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5764
        ok = 0 ;
5765
    end
5766
 
5767
    if ( temp_val1[24] !== 0 )
5768
    begin
5769
        $display("Parity checker testing failed! Time %t ", $time) ;
5770
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5771
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5772
        ok = 0 ;
5773
    end
5774
 
5775
    if ( ok )
5776
        test_ok ;
5777
 
5778
    // clear statuses
5779
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5780
 
5781
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5782
    fork
5783
    begin
5784
        ipci_unsupported_commands_master.master_reference
5785
        (
5786
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5787
            32'h5555_5555,      // second part of address in dual address cycle
5788
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5789
            `BC_MEM_WRITE,      // normal command
5790
            4'h0,               // byte enables
5791
            32'h1234_5678,      // data
5792
            1'b1,               // make address parity error on first phase of dual address
5793
            1'b1,               // make address parity error on second phase of dual address
5794
            ok                  // result of operation
5795
        ) ;
5796
        disable wait_serr19 ;
5797
    end
5798
    begin:wait_serr19
5799
        perr_asserted = 0 ;
5800
        @(posedge pci_clock) ;
5801
        while( SERR === 1 )
5802
            @(posedge pci_clock) ;
5803
 
5804
        perr_asserted = 1 ;
5805
        $display("Parity checker testing failed! Time %t ", $time) ;
5806
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5807
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5808
    end
5809
    join
5810
 
5811
    if ( ok && !perr_asserted)
5812
        test_ok ;
5813
 
5814
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5815
 
5816
    `ifdef HOST
5817
        repeat(4)
5818 26 mihad
            @(posedge pci_clock) ;
5819
        repeat(4)
5820 15 mihad
            @(posedge wb_clock) ;
5821
        if ( INT_O !== 0 )
5822
        begin
5823
            $display("Parity checker testing failed! Time %t ", $time) ;
5824
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5825
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5826
        end
5827
        else
5828
            test_ok ;
5829
    `else
5830
    `ifdef GUEST
5831 26 mihad
        repeat(4)
5832
            @(posedge wb_clock) ;
5833
        repeat(4)
5834 15 mihad
            @(posedge pci_clock) ;
5835
 
5836
        if ( INTA !== 1 )
5837
        begin
5838
            $display("Parity checker testing failed! Time %t ", $time) ;
5839
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5840
            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") ;
5841
        end
5842
        else
5843
            test_ok ;
5844
    `endif
5845
    `endif
5846
 
5847
    // check statuses!
5848
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5849
    ok = 1 ;
5850
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5851
    if ( temp_val1[31] !== 1 )
5852
    begin
5853
        $display("Parity checker testing failed! Time %t ", $time) ;
5854
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5855
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5856
        ok = 0 ;
5857
    end
5858
 
5859
    if ( temp_val1[30] !== 0 )
5860
    begin
5861
        $display("Parity checker testing failed! Time %t ", $time) ;
5862
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5863
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5864
        ok = 0 ;
5865
    end
5866
 
5867
    if ( temp_val1[24] !== 0 )
5868
    begin
5869
        $display("Parity checker testing failed! Time %t ", $time) ;
5870
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5871
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5872
        ok = 0 ;
5873
    end
5874
 
5875
    if ( ok )
5876
        test_ok ;
5877
 
5878
    // clear statuses
5879
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5880
 
5881
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5882
 
5883
    // do normal write
5884
    fork
5885
    begin
5886
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5887
               target_address, 32'h1234_5678, `Test_All_Bytes,
5888
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5889
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5890
        do_pause( 1 ) ;
5891
    end
5892
    begin:wait_serr13
5893
        perr_asserted = 0 ;
5894
        @(posedge pci_clock) ;
5895
        while( SERR === 1 )
5896
            @(posedge pci_clock) ;
5897
 
5898
        perr_asserted = 1 ;
5899
        $display("Parity checker testing failed! Time %t ", $time) ;
5900
        $display("SERR asserted for no reason!") ;
5901
        test_fail("SERR was asserted for no reason") ;
5902
    end
5903
    begin
5904
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5905
        if ( ok !== 1 )
5906
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5907
 
5908
        disable wait_serr13 ;
5909
    end
5910
    join
5911
 
5912
    if ( ok && !perr_asserted )
5913
        test_ok ;
5914
 
5915
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
5916
    `ifdef HOST
5917 26 mihad
        repeat( 4 )
5918
            @(posedge pci_clock) ;
5919 15 mihad
        repeat(4)
5920
            @(posedge wb_clock) ;
5921
        if ( INT_O !== 0 )
5922
        begin
5923
            $display("Parity checker testing failed! Time %t ", $time) ;
5924
            $display("Interrupt request asserted for no reason!") ;
5925
            test_fail("Interrupt request was asserted for no reason") ;
5926
        end
5927
        else
5928
            test_ok ;
5929
    `else
5930
    `ifdef GUEST
5931 26 mihad
        repeat(4)
5932
            @(posedge wb_clock) ;
5933
        repeat(4)
5934 15 mihad
            @(posedge pci_clock) ;
5935
 
5936
        if ( INTA !== 1 )
5937
        begin
5938
            $display("Parity checker testing failed! Time %t ", $time) ;
5939
            $display("Interrupt request asserted for no reason!") ;
5940
            test_fail("Interrupt request was asserted for no reason") ;
5941
        end
5942
        else
5943
            test_ok ;
5944
    `endif
5945
    `endif
5946
 
5947
    // check statuses!
5948
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5949
    ok = 1 ;
5950
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5951
    if ( temp_val1[31] !== 0 )
5952
    begin
5953
        $display("Parity checker testing failed! Time %t ", $time) ;
5954
        $display("Detected Parity Error bit was set for no reason!") ;
5955
        test_fail("Detected Parity Error bit was set for no reason") ;
5956
        ok = 0 ;
5957
    end
5958
 
5959
    if ( temp_val1[30] !== 0 )
5960
    begin
5961
        $display("Parity checker testing failed! Time %t ", $time) ;
5962
        $display("Signalled System Error bit was set for no reason!") ;
5963
        test_fail("Signalled System Error bit was set for no reason") ;
5964
        ok = 0 ;
5965
    end
5966
 
5967
    if ( temp_val1[24] !== 0 )
5968
    begin
5969
        $display("Parity checker testing failed! Time %t ", $time) ;
5970
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5971
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5972
        ok = 0 ;
5973
    end
5974
 
5975
    if ( ok )
5976
        test_ok ;
5977
 
5978
    // clear statuses
5979
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5980
 
5981
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5982
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5983
    ok = 1 ;
5984
 
5985
    if ( temp_val1[4] !== 0 )
5986
    begin
5987
        $display("Parity checker testing failed! Time %t ", $time) ;
5988
        $display("System error interrupt status bit set when not expected!") ;
5989
        test_fail("System error interrupt status bit set when not expected") ;
5990
        ok = 0 ;
5991
    end
5992
 
5993
    if ( temp_val1[3] !== 0 )
5994
    begin
5995
        $display("Parity checker testing failed! Time %t ", $time) ;
5996
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5997
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5998
        ok = 0 ;
5999
    end
6000
 
6001
    if ( ok )
6002
        test_ok ;
6003
 
6004
    // clear statuses
6005
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6006
 
6007
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6008
 
6009
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6010
 
6011
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6012
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6013
 
6014
    // setup target's image!
6015
    target_address  = Target_Base_Addr_R[1] ;
6016
 
6017
    // base address
6018
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6019
 
6020
    // address mask
6021
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6022
 
6023
    // image control
6024
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6025
 
6026
    // enable everything possible for parity checking
6027
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6028
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6029
 
6030
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6031
 
6032
    fork
6033
    begin
6034
        if ( target_mem_image === 1 )
6035
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6036
                   target_address, 32'h1234_5678,
6037
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6038
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6039
        else
6040
            PCIU_IO_WRITE_MAKE_PERR (
6041
                                    `Test_Master_1,
6042
                                    target_address,
6043
                                    32'h1234_5678,
6044
                                    4'h0,
6045
                                    1,
6046
                                    `Test_Target_Normal_Completion
6047
                                    );
6048
 
6049
        do_pause( 1 ) ;
6050
    end
6051
    begin:wait_perr11
6052
        perr_asserted = 0 ;
6053
        @(posedge pci_clock) ;
6054
        while ( PERR === 1 )
6055
            @(posedge pci_clock) ;
6056
 
6057
        if ( PERR === 0 )
6058
            perr_asserted = 1 ;
6059
 
6060
    end
6061
    begin
6062
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6063
 
6064
        if ( ok !== 1 )
6065
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6066
 
6067
        repeat(2)
6068
            @(posedge pci_clock) ;
6069
 
6070
        disable wait_perr11 ;
6071
    end
6072
    join
6073
 
6074
    if ( ok && perr_asserted )
6075
        test_ok ;
6076
    else
6077
    if ( !perr_asserted )
6078
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6079
 
6080
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6081
    `ifdef HOST
6082 26 mihad
        repeat (4)
6083
            @(posedge pci_clock) ;
6084 15 mihad
        repeat(4)
6085
            @(posedge wb_clock) ;
6086
        if ( INT_O !== 0 )
6087
        begin
6088
            $display("Parity checker testing failed! Time %t ", $time) ;
6089
            $display("Interrupt request asserted for no reason!") ;
6090
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6091
        end
6092
        else
6093
            test_ok ;
6094
    `else
6095
    `ifdef GUEST
6096 26 mihad
        repeat(4)
6097
            @(posedge wb_clock) ;
6098
        repeat (4)
6099 15 mihad
            @(posedge pci_clock) ;
6100
 
6101
        if ( INTA !== 1 )
6102
        begin
6103
            $display("Parity checker testing failed! Time %t ", $time) ;
6104
            $display("Interrupt request asserted for no reason!") ;
6105
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6106
        end
6107
        else
6108
            test_ok ;
6109
 
6110
    `endif
6111
    `endif
6112
 
6113
    // check statuses!
6114
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6115
    ok = 1 ;
6116
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6117
    if ( temp_val1[31] !== 1 )
6118
    begin
6119
        $display("Parity checker testing failed! Time %t ", $time) ;
6120
        $display("Detected Parity Error bit was not set after Target detected parity error!") ;
6121
        test_fail("Detected Parity Error bit was not set after Target detected parity error") ;
6122
        ok = 0 ;
6123
    end
6124
 
6125
    if ( temp_val1[30] !== 0 )
6126
    begin
6127
        $display("Parity checker testing failed! Time %t ", $time) ;
6128
        $display("Signalled System Error bit was set for no reason!") ;
6129
        test_fail("Signalled System Error bit was set for no reason") ;
6130
        ok = 0 ;
6131
    end
6132
 
6133
    if ( temp_val1[24] !== 0 )
6134
    begin
6135
        $display("Parity checker testing failed! Time %t ", $time) ;
6136
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6137
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6138
        ok = 0 ;
6139
    end
6140
 
6141
    if ( ok )
6142
        test_ok ;
6143
 
6144
    // clear statuses
6145
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6146
 
6147
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6148
 
6149
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6150
    ok = 1 ;
6151
    if ( temp_val1[4] !== 0 )
6152
    begin
6153
        $display("Parity checker testing failed! Time %t ", $time) ;
6154
        $display("System error interrupt status bit set when not expected!") ;
6155
        test_fail("System error interrupt status bit set when not expected") ;
6156
        ok = 0 ;
6157
    end
6158
 
6159
    if ( temp_val1[3] !== 0 )
6160
    begin
6161
        $display("Parity checker testing failed! Time %t ", $time) ;
6162
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6163
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6164
        ok = 0 ;
6165
    end
6166
 
6167
    if ( ok )
6168
        test_ok ;
6169
 
6170
    // clear statuses
6171
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6172
 
6173
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6174
 
6175
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6176
    fork
6177
    begin
6178
        if ( target_mem_image === 1 )
6179
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6180
                          target_address, 32'h1234_5678,
6181
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6182
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6183
        else
6184
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6185
 
6186
        do_pause( 1 ) ;
6187
    end
6188
    begin:wait_perr12
6189
        perr_asserted = 0 ;
6190
        @(posedge pci_clock) ;
6191
        while ( PERR === 1 )
6192
            @(posedge pci_clock) ;
6193
 
6194
        if ( PERR === 0 )
6195
            perr_asserted = 1 ;
6196
    end
6197
    begin
6198
 
6199
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6200
        if ( ok !== 1 )
6201
        begin
6202
            test_fail("Bridge failed to process Target Memory read correctly") ;
6203
            disable main ;
6204
        end
6205
 
6206
        repeat(3)
6207
            @(posedge pci_clock) ;
6208
 
6209
        if ( target_mem_image === 1 )
6210
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6211
                    target_address, 32'h1234_5678,
6212
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6213
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6214
        else
6215
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6216
 
6217
        do_pause( 1 ) ;
6218
 
6219
    end
6220
    begin
6221
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6222
        if ( ok !== 1 )
6223
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6224
        else
6225
        begin
6226
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6227
            if ( ok !== 1 )
6228
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6229
        end
6230
 
6231
        repeat(3)
6232
            @(posedge pci_clock) ;
6233
 
6234
        disable wait_perr12 ;
6235
    end
6236
    join
6237
 
6238
    if ( ok && perr_asserted )
6239
        test_ok ;
6240
    else
6241
    if ( !perr_asserted )
6242
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6243
 
6244
 
6245
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6246
    `ifdef HOST
6247
        repeat(4)
6248 26 mihad
            @(posedge pci_clock) ;
6249
        repeat(4)
6250 15 mihad
            @(posedge wb_clock) ;
6251
        if ( INT_O !== 0 )
6252
        begin
6253
            $display("Parity checker testing failed! Time %t ", $time) ;
6254
            $display("Interrupt request asserted for no reason!") ;
6255
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6256
        end
6257
        else
6258
            test_ok ;
6259
    `else
6260
    `ifdef GUEST
6261 26 mihad
        repeat(4)
6262
            @(posedge wb_clock) ;
6263
        repeat(4)
6264 15 mihad
            @(posedge pci_clock) ;
6265
 
6266
        if ( INTA !== 1 )
6267
        begin
6268
            $display("Parity checker testing failed! Time %t ", $time) ;
6269
            $display("Interrupt request asserted for no reason!") ;
6270
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6271
        end
6272
        else
6273
            test_ok ;
6274
    `endif
6275
    `endif
6276
 
6277
    // check statuses!
6278
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6279
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6280
    ok = 1 ;
6281
    if ( temp_val1[31] !== 1 )
6282
    begin
6283
        $display("Parity checker testing failed! Time %t ", $time) ;
6284
        $display("Detected Parity Error bit was not set after Target receive PERR asserted!") ;
6285
        test_fail("Detected Parity Error bit was not set after Target received PERR asserted on read reference") ;
6286
        ok = 0 ;
6287
    end
6288
 
6289
    if ( temp_val1[30] !== 0 )
6290
    begin
6291
        $display("Parity checker testing failed! Time %t ", $time) ;
6292
        $display("Signalled System Error bit was set for no reason!") ;
6293
        test_fail("Signalled System Error bit was set for no reason") ;
6294
        ok = 0 ;
6295
    end
6296
 
6297
    if ( temp_val1[24] !== 0 )
6298
    begin
6299
        $display("Parity checker testing failed! Time %t ", $time) ;
6300
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6301
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6302
        ok = 0 ;
6303
    end
6304
 
6305
    if ( ok )
6306
        test_ok ;
6307
 
6308
    // clear statuses
6309
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6310
 
6311
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6312
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6313
    ok = 1 ;
6314
    if ( temp_val1[4] !== 0 )
6315
    begin
6316
        $display("Parity checker testing failed! Time %t ", $time) ;
6317
        $display("System error interrupt status bit set when not expected!") ;
6318
        test_fail("System error interrupt status bit set when not expected") ;
6319
        ok = 0 ;
6320
    end
6321
 
6322
    if ( temp_val1[3] !== 0 )
6323
    begin
6324
        $display("Parity checker testing failed! Time %t ", $time) ;
6325
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6326
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6327
        ok = 0 ;
6328
    end
6329
 
6330
    if ( ok )
6331
        test_ok ;
6332
    // clear statuses
6333
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6334
 
6335
    $fdisplay(pci_mon_log_file_desc,
6336
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6337
    test_name = "DISABLE USED IMAGES" ;
6338
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6339
    if ( ok !== 1 )
6340
    begin
6341
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6342
        test_fail("WB Image Address Mask register could not be written to") ;
6343
        disable main ;
6344
    end
6345
 
6346
    config_write( p_am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6347
    if ( ok !== 1 )
6348
    begin
6349
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6350
        test_fail("PCI Image Address Mask register could not be written to") ;
6351
        disable main ;
6352
    end
6353
 
6354
    // disable target's 1 response to parity errors
6355
    configuration_cycle_write(0,             // bus number
6356
                              1,             // device number
6357
                              0,             // function number
6358
                              1,             // register number
6359
                              0,             // type of configuration cycle
6360
                              4'b0001,       // byte enables
6361
                              32'h0000_0007  // data
6362
                             ) ;
6363
 
6364
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6365
end
6366
endtask // parity_checking
6367
 
6368
task wb_to_pci_transactions ;
6369
    reg   [11:0] ctrl_offset ;
6370
    reg   [11:0] ba_offset ;
6371
    reg   [11:0] am_offset ;
6372
    reg   [11:0] pci_ctrl_offset ;
6373
    reg   [11:0] err_cs_offset ;
6374
    reg   [11:0] icr_offset ;
6375
    reg   [11:0] isr_offset ;
6376
    reg   [11:0] lat_tim_cls_offset ;
6377
 
6378
    reg `WRITE_STIM_TYPE  write_data ;
6379
    reg `READ_STIM_TYPE   read_data ;
6380
    reg `READ_RETURN_TYPE read_status ;
6381
 
6382
    reg `WRITE_RETURN_TYPE write_status ;
6383
    reg `WB_TRANSFER_FLAGS write_flags ;
6384
    reg [31:0] temp_val1 ;
6385
    reg [31:0] temp_val2 ;
6386
    reg        ok   ;
6387
 
6388
    reg [31:0] image_base ;
6389
    reg [31:0] target_address ;
6390
    integer i ;
6391
    integer required_reads ;
6392
    integer writes_left ;
6393
 
6394
begin:main
6395
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6396
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6397
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6398
    pci_ctrl_offset    = 12'h4 ;
6399
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6400
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6401
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6402
    lat_tim_cls_offset = 12'hC ;
6403
 
6404
    $display("Checking WB to PCI transaction lengths!") ;
6405
    target_address  = `BEH_TAR1_MEM_START ;
6406
    image_base      = 0 ;
6407
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6408
 
6409
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6410
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6411
    write_flags                    = 0 ;
6412
    write_flags`INIT_WAITS         = tb_init_waits ;
6413
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6414
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6415
 
6416
    // enable master & target operation
6417
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6418
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6419
    if ( ok !== 1 )
6420
    begin
6421
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6422
        test_fail("write to PCI Device Control register failed") ;
6423
        disable main ;
6424
    end
6425
 
6426
    // prepare image control register
6427
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6428
    if ( ok !== 1 )
6429
    begin
6430
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6431
        test_fail("write to WB Image Control register failed") ;
6432
        disable main ;
6433
    end
6434
 
6435
    // prepare base address register
6436
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6437
    if ( ok !== 1 )
6438
    begin
6439
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6440
        test_fail("write to WB Base Address register failed") ;
6441
        disable main ;
6442
    end
6443
 
6444
    // write address mask register
6445
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6446
    if ( ok !== 1 )
6447
    begin
6448
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6449
        test_fail("write to WB Address Mask register failed") ;
6450
        disable main ;
6451
    end
6452
 
6453
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6454
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6455
    if ( ok !== 1 )
6456
    begin
6457
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6458
        test_fail("write to WB Error Control and Status register failed") ;
6459
        disable main ;
6460
    end
6461
 
6462
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6463
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6464
    if ( ok !== 1 )
6465
    begin
6466
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6467
        test_fail("write to Interrupt Control register failed") ;
6468
        disable main ;
6469
    end
6470
 
6471
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6472
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6473
    if ( ok !== 1 )
6474
    begin
6475
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6476
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6477
        disable main ;
6478
    end
6479
 
6480
    $display("Testing single write transaction progress from WB to PCI!") ;
6481
    write_data`WRITE_ADDRESS = target_address ;
6482
    write_data`WRITE_DATA    = wmem_data[0] ;
6483
    write_data`WRITE_SEL     = 4'hF ;
6484
 
6485
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6486
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6487
 
6488
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6489
    fork
6490
    begin
6491
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6492
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6493
        begin
6494
            $display("Transaction progress testing failed! Time %t ", $time) ;
6495
            $display("Bridge failed to process single memory write!") ;
6496
            test_fail("bridge failed to post single memory write") ;
6497
            disable main ;
6498
        end
6499
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6500
    end
6501
    begin
6502
        // wait two retries, then enable target response
6503
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6504
        if ( ok !== 1 )
6505
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6506
        else
6507
            test_ok ;
6508
 
6509
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6510
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6511
        if ( ok !== 1 )
6512
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6513
        else
6514
            test_ok ;
6515
 
6516
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6517
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6518
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6519
 
6520
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6521
        if ( ok !== 1 )
6522
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6523
        else
6524
            test_ok ;
6525
    end
6526
    join
6527
 
6528
    $display("Testing burst write transaction progress from WB to PCI!") ;
6529
    write_data`WRITE_ADDRESS = target_address ;
6530
    write_data`WRITE_DATA    = wmem_data[0] ;
6531
    write_data`WRITE_SEL     = 4'hF ;
6532
 
6533
    wishbone_master.blk_write_data[0] = write_data ;
6534
 
6535
    write_data`WRITE_ADDRESS = target_address + 4 ;
6536
    write_data`WRITE_DATA    = wmem_data[1] ;
6537
    write_data`WRITE_SEL     = 4'hF ;
6538
 
6539
    wishbone_master.blk_write_data[1] = write_data ;
6540
 
6541
    write_flags`WB_TRANSFER_SIZE = 2 ;
6542
    write_flags`WB_TRANSFER_CAB  = 1 ;
6543
 
6544
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6545
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6546
 
6547
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6548
 
6549
    fork
6550
    begin
6551
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6552
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6553
        begin
6554
            $display("Transaction progress testing failed! Time %t ", $time) ;
6555
            $display("Bridge failed to process whole CAB memory write!") ;
6556
            test_fail("bridge failed to post whole CAB memory write") ;
6557
            disable main ;
6558
        end
6559
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6560
    end
6561
    begin
6562
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6563
        if ( ok !== 1 )
6564
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6565
        else
6566
            test_ok ;
6567
 
6568
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6569
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6570
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6571
 
6572
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6573
        if ( ok !== 1 )
6574
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6575
        else
6576
            test_ok ;
6577
 
6578
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6579
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6580
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6581
 
6582
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6583
        if ( ok !== 1 )
6584
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6585
        else
6586
            test_ok ;
6587
    end
6588
    join
6589
 
6590
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6591
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6592
 
6593
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6594
    // try same write with other terminations
6595
    fork
6596
    begin
6597
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6598
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6599
        begin
6600
            $display("Transaction progress testing failed! Time %t ", $time) ;
6601
            $display("Bridge failed to process whole CAB memory write!") ;
6602
            test_fail("bridge failed to post whole CAB memory write") ;
6603
            disable main ;
6604
        end
6605
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6606
    end
6607
    begin
6608
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6609
        if ( ok !== 1 )
6610
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6611
        else
6612
            test_ok ;
6613
 
6614
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6615
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6616
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6617
 
6618
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6619
        if ( ok !== 1 )
6620
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6621
        else
6622
            test_ok ;
6623
    end
6624
    join
6625
 
6626
    // repeat the write with normal completion
6627
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6628
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6629
 
6630
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6631
    fork
6632
    begin
6633
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6634
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6635
        begin
6636
            $display("Transaction progress testing failed! Time %t ", $time) ;
6637
            $display("Bridge failed to process whole CAB memory write!") ;
6638
            test_fail("bridge failed to post whole CAB memory write") ;
6639
            disable main ;
6640
        end
6641
    end
6642
    begin
6643
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6644
        if ( ok !== 1 )
6645
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6646
        else
6647
            test_ok ;
6648
    end
6649
    join
6650
 
6651
    // do the same thing with burst length of 3
6652
    write_data`WRITE_ADDRESS = target_address + 8 ;
6653
    write_data`WRITE_DATA    = wmem_data[2] ;
6654
    write_data`WRITE_SEL     = 4'hF ;
6655
 
6656
    wishbone_master.blk_write_data[2] = write_data ;
6657
 
6658
    write_flags`WB_TRANSFER_SIZE = 3 ;
6659
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6660
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6661
 
6662
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6663
 
6664
    fork
6665
    begin
6666
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6667
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6668
        begin
6669
            $display("Transaction progress testing failed! Time %t ", $time) ;
6670
            $display("Bridge failed to process whole CAB memory write!") ;
6671
            test_fail("bridge failed to post whole CAB memory write") ;
6672
            disable main ;
6673
        end
6674
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6675
    end
6676
    begin
6677
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6678
        if ( ok !== 1 )
6679
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6680
        else
6681
            test_ok ;
6682
 
6683
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6684
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6685
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6686
 
6687
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6688
        if ( ok !== 1 )
6689
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6690
        else
6691
            test_ok ;
6692
    end
6693
    join
6694
 
6695
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6696
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6697
 
6698
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6699
    fork
6700
    begin
6701
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6702
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6703
        begin
6704
            $display("Transaction progress testing failed! Time %t ", $time) ;
6705
            $display("Bridge failed to process whole CAB memory write!") ;
6706
            test_fail("bridge failed to post whole CAB memory write") ;
6707
            disable main ;
6708
        end
6709
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6710
    end
6711
    begin
6712
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6713
        if ( ok !== 1 )
6714
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6715
        else
6716
            test_ok ;
6717
 
6718
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6719
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6720
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6721
 
6722
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6723
        if ( ok !== 1 )
6724
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6725
        else
6726
            test_ok ;
6727
 
6728
    end
6729
    join
6730
 
6731
    // repeat with normal completion
6732
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6733
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6734
 
6735
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6736
    fork
6737
    begin
6738
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6739
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6740
        begin
6741
            $display("Transaction progress testing failed! Time %t ", $time) ;
6742
            $display("Bridge failed to process whole CAB memory write!") ;
6743
            test_fail("bridge failed to post whole CAB memory write") ;
6744
            disable main ;
6745
        end
6746
    end
6747
    begin
6748
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6749
        if ( ok !== 1 )
6750
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6751
        else
6752
            test_ok ;
6753
 
6754
    end
6755
    join
6756
 
6757
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6758
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6759
    begin
6760
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6761
        write_data`WRITE_DATA    = wmem_data[i] ;
6762
        write_data`WRITE_SEL     = 4'hF ;
6763
 
6764
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6765
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6766
 
6767
        wishbone_master.blk_write_data[i]   = write_data ;
6768
        wishbone_master.blk_read_data_in[i] = read_data ;
6769
    end
6770
 
6771
    write_flags`WB_TRANSFER_CAB      = 1 ;
6772
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6773
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6774
 
6775
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6776
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6777
 
6778
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6779
    fork
6780
    begin
6781
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6782
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6783
        begin
6784
            $display("Transaction progress testing failed! Time %t ", $time) ;
6785
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6786
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6787
            test_fail("bridge failed to post whole CAB memory write") ;
6788
            disable main ;
6789
        end
6790
 
6791
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6792
 
6793
        // read here just checks if data was transfered OK
6794
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6795
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6796
 
6797
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6798
 
6799
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6800
        begin
6801
            $display("Transaction progress testing failed! Time %t ", $time) ;
6802
            $display("Bridge processed CAB read wrong!") ;
6803
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6804
        end
6805
 
6806
    end
6807
    begin
6808
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6809
        if ( ok !== 1 )
6810
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6811
        else
6812
            test_ok ;
6813
 
6814
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6815
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6816
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6817
 
6818
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6819
        if ( ok !== 1 )
6820
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6821
        else
6822
            test_ok ;
6823
 
6824
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6825
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6826
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6827
 
6828
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6829
        if ( ok !== 1 )
6830
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6831
        else
6832
            test_ok ;
6833
 
6834
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6835
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6836
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6837
 
6838
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6839
        if ( ok !== 1 )
6840
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6841
        else
6842
            test_ok ;
6843
 
6844
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6845
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6846
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6847
 
6848
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6849
        if ( ok !== 1 )
6850
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6851
        else
6852
            test_ok ;
6853
 
6854
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6855
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6856
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6857
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6858
        begin
6859
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6860
            if ( ok !== 1 )
6861
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6862
        end
6863
    end
6864
    join
6865
 
6866
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6867
    begin
6868
        read_status = wishbone_master.blk_read_data_out[i] ;
6869
        if (read_status`READ_DATA !== wmem_data[i])
6870
        begin
6871
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6872
            test_fail("data read from target wasn't the same as data written to it") ;
6873
            ok = 0 ;
6874
        end
6875
    end
6876
 
6877
    if ( ok )
6878
        test_ok ;
6879
 
6880
    $display("Testing single read transaction progress from WB to PCI!") ;
6881
    read_data`READ_ADDRESS = target_address + 8 ;
6882
    read_data`READ_SEL     = 4'hF ;
6883
 
6884
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6885
 
6886
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6887
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6888
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6889
 
6890
    fork
6891
    begin
6892
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6893
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6894
        begin
6895
            $display("Transaction progress testing failed! Time %t ", $time) ;
6896
            $display("Bridge processed single read wrong!") ;
6897
            test_fail("bridge processed single read wrong") ;
6898
            disable main ;
6899
        end
6900
 
6901
        if (read_status`READ_DATA !== wmem_data[2])
6902
        begin
6903
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6904
            test_fail("data returned from single read was not as expected") ;
6905
        end
6906
        else
6907
        if ( ok )
6908
            test_ok ;
6909
    end
6910
    begin
6911
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
6912
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6913
 
6914
        if ( ok !== 1 )
6915
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6916
 
6917
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
6918
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6919
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6920
 
6921
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6922
        if ( ok !== 1 )
6923
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6924
    end
6925
    join
6926
 
6927
    $display("Testing CAB read transaction progress from WB to PCI!") ;
6928
 
6929
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6930
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6931
 
6932
    test_name = "FILL TARGET MEMORY WITH DATA" ;
6933
    // first fill target's memory with enough data to fill WBR_FIFO
6934
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
6935
    begin
6936
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6937
        write_data`WRITE_DATA    = wmem_data[i] ;
6938
        write_data`WRITE_SEL     = 4'hF ;
6939
 
6940
        wishbone_master.blk_write_data[i] = write_data ;
6941
    end
6942
 
6943
    write_flags`WB_TRANSFER_CAB = 1 ;
6944
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6945
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
6946
 
6947
    wishbone_master.wb_block_write( write_flags, write_status ) ;
6948
 
6949
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
6950
    begin
6951
        $display("Transaction progress testing failed! Time %t ", $time) ;
6952
        $display("Bridge processed CAB write wrong!") ;
6953
        test_fail("bridge didn't process all the writes as it was supposed too") ;
6954
        disable main ;
6955
    end
6956
 
6957
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
6958
    // perform single read to force write data to pci
6959
    read_data`READ_ADDRESS = target_address + 8;
6960
    read_data`READ_SEL     = 4'hF ;
6961
 
6962
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6963
 
6964
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6965
    begin
6966
        $display("Transaction progress testing failed! Time %t ", $time) ;
6967
        $display("Bridge processed single read wrong!") ;
6968
        test_fail("bridge didn't process single memory read as expected") ;
6969
        disable main ;
6970
    end
6971
 
6972
    wishbone_master.blk_read_data_in[0] = read_data ;
6973
 
6974
    read_data`READ_ADDRESS = target_address + 12 ;
6975
    read_data`READ_SEL     = 4'hF ;
6976
 
6977
    wishbone_master.blk_read_data_in[1] = read_data ;
6978
 
6979
    read_data`READ_ADDRESS = target_address + 16 ;
6980
    read_data`READ_SEL     = 4'hF ;
6981
 
6982
    wishbone_master.blk_read_data_in[2] = read_data ;
6983
 
6984
    write_flags`WB_TRANSFER_CAB  = 1 ;
6985
    write_flags`WB_TRANSFER_SIZE = 2 ;
6986
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6987
    read_status = 0 ;
6988
 
6989
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6990
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6991
 
6992
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
6993
 
6994
    ok = 1 ;
6995
    fork
6996
    begin
6997
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
6998
            wishbone_master.wb_block_read( write_flags, read_status ) ;
6999
 
7000
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7001
        begin
7002
            $display("Transaction progress testing failed! Time %t ", $time) ;
7003
            $display("Bridge processed CAB read wrong!") ;
7004
            test_fail("bridge didn't process disconnected burst read as expected") ;
7005
        end
7006
        else
7007
        begin
7008
 
7009
            read_status = wishbone_master.blk_read_data_out[0] ;
7010
 
7011
            if (read_status`READ_DATA !== wmem_data[2])
7012
            begin
7013
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7014
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7015
            end
7016
            else
7017
                test_ok ;
7018
        end
7019
 
7020
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7021
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7022
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7023
 
7024
        read_status = 0 ;
7025
 
7026
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7027
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7028
 
7029
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7030
        begin
7031
            $display("Transaction progress testing failed! Time %t ", $time) ;
7032
            $display("Bridge processed CAB read wrong!") ;
7033
            test_fail("bridge didn't process disconnected burst read as expected") ;
7034
        end
7035
        else
7036
        begin
7037
 
7038
            read_status = wishbone_master.blk_read_data_out[0] ;
7039
 
7040
            if (read_status`READ_DATA !== wmem_data[3])
7041
            begin
7042
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7043
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7044
            end
7045
            else
7046
                test_ok ;
7047
        end
7048
 
7049
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7050
        // complete delayed read which was requested
7051
        read_data = wishbone_master.blk_read_data_in[2] ;
7052
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7053
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7054
 
7055
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7056
        begin
7057
            $display("Transaction progress testing failed! Time %t ", $time) ;
7058
            $display("Bridge processed single out of burst read wrong!") ;
7059
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7060
        end
7061
        else
7062
        begin
7063
 
7064
            if (read_status`READ_DATA !== wmem_data[4])
7065
            begin
7066
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7067
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7068
            end
7069
            else
7070
                test_ok ;
7071
        end
7072
 
7073
    end
7074
    begin
7075
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7076
 
7077
        if ( ok !== 1 )
7078
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7079
 
7080
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7081
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7082
 
7083
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7084
        if ( ok !== 1 )
7085
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7086
 
7087
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7088
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7089
 
7090
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7091
        if ( ok !== 1 )
7092
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7093
    end
7094
    join
7095
 
7096
    // now try burst read with normal termination
7097
    read_data`READ_ADDRESS = target_address + 12 ;
7098
    read_data`READ_SEL     = 4'hF ;
7099
 
7100
    wishbone_master.blk_read_data_in[0] = read_data ;
7101
 
7102
    read_data`READ_ADDRESS = target_address + 16 ;
7103
    read_data`READ_SEL     = 4'hF ;
7104
 
7105
    wishbone_master.blk_read_data_in[1] = read_data ;
7106
 
7107
    write_flags`WB_TRANSFER_SIZE = 2 ;
7108
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7109
    write_flags`WB_TRANSFER_CAB = 1 ;
7110
 
7111
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7112
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7113
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7114
 
7115
    fork
7116
    begin
7117
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7118
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7119
        begin
7120
            $display("Transaction progress testing failed! Time %t ", $time) ;
7121
            $display("Bridge processed CAB read wrong!") ;
7122
            test_fail("bridge didn't process burst read as expected") ;
7123
            ok = 0 ;
7124
        end
7125
    end
7126
    begin
7127
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7128
        if ( ok !== 1 )
7129
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7130
    end
7131
    join
7132
 
7133
    if ( ok )
7134
    begin
7135
        read_status = wishbone_master.blk_read_data_out[0] ;
7136
        if ( read_status`READ_DATA !== wmem_data[3] )
7137
        begin
7138
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7139
            test_fail("data provided from normaly terminated read was wrong") ;
7140
            ok = 0 ;
7141
        end
7142
 
7143
        read_status = wishbone_master.blk_read_data_out[1] ;
7144
        if ( read_status`READ_DATA !== wmem_data[4] )
7145
        begin
7146
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7147
            test_fail("data provided from normaly terminated read was wrong") ;
7148
            ok = 0 ;
7149
        end
7150
    end
7151
 
7152
    if ( ok )
7153
        test_ok ;
7154
 
7155
    // disable memory read line command and enable prefetch
7156
    // prepare image control register
7157
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7158
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7159
    if ( ok !== 1 )
7160
    begin
7161
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7162
        test_fail("WB Image Control register couldn't be written to") ;
7163
        disable main ;
7164
    end
7165
 
7166
    write_flags`WB_TRANSFER_SIZE = 4 ;
7167
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7168
    write_flags`WB_TRANSFER_CAB = 1 ;
7169
 
7170
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7171
 
7172
    for ( i = 0 ; i < 4 ; i = i + 1 )
7173
    begin
7174
        read_data`READ_ADDRESS = target_address + i*4 ;
7175
        read_data`READ_SEL     = 4'b1010 ;
7176
 
7177
        wishbone_master.blk_read_data_in[i] = read_data ;
7178
    end
7179
 
7180
    fork
7181
    begin
7182
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7183
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7184
        begin
7185
            $display("Transaction progress testing failed! Time %t ", $time) ;
7186
            $display("Bridge processed CAB read wrong!") ;
7187
            test_fail("bridge didn't process prefetched burst read as expected") ;
7188
            ok = 0 ;
7189
        end
7190
    end
7191
    begin
7192
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7193
        if ( ok !== 1 )
7194
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7195
    end
7196
    join
7197
 
7198
    if ( ok )
7199
    begin
7200
        for ( i = 0 ; i < 4 ; i = i + 1 )
7201
        begin
7202
            read_status = wishbone_master.blk_read_data_out[i] ;
7203
            if ( read_status`READ_DATA !== wmem_data[i] )
7204
            begin
7205
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7206
                test_fail("burst read returned unexpected data") ;
7207
                ok = 0 ;
7208
            end
7209
        end
7210
    end
7211
 
7212
    if ( ok )
7213
        test_ok ;
7214
 
7215
    // do one single read with different byte enables
7216
    read_data`READ_ADDRESS = target_address + 4 ;
7217
    read_data`READ_SEL     = 4'b1010 ;
7218
 
7219
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7220
    fork
7221
    begin
7222
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7223
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7224
        begin
7225
            $display("Transaction progress testing failed! Time %t ", $time) ;
7226
            $display("Bridge processed single read wrong!") ;
7227
            test_fail("bridge didn't process single memory read as expected") ;
7228
            ok = 0 ;
7229
        end
7230
    end
7231
    begin
7232
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7233
        if ( ok !== 1 )
7234
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7235
    end
7236
    join
7237
 
7238
    // check read data
7239
    if ( ok )
7240
    begin
7241
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7242
        begin
7243
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7244
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7245
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7246
            ok = 0 ;
7247
            test_fail("unexpected data received from single read") ;
7248
        end
7249
    end
7250
 
7251
    if ( ok )
7252
         test_ok ;
7253
 
7254
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7255
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7256
 
7257
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7258
    if ( ok !== 1 )
7259
    begin
7260
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7261
        test_fail("WB Image Control register could not be written") ;
7262
        disable main ;
7263
    end
7264
 
7265
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7266
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7267
    begin
7268
        read_data`READ_ADDRESS = target_address + i*4 ;
7269
        read_data`READ_SEL     = 4'b1111 ;
7270
 
7271
        wishbone_master.blk_read_data_in[i] = read_data ;
7272
    end
7273
 
7274
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7275
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7276
    write_flags`WB_TRANSFER_CAB = 1 ;
7277
 
7278
    fork
7279
    begin
7280
        read_status         = 0 ;
7281
        read_status`CYC_RTY = 1 ;
7282
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7283
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7284
 
7285
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7286
        begin
7287
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7288
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7289
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7290
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7291
            ok = 0 ;
7292
        end
7293
    end
7294
    begin
7295
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7296
        if ( ok !== 1 )
7297
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7298
    end
7299
    join
7300
 
7301
    // now repeat single read to flush redundant read initiated
7302
    write_flags`WB_TRANSFER_SIZE = 1 ;
7303
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7304
    write_flags`WB_TRANSFER_CAB = 1 ;
7305
 
7306
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7307
    read_data`READ_SEL     = 4'hF ;
7308
 
7309
    wishbone_master.blk_read_data_in[0] = read_data ;
7310
 
7311
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7312
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7313
 
7314
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7315
    begin
7316
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7317
        $display(" PCI bridge failed to process single CAB read!") ;
7318
        test_fail("single CAB write was not processed as expected") ;
7319
    end
7320
 
7321
    // because last read could be very long on PCI - delete target abort status
7322
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7323
 
7324
    // write unsupported value to cache line size register
7325
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7326
 
7327
    read_data`READ_ADDRESS = target_address ;
7328
    read_data`READ_SEL     = 4'hF ;
7329
    wishbone_master.blk_read_data_in[0] = read_data ;
7330
 
7331
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7332
    // perform a read
7333
    fork
7334
    begin
7335
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7336
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7337
        begin
7338
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7339
            $display(" PCI bridge failed to process single CAB read!") ;
7340
            test_fail("burst read was not processed as expected") ;
7341
            ok = 0 ;
7342
        end
7343
    end
7344
    begin
7345
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7346
        if ( ok !== 1 )
7347
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7348
    end
7349
    join
7350
 
7351
    if ( ok )
7352
        test_ok ;
7353
 
7354
    // write 2 to cache line size register
7355
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7356
 
7357
    // perform a read
7358
    fork
7359
    begin
7360
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7361
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7362
        begin
7363
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7364
            $display(" PCI bridge failed to process single CAB read!") ;
7365
            test_fail("burst read was not processed as expected") ;
7366
            ok = 0 ;
7367
        end
7368
    end
7369
    begin
7370
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7371
        if ( ok !== 1 )
7372
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7373
    end
7374
    join
7375
 
7376
    if ( ok )
7377
        test_ok ;
7378
 
7379
    // write 0 to cache line size
7380
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7381
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7382
 
7383
    // perform a read
7384
    fork
7385
    begin
7386
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7387
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7388
        begin
7389
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7390
            $display(" PCI bridge failed to process single CAB read!") ;
7391
            test_fail("burst read was not processed as expected") ;
7392
            ok = 0 ;
7393
        end
7394
    end
7395
    begin
7396
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7397
        if ( ok !== 1 )
7398
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7399
    end
7400
    join
7401
 
7402
    if ( ok )
7403
        test_ok ;
7404
 
7405
    // write normal value to cls register
7406
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7407
 
7408
    $display("Testing Master's latency timer operation!") ;
7409
    $display("Testing Latency timer during Master Writes!") ;
7410
 
7411
    for ( i = 0 ; i < 6 ; i = i + 1 )
7412
    begin
7413
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7414
        write_data`WRITE_SEL     = 4'b1111 ;
7415
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7416
 
7417
        wishbone_master.blk_write_data[i] = write_data ;
7418
    end
7419
 
7420
    write_flags`WB_TRANSFER_SIZE = 6 ;
7421
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7422
    write_flags`WB_TRANSFER_CAB = 1 ;
7423
 
7424
    // start wb write, pci write and monitor in parallel
7425
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7426
    fork
7427
    begin
7428
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7429
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7430
        begin
7431
            $display("Transaction progress testing failed! Time %t ", $time) ;
7432
            $display("Bridge failed to process CAB write!") ;
7433
            test_fail("bridge didn't post whole burst memory write") ;
7434
            disable main ;
7435
        end
7436
    end
7437
    begin
7438
        // wait for bridge's master to start transaction
7439
        @(posedge pci_clock) ;
7440
        while ( FRAME === 1 )
7441
            @(posedge pci_clock) ;
7442
 
7443
        // start behavioral master request
7444
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7445
               target_address, wmem_data[1023], `Test_All_Bytes,
7446
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7447
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7448
 
7449
        do_pause ( 1 ) ;
7450
    end
7451
    begin
7452
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7453
        if ( ok !== 1 )
7454
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7455
        else
7456
            test_ok ;
7457
    end
7458
    join
7459
 
7460
    // perform a read to check data
7461
    for ( i = 0 ; i < 6 ; i = i + 1 )
7462
    begin
7463
        read_data`READ_ADDRESS = target_address + i*4 ;
7464
        read_data`READ_SEL     = 4'b1111 ;
7465
 
7466
        wishbone_master.blk_read_data_in[i] = read_data ;
7467
    end
7468
 
7469
    write_flags`WB_TRANSFER_SIZE = 6 ;
7470
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7471
    write_flags`WB_TRANSFER_CAB = 1 ;
7472
 
7473
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7474
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7475
 
7476
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7477
    begin
7478
        $display("Transaction progress testing failed! Time %t ", $time) ;
7479
        $display("Bridge failed to process CAB read!") ;
7480
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7481
        disable main ;
7482
    end
7483
 
7484
    ok = 1 ;
7485
    for ( i = 0 ; i < 6 ; i = i + 1 )
7486
    begin
7487
        read_status = wishbone_master.blk_read_data_out[i] ;
7488
 
7489
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7490
        begin
7491
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7492
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7493
            test_fail("unexpected data read back from PCI") ;
7494
            ok = 0 ;
7495
        end
7496
    end
7497
 
7498
    if ( ok )
7499
        test_ok ;
7500
 
7501
    $display("Testing Latency timer during Master Reads!") ;
7502
 
7503
    // at least 2 words are transfered during Master Reads terminated with timeout
7504
    write_flags`WB_TRANSFER_SIZE = 2 ;
7505
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7506
    fork
7507
    begin
7508
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7509
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7510
        begin
7511
            $display("Transaction progress testing failed! Time %t ", $time) ;
7512
            $display("Bridge failed to process CAB read!") ;
7513
            test_fail("bridge didn't process burst read as expected") ;
7514
            ok = 0 ;
7515
        end
7516
    end
7517
    begin
7518
        // wait for bridge's master to start transaction
7519
        @(posedge pci_clock) ;
7520
        while ( FRAME === 1 )
7521
            @(posedge pci_clock) ;
7522
 
7523
        // start behavioral master request
7524
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7525
               target_address, wmem_data[0], `Test_All_Bytes,
7526
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7527
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7528
 
7529
        do_pause ( 1 ) ;
7530
    end
7531
    begin
7532
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7533
        if ( ok !== 1 )
7534
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7535
    end
7536
    join
7537
 
7538
    // check data provided by target
7539
    if ( ok )
7540
    begin
7541
        for ( i = 0 ; i < 2 ; i = i + 1 )
7542
        begin
7543
            read_status = wishbone_master.blk_read_data_out[i] ;
7544
 
7545
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7546
            begin
7547
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7548
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7549
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7550
                ok = 0 ;
7551
            end
7552
        end
7553
    end
7554
    if ( ok )
7555
        test_ok ;
7556
 
7557
    test_name = "DISABLE_IMAGE" ;
7558
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7559
    if ( ok !== 1 )
7560
    begin
7561
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7562
        test_fail("write to WB Address Mask register failed") ;
7563
        disable main ;
7564
    end
7565
 
7566
end
7567
endtask //wb_to_pci_transactions
7568
 
7569
task iack_cycle ;
7570
    reg `READ_STIM_TYPE   read_data ;
7571
    reg `READ_RETURN_TYPE read_status ;
7572
    reg `WB_TRANSFER_FLAGS flags ;
7573
 
7574
    reg [31:0] temp_var ;
7575
    reg ok ;
7576
begin
7577
 
7578
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7579
 
7580
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7581
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7582
 
7583
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7584
    read_data`READ_SEL     = 4'hF ;
7585
 
7586
    flags = 0 ;
7587
 
7588
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7589
 
7590
    irq_respond = 0 ;
7591
    irq_vector  = 32'hAAAA_AAAA ;
7592
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7593
 
7594
    fork
7595
    begin
7596
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7597
    end
7598
    begin
7599
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok) ;
7600
        if ( ok !== 1 )
7601
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7602
    end
7603
    join
7604
 
7605
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7606
    begin
7607
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7608
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7609
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7610
    end
7611
    else
7612
    if ( ok )
7613
        test_ok ;
7614
        // clearing the status bits
7615
        config_write(12'h4, 32'hFFFF_0000, 4'hC, ok);
7616
 
7617
    irq_respond = 1 ;
7618
    irq_vector  = 32'h5555_5555 ;
7619
 
7620
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7621
    fork
7622
    begin
7623
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7624
    end
7625
    begin
7626
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7627
        if ( ok !== 1 )
7628
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7629
    end
7630
    join
7631
 
7632
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7633
    begin
7634
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7635
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7636
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7637
        ok = 0 ;
7638
    end
7639
 
7640
    if ( read_status`READ_DATA !== irq_vector )
7641
    begin
7642
        $display(" Time %t ", $time ) ;
7643
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7644
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7645
        ok = 0 ;
7646
    end
7647
 
7648
    if ( ok )
7649
        test_ok ;
7650
 
7651
    read_data`READ_SEL = 4'b0101 ;
7652
    irq_vector  = 32'hAAAA_AAAA ;
7653
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7654
    fork
7655
    begin
7656
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7657
    end
7658
    begin
7659
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok) ;
7660
        if ( ok !== 1 )
7661
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7662
    end
7663
    join
7664
 
7665
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7666
    begin
7667
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7668
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7669
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7670
        ok = 0 ;
7671
    end
7672
 
7673
    if ( read_status`READ_DATA !== 32'h00AA_00AA )
7674
    begin
7675
        $display(" Time %t ", $time ) ;
7676
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h00AA_00AA, read_status`READ_DATA ) ;
7677
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7678
        ok = 0 ;
7679
    end
7680
 
7681
    if ( ok )
7682
        test_ok ;
7683
 
7684
 
7685
end
7686
endtask //iack_cycle
7687
 
7688
task transaction_ordering ;
7689
    reg   [11:0] wb_ctrl_offset ;
7690
    reg   [11:0] wb_ba_offset ;
7691
    reg   [11:0] wb_am_offset ;
7692
    reg   [11:0] pci_ctrl_offset ;
7693
    reg   [11:0] pci_ba_offset ;
7694
    reg   [11:0] pci_am_offset ;
7695
    reg   [11:0] pci_device_ctrl_offset ;
7696
    reg   [11:0] wb_err_cs_offset ;
7697
    reg   [11:0] pci_err_cs_offset ;
7698
    reg   [11:0] icr_offset ;
7699
    reg   [11:0] isr_offset ;
7700
    reg   [11:0] lat_tim_cls_offset ;
7701
 
7702
    reg `WRITE_STIM_TYPE  write_data ;
7703
    reg `READ_STIM_TYPE   read_data ;
7704
    reg `READ_RETURN_TYPE read_status ;
7705
 
7706
    reg `WRITE_RETURN_TYPE write_status ;
7707
    reg `WB_TRANSFER_FLAGS write_flags ;
7708
    reg [31:0] temp_val1 ;
7709
    reg [31:0] temp_val2 ;
7710
    reg        ok   ;
7711
 
7712
    reg [31:0] wb_image_base ;
7713
    reg [31:0] wb_target_address ;
7714
    reg [31:0] pci_image_base ;
7715
    integer i ;
7716
 
7717
    reg     error_monitor_done ;
7718
begin:main
7719
    write_flags`INIT_WAITS = tb_init_waits ;
7720
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7721
 
7722
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7723
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7724
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7725
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7726
 
7727
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7728
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7729
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7730
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7731
 
7732
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7733
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7734
    lat_tim_cls_offset = 12'hC ;
7735
    pci_device_ctrl_offset    = 12'h4 ;
7736
 
7737
    wb_target_address  = `BEH_TAR1_MEM_START ;
7738
    wb_image_base      = 0 ;
7739
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7740
 
7741
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7742
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7743
    write_flags                    = 0 ;
7744
    write_flags`INIT_WAITS         = 0 ;
7745
    write_flags`SUBSEQ_WAITS       = 0 ;
7746
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7747
 
7748
    pci_image_base = Target_Base_Addr_R[1] ;
7749
 
7750
    // enable master & target operation
7751
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7752
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7753
    if ( ok !== 1 )
7754
    begin
7755
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7756
        test_fail("write to PCI Device Control register failed") ;
7757
        disable main ;
7758
    end
7759
 
7760
    // prepare image control register
7761
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7762
    if ( ok !== 1 )
7763
    begin
7764
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7765
        test_fail("write to WB Image Control register failed") ;
7766
        disable main ;
7767
    end
7768
 
7769
    // prepare base address register
7770
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7771
    if ( ok !== 1 )
7772
    begin
7773
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7774
        test_fail("write to WB Base Address register failed") ;
7775
        disable main ;
7776
    end
7777
 
7778
    // write address mask register
7779
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7780
    if ( ok !== 1 )
7781
    begin
7782
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7783
        test_fail("write to WB Address Mask register failed") ;
7784
        disable main ;
7785
    end
7786
 
7787
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7788
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7789
    if ( ok !== 1 )
7790
    begin
7791
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
7792
        test_fail("write to WB Error Control and Status register failed") ;
7793
        disable main ;
7794
    end
7795
 
7796
    // prepare image control register
7797
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7798
    if ( ok !== 1 )
7799
    begin
7800
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
7801
        test_fail("write to PCI Image Control register failed") ;
7802
        disable main ;
7803
    end
7804
 
7805
    // prepare base address register
7806
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
7807
    if ( ok !== 1 )
7808
    begin
7809
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
7810
        test_fail("write to PCI Base Address register failed") ;
7811
        disable main ;
7812
    end
7813
 
7814
    // write address mask register
7815
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7816
    if ( ok !== 1 )
7817
    begin
7818
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
7819
        test_fail("write to PCI Address Mask register failed") ;
7820
        disable main ;
7821
    end
7822
 
7823
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7824
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7825
    if ( ok !== 1 )
7826
    begin
7827
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
7828
        test_fail("write to PCI Error Control and Status register failed") ;
7829
        disable main ;
7830
    end
7831
 
7832
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
7833
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7834
    if ( ok !== 1 )
7835
    begin
7836
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
7837
        test_fail("write to Interrupt Control register failed") ;
7838
        disable main ;
7839
    end
7840
 
7841
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
7842
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
7843
    if ( ok !== 1 )
7844
    begin
7845
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
7846
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
7847
        disable main ;
7848
    end
7849
 
7850
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
7851
 
7852
    // prepare wb_master write and read data
7853
    for ( i = 0 ; i < 4 ; i = i + 1 )
7854
    begin
7855
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
7856
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
7857
        write_data`WRITE_SEL     = 4'hF ;
7858
 
7859
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
7860
        read_data`READ_SEL       = write_data`WRITE_SEL ;
7861
 
7862
        wishbone_master.blk_write_data[i]   = write_data ;
7863
        wishbone_master.blk_read_data_in[i] = read_data ;
7864
    end
7865
 
7866
    // put wishbone slave in acknowledge and pci target in retry mode
7867
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
7868
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7869
 
7870
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7871
 
7872
    fork
7873
    begin
7874
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7875
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7876
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7877
        begin
7878
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7879
            test_fail("Bridge didn't post single memory write as expected") ;
7880
        end
7881
 
7882
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7883
        if ( ok !== 1 )
7884
        begin
7885
            $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) ;
7886
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7887
            ok = 0 ;
7888
        end
7889
 
7890
        // now post single write to target - normal progress
7891
        if ( target_mem_image == 1 )
7892
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7893
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7894
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7895
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7896
        else
7897
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7898
 
7899
        do_pause( 1 ) ;
7900
 
7901
    end
7902
    begin:error_monitor_1
7903
        @(error_event_int) ;
7904
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7905
        ok = 0 ;
7906
    end
7907
    begin
7908
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7909
        if ( ok !== 1 )
7910
        begin
7911
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7912
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7913
        end
7914
        else
7915
        begin
7916 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7917
//            while ( FRAME === 0 || IRDY === 0 )
7918
//                @(posedge pci_clock) ;
7919 15 mihad
 
7920
            // enable response in PCI target
7921
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
7922
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7923
 
7924
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7925
            if ( ok !== 1 )
7926
            begin
7927
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
7928
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
7929
            end
7930
        end
7931
 
7932
        disable error_monitor_1 ;
7933
    end
7934
    join
7935
 
7936
    if ( ok )
7937
        test_ok ;
7938
 
7939
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
7940
 
7941
    // put WISHBONE slave in retry mode
7942
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
7943
 
7944
    fork
7945
    begin
7946
        // now post single write to target - normal progress
7947
        if ( target_mem_image == 1 )
7948
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
7949
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
7950
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
7951
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7952
        else
7953
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
7954
 
7955
        do_pause( 1 ) ;
7956
 
7957
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
7958
        if ( ok !== 1 )
7959
        begin
7960
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
7961
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
7962
        end
7963
 
7964
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7965
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
7966
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
7967
        begin
7968
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
7969
            test_fail("Bridge didn't post single memory write as expected") ;
7970
        end
7971
 
7972
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
7973
        if ( ok !== 1 )
7974
        begin
7975
            $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) ;
7976
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
7977
            ok = 0 ;
7978
        end
7979
 
7980
        wait ( CYC_O === 0 ) ;
7981
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
7982
 
7983
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
7984
        if ( ok !== 1 )
7985
        begin
7986
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
7987
            test_fail("WB Master didn't start expected transaction on WB bus") ;
7988
        end
7989
 
7990
        disable error_monitor_2 ;
7991
    end
7992
    begin:error_monitor_2
7993
        @(error_event_int) ;
7994
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
7995
        ok = 0 ;
7996
    end
7997
    join
7998
 
7999
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8000
 
8001
    // put wishbone slave in acknowledge and pci target in retry mode
8002
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8003
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8004
 
8005
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8006
 
8007
    fork
8008
    begin
8009
        write_flags`WB_TRANSFER_SIZE = 3 ;
8010
        write_flags`WB_TRANSFER_CAB  = 1 ;
8011
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8012
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8013
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8014
        begin
8015
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8016
            test_fail("Bridge didn't post burst memory write as expected") ;
8017
        end
8018
 
8019
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8020
        if ( ok !== 1 )
8021
        begin
8022
            $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) ;
8023
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8024
            ok = 0 ;
8025
        end
8026
 
8027
        // now post single write to target - normal progress
8028
        if ( target_mem_image == 1 )
8029
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8030
                        pci_image_base, 32'h5555_5555, 4'h0,
8031
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8032
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8033
        else
8034
        begin
8035
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8036
            do_pause( 1 ) ;
8037
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8038
        end
8039
 
8040
        do_pause( 1 ) ;
8041
 
8042
    end
8043
    begin:error_monitor_3
8044
        @(error_event_int) ;
8045
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8046
        ok = 0 ;
8047
    end
8048
    begin
8049
        if ( target_mem_image == 1 )
8050
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8051
        else
8052
        begin
8053
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8054
            if ( ok )
8055
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8056
        end
8057
 
8058
        if ( ok !== 1 )
8059
        begin
8060
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8061
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8062
        end
8063
        else
8064
        begin
8065 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8066
//            while ( FRAME === 0 || IRDY === 0 )
8067
//                @(posedge pci_clock) ;
8068 15 mihad
 
8069
            // enable response in PCI target
8070
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8071
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8072
 
8073
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8074
            if ( ok !== 1 )
8075
            begin
8076
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8077
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8078
            end
8079
        end
8080
 
8081
        disable error_monitor_3 ;
8082
    end
8083
    join
8084
 
8085
    if ( ok )
8086
        test_ok ;
8087
 
8088
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8089
 
8090
    // put WISHBONE slave in retry mode
8091
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8092
 
8093
    fork
8094
    begin
8095
        // now post single write to target - normal progress
8096
        if ( target_mem_image == 1 )
8097
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8098
                        pci_image_base, 32'h5555_5555, 4'h0,
8099
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8100
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8101
        else
8102
        begin
8103
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8104
            do_pause( 1 ) ;
8105
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8106
        end
8107
 
8108
        do_pause( 1 ) ;
8109
 
8110
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8111
 
8112
        if ( ok !== 1 )
8113
        begin
8114
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8115
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8116
        end
8117
 
8118
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8119
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8120
        write_flags`WB_TRANSFER_CAB      = 1 ;
8121
 
8122
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8123
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8124
        begin
8125
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8126
            test_fail("Bridge didn't post burst memory write as expected") ;
8127
        end
8128
 
8129
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8130
        if ( ok !== 1 )
8131
        begin
8132
            $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) ;
8133
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8134
            ok = 0 ;
8135
        end
8136
 
8137
        @(posedge wb_clock) ;
8138
        while ( CYC_O === 1 )
8139
            @(posedge wb_clock) ;
8140
 
8141
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8142
 
8143
        if ( target_mem_image == 1 )
8144
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8145
        else
8146
        begin
8147
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8148
            if ( ok )
8149
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8150
        end
8151
 
8152
 
8153
        disable error_monitor_4 ;
8154
    end
8155
    begin:error_monitor_4
8156
        @(error_event_int) ;
8157
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8158
        ok = 0 ;
8159
    end
8160
    join
8161
 
8162
    if ( ok )
8163
        test_ok ;
8164
 
8165
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8166
 
8167
    // put wishbone slave in acknowledge and pci target in retry mode
8168
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8169
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8170
 
8171
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8172
 
8173
    master1_check_received_data = 1 ;
8174
 
8175
    error_monitor_done = 0 ;
8176
    fork
8177
    begin:error_monitor_5
8178
        @(error_event_int or error_monitor_done) ;
8179
        if ( !error_monitor_done )
8180
        begin
8181
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8182
            ok = 0 ;
8183
        end
8184
    end
8185
    begin
8186
 
8187
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8188
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8189
        begin
8190
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8191
            test_fail("Bridge didn't post single memory write as expected") ;
8192
        end
8193
 
8194
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8195
        if ( ok !== 1 )
8196
        begin
8197
            $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) ;
8198
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8199
            ok = 0 ;
8200
        end
8201
 
8202
        // start Read Through pci target
8203
        if ( target_mem_image == 1 )
8204
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8205
                          pci_image_base, 32'h5555_5555,
8206
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8207
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8208
        else
8209
            PCIU_IO_READ
8210
             (
8211
                `Test_Master_1,
8212
                pci_image_base,
8213
                32'h5555_5555,
8214
                4'h0,
8215
                1,
8216
                `Test_Target_Retry_On
8217
             );
8218
 
8219
         do_pause( 1 ) ;
8220
 
8221
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8222
         if ( ok !== 1 )
8223
         begin
8224
            $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) ;
8225
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8226
         end
8227
 
8228
         // repeat the read 4 times - it should be retried all the time by pci target
8229
        for ( i = 0 ; i < 4 ; i = i + 1 )
8230
        begin
8231
            if ( target_mem_image == 1 )
8232
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8233
                            pci_image_base, 32'h5555_5555,
8234
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8235
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8236
            else
8237
                PCIU_IO_READ
8238
                (
8239
                    `Test_Master_1,
8240
                    pci_image_base,
8241
                    32'h5555_5555,
8242
                    4'h0,
8243
                    1,
8244
                    `Test_Target_Retry_On
8245
                );
8246
 
8247
            do_pause( 1 ) ;
8248
        end
8249
 
8250
        // now do posted write through target - it must go through OK
8251
        if ( target_mem_image == 1 )
8252
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8253
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8254
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8255
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8256
        else
8257
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8258
 
8259
        do_pause( 1 ) ;
8260
 
8261
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8262
        if ( ok !== 1 )
8263
        begin
8264
           $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) ;
8265
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8266
        end
8267
 
8268
        // start a read through wb_slave
8269
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8270
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8271
        begin
8272
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8273
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8274
            ok = 0 ;
8275
        end
8276
 
8277 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8278
//        while ( FRAME === 0 || IRDY === 0 )
8279
//            @(posedge pci_clock) ;
8280 15 mihad
 
8281
        // set the target to normal completion
8282
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8283
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8284
 
8285
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8286
        if ( ok !== 1 )
8287
        begin
8288
            $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) ;
8289
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8290
            ok = 0 ;
8291
        end
8292
 
8293
        // now wait for delayed read to finish
8294
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8295
        if ( ok !== 1 )
8296
        begin
8297
            $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) ;
8298
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8299
            ok = 0 ;
8300
        end
8301
 
8302
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8303
        fork
8304
        begin
8305
                if ( target_mem_image == 1 )
8306
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8307
                                pci_image_base, 32'h5555_5555, 4'h0,
8308
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8309
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8310
                else
8311
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8312
 
8313
                do_pause( 1 ) ;
8314
                end
8315
                begin
8316
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8317
                end
8318
                join
8319
 
8320
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8321
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8322
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8323
        begin
8324
            $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) ;
8325
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8326
            ok = 0 ;
8327
        end
8328
 
8329
        fork
8330
        begin
8331
        // now complete a read from PCI Target
8332
            if ( target_mem_image == 1 )
8333
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8334
                            pci_image_base, 32'h5555_5555,
8335
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8336
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8337
            else
8338
                PCIU_IO_READ
8339
                (
8340
                    `Test_Master_1,
8341
                    pci_image_base,
8342
                    32'h5555_5555,
8343
                    4'h0,
8344
                    1,
8345
                    `Test_Target_Normal_Completion
8346
                );
8347
 
8348
            do_pause( 1 ) ;
8349
        end
8350
        begin
8351
            if ( target_mem_image == 1 )
8352
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8353
            else
8354
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8355
        end
8356
        join
8357
 
8358
        @(posedge pci_clock) ;
8359
        repeat( 4 )
8360
            @(posedge wb_clock) ;
8361
 
8362
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8363
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8364
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8365
        begin
8366
            $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) ;
8367
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8368
            ok = 0 ;
8369
        end
8370
 
8371
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8372
        if ( ok !== 1 )
8373
        begin
8374
            $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) ;
8375
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8376
            ok = 0 ;
8377
        end
8378
 
8379
        // finish a read on WISHBONE also
8380
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8381
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8382
        begin
8383
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8384
            test_fail("WB Slave didn't process single delayed read as expected") ;
8385
        end
8386
 
8387
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8388
        begin
8389
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8390
            ok = 0 ;
8391
        end
8392
 
8393
 
8394
        error_monitor_done = 1 ;
8395
    end
8396
    join
8397
 
8398
    if ( ok )
8399
        test_ok ;
8400
 
8401
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8402
 
8403
    // put wishbone slave in retry and pci target in completion mode
8404
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8405
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8406
 
8407
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8408
 
8409
    master1_check_received_data = 1 ;
8410
 
8411
    error_monitor_done = 0 ;
8412
    fork
8413
    begin:error_monitor_6
8414
        @(error_event_int or error_monitor_done) ;
8415
        if ( !error_monitor_done )
8416
        begin
8417
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8418
            ok = 0 ;
8419
        end
8420
    end
8421
    begin
8422
 
8423
        // do a write through Target
8424
        fork
8425
        begin
8426
            if ( target_mem_image == 1 )
8427
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8428
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8429
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8430
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8431
            else
8432
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8433
 
8434
            do_pause( 1 ) ;
8435
        end
8436
        begin
8437
            if ( target_mem_image == 1 )
8438
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8439
            else
8440
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8441
        end
8442
        join
8443
 
8444
        // start a read through WB slave
8445
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8446
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8447
        begin
8448
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8449
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8450
            ok = 0 ;
8451
        end
8452
 
8453
        // now wait for this read to finish on pci
8454
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8455
        if ( ok !== 1 )
8456
        begin
8457
            $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) ;
8458
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8459
            ok = 0 ;
8460
        end
8461
 
8462
        // repeat the read four times - it should be retried
8463
        for ( i = 0 ; i < 4 ; i = i + 1 )
8464
        begin
8465
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8466
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8467
            begin
8468
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8469
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8470
                ok = 0 ;
8471
            end
8472
        end
8473
 
8474
        // posted write through WB Slave - must go through
8475
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8476
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8477
        begin
8478
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8479
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8480
            ok = 0 ;
8481
        end
8482
 
8483
        // write must come through
8484
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8485
        if ( ok !== 1 )
8486
        begin
8487
            $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) ;
8488
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8489
            ok = 0 ;
8490
        end
8491
 
8492
        // do a read through pci target
8493
        if ( target_mem_image == 1 )
8494
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8495
                          pci_image_base + 12, 32'hDEAD_BEAF,
8496
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8497
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8498
        else
8499
            PCIU_IO_READ
8500
             (
8501
                `Test_Master_1,
8502
                pci_image_base + 12,
8503
                32'hDEAD_BEAF,
8504
                4'h0,
8505
                1,
8506
                `Test_Target_Retry_On
8507
             );
8508
 
8509
         do_pause( 1 ) ;
8510
 
8511
        // wait for current cycle to finish on WB
8512 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8513
//        @(posedge wb_clock) ;
8514
//        while( CYC_O === 1 )
8515
//            @(posedge wb_clock) ;
8516 15 mihad
 
8517
        // set slave response to acknowledge
8518
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8519
 
8520
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8521
        if ( ok !== 1 )
8522
        begin
8523
            $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) ;
8524
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8525
        end
8526
 
8527
        // check the read to finish on wb
8528
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8529
        if ( ok !== 1 )
8530
        begin
8531
            $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) ;
8532
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8533
        end
8534
 
8535
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8536
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8537
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8538
        begin
8539
            $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) ;
8540
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8541
            ok = 0 ;
8542
        end
8543
 
8544
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8545
        fork
8546
        begin
8547
            if ( target_mem_image == 1 )
8548
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8549
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8550
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8551
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8552
            else
8553
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8554
        end
8555
        begin
8556
            if ( target_mem_image == 1 )
8557
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8558
            else
8559
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8560
        end
8561
        join
8562
 
8563
        do_pause( 1 ) ;
8564
 
8565
        // complete a read in WB Slave Unit
8566
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8567
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8568
        begin
8569
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8570
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8571
            ok = 0 ;
8572
        end
8573
 
8574
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8575
        begin
8576
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8577
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8578
            ok = 0 ;
8579
        end
8580
 
8581
        // wait for statuses to be propagated from one side of bridge to another
8582
        repeat( 4 )
8583
            @(posedge pci_clock) ;
8584
 
8585
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8586
        fork
8587
        begin
8588
            if ( target_mem_image == 1 )
8589
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8590
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8591
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8592
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8593
            else
8594
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8595
 
8596
            do_pause( 1 ) ;
8597
        end
8598
        begin
8599
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8600
            if ( ok !== 1 )
8601
            begin
8602
                $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) ;
8603
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8604
            end
8605
        end
8606
        join
8607
 
8608
        // finish the last read in PCI Target Unit
8609
        if ( target_mem_image == 1 )
8610
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8611
                          pci_image_base + 12, 32'hDEAD_BEAF,
8612
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8613
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8614
        else
8615
            PCIU_IO_READ
8616
             (
8617
                `Test_Master_1,
8618
                pci_image_base + 12,
8619
                32'hDEAD_BEAF,
8620
                4'h0,
8621
                1,
8622
                `Test_Target_Normal_Completion
8623
             );
8624
 
8625
         do_pause( 1 ) ;
8626
 
8627
         error_monitor_done = 1 ;
8628
    end
8629
    join
8630
 
8631
    if ( ok )
8632
        test_ok ;
8633
 
8634
end
8635
endtask // transaction_ordering
8636
 
8637
task pci_transaction_progress_monitor ;
8638
    input [31:0] address ;
8639
    input [3:0]  bus_command ;
8640
    input [31:0] num_of_transfers ;
8641
    input [31:0] num_of_cycles ;
8642
    input check_transfers ;
8643
    input check_cycles ;
8644
    input doing_fast_back_to_back ;
8645
    output ok ;
8646
    reg in_use ;
8647
    integer deadlock_counter ;
8648
    integer transfer_counter ;
8649
    integer cycle_counter ;
8650
    integer deadlock_max_val ;
8651
begin:main
8652
 
8653
    if ( in_use === 1 )
8654
    begin
8655
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8656
        ok = 0 ;
8657
        disable main ;
8658
    end
8659
 
8660
    // approximate number of cycles on WB bus for maximum transaction length
8661
    deadlock_max_val = tb_init_waits + 100 +
8662
                       `WBW_DEPTH *
8663
                       (tb_subseq_waits + 1 +
8664
                       `ifdef REGISTER_WBS_OUTPUTS
8665
                       1) ;
8666
                       `else
8667
                       0) ;
8668
                       `endif
8669
 
8670
    // time used for maximum transaction length on WB
8671
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8672
 
8673
    // maximum pci clock cycles
8674
    `ifdef PCI33
8675
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8676
    `else
8677
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8678
    `endif
8679
 
8680
    in_use = 1 ;
8681
    ok     = 1 ;
8682
 
8683
    fork
8684
    begin:wait_start
8685
 
8686
        deadlock_counter = 0 ;
8687
 
8688
        @(posedge pci_clock) ;
8689
 
8690
        if ( doing_fast_back_to_back !== 1 )
8691
        begin
8692
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8693
            begin
8694 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8695
                    deadlock_counter = 0 ;
8696
                else
8697
                    deadlock_counter = deadlock_counter + 1 ;
8698 15 mihad
                @(posedge pci_clock) ;
8699
            end
8700
            if ( FRAME !== 1 )
8701
            begin
8702
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8703
                in_use = 0 ;
8704
                ok     = 0 ;
8705
                disable main ;
8706
            end
8707
        end
8708
 
8709
        deadlock_counter = 0 ;
8710
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8711
        begin
8712
            deadlock_counter = deadlock_counter + 1 ;
8713
            @(posedge pci_clock) ;
8714
        end
8715
 
8716
        if ( FRAME !== 0 )
8717
        begin
8718
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8719
            in_use = 0 ;
8720
            ok     = 0 ;
8721
            disable main ;
8722
        end
8723
    end //wait_start
8724
 
8725
    begin:addr_bc_monitor
8726
 
8727
        @(posedge pci_clock) ;
8728
 
8729
        if ( doing_fast_back_to_back !== 1 )
8730
        begin
8731
            while ( FRAME !== 1 )
8732
                @(posedge pci_clock) ;
8733
        end
8734
 
8735
        while( FRAME !== 0 )
8736
            @(posedge pci_clock) ;
8737
 
8738
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8739
        if ( bus_command !== `BC_IACK )
8740
        begin
8741
            if ( AD !== address )
8742
            begin
8743
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8744
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8745
                ok = 0 ;
8746
            end
8747
        end
8748
 
8749
        if ( CBE !== bus_command )
8750
        begin
8751
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8752
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8753
            ok = 0 ;
8754
        end
8755
    end //addr_bc_monitor
8756
 
8757
    begin:transfer_checker
8758
        transfer_counter = 0 ;
8759
 
8760
        @(posedge pci_clock) ;
8761
 
8762
        if ( doing_fast_back_to_back !== 1 )
8763
        begin
8764
            while ( FRAME !== 1 )
8765
                @(posedge pci_clock) ;
8766
        end
8767
 
8768
        while( FRAME !== 0 )
8769
            @(posedge pci_clock) ;
8770
 
8771
        while( FRAME === 0 )
8772
        begin
8773
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
8774
                transfer_counter = transfer_counter + 1 ;
8775
            @(posedge pci_clock) ;
8776
        end
8777
 
8778
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
8779
        begin
8780
            @(posedge pci_clock) ;
8781
        end
8782
 
8783
        if ( (TRDY === 0) && (DEVSEL === 0) )
8784
                transfer_counter = transfer_counter + 1 ;
8785
 
8786
        if ( check_transfers === 1 )
8787
        begin
8788
            if ( transfer_counter !== num_of_transfers )
8789
            begin
8790
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8791
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8792
                ok = 0 ;
8793
            end
8794
        end
8795
    end //transfer_checker
8796
    begin:cycle_checker
8797
        if ( check_cycles )
8798
        begin
8799
            cycle_counter = 0 ;
8800
            @(posedge pci_clock) ;
8801
 
8802
            if ( doing_fast_back_to_back !== 1)
8803
            begin
8804
                while ( FRAME !== 1 )
8805
                    @(posedge pci_clock) ;
8806
            end
8807
 
8808
            while( FRAME !== 0 )
8809
                @(posedge pci_clock) ;
8810
 
8811
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
8812
            begin
8813
                cycle_counter = cycle_counter + 1 ;
8814
                @(posedge pci_clock) ;
8815
            end
8816
 
8817
            if ( FRAME !== 1 )
8818
            begin
8819
                while ((FRAME === 0) && (MAS0_GNT === 0))
8820
                    @(posedge pci_clock) ;
8821
 
8822
                if ( FRAME !== 1 )
8823
                begin
8824
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
8825
                        @(posedge pci_clock) ;
8826
 
8827
                    @(posedge pci_clock) ;
8828
 
8829
                    if ( FRAME !== 1 )
8830
                    begin
8831
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
8832
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
8833
                        ok = 0 ;
8834
                    end
8835
                end
8836
            end
8837
        end
8838
    end // cycle_checker
8839
    join
8840
 
8841
    in_use = 0 ;
8842
end
8843
endtask //pci_transaction_progress_monitor
8844
 
8845
reg CYC_O_previous ;
8846
always@(posedge wb_clock or posedge reset)
8847
begin
8848
    if ( reset )
8849
        CYC_O_previous <= #1 1'b0 ;
8850
    else
8851
        CYC_O_previous <= #1 CYC_O ;
8852
end
8853
 
8854
task wb_transaction_progress_monitor ;
8855
    input [31:0] address ;
8856
    input        write ;
8857
    input [31:0] num_of_transfers ;
8858
    input check_transfers ;
8859
    output ok ;
8860
    reg in_use ;
8861
    integer deadlock_counter ;
8862
    integer transfer_counter ;
8863
    integer deadlock_max_val ;
8864
begin:main
8865
    if ( in_use === 1 )
8866
    begin
8867
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8868
        ok = 0 ;
8869
        disable main ;
8870
    end
8871
 
8872
    // number of cycles on WB bus for maximum transaction length
8873
    deadlock_max_val = 4 - tb_init_waits + 100 +
8874
                       `PCIW_DEPTH *
8875
                       (4 - tb_subseq_waits + 1) ;
8876
 
8877
    // time used for maximum transaction length on PCI
8878
    `ifdef PCI33
8879
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
8880
    `else
8881
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
8882
    `endif
8883
 
8884
    // maximum wb clock cycles
8885
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
8886
 
8887
    in_use = 1 ;
8888
    ok     = 1 ;
8889
 
8890
    fork
8891
    begin:wait_start
8892
        deadlock_counter = 0 ;
8893
        @(posedge wb_clock) ;
8894
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
8895
        begin
8896 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
8897
                deadlock_counter = deadlock_counter + 1 ;
8898
            else
8899
                deadlock_counter = 0;
8900 15 mihad
            @(posedge wb_clock) ;
8901
        end
8902
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
8903
        begin
8904
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8905
            in_use = 0 ;
8906
            ok     = 0 ;
8907
            disable main ;
8908
        end
8909
 
8910
        deadlock_counter = 0 ;
8911
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
8912
        begin
8913
            deadlock_counter = deadlock_counter + 1 ;
8914
            @(posedge wb_clock) ;
8915
        end
8916
 
8917
        if ( CYC_O !== 1 )
8918
        begin
8919
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8920
            in_use = 0 ;
8921
            ok     = 0 ;
8922
            disable main ;
8923
        end
8924
    end //wait_start
8925
    begin:addr_monitor
8926
        @(posedge wb_clock) ;
8927
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8928
            @(posedge wb_clock) ;
8929
 
8930
        while( CYC_O !== 1 )
8931
            @(posedge wb_clock) ;
8932
 
8933
        while (STB_O !== 1 )
8934
            @(posedge wb_clock) ;
8935
 
8936
        if ( WE_O !== write )
8937
        begin
8938
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
8939
            if ( write !== 1 )
8940
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
8941
            else
8942
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
8943
        end
8944
 
8945
        if ( ADR_O !== address )
8946
        begin
8947
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
8948
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
8949
            ok = 0 ;
8950
        end
8951
    end
8952
    begin:transfer_checker
8953
        transfer_counter = 0 ;
8954
        @(posedge wb_clock) ;
8955
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
8956
            @(posedge wb_clock) ;
8957
 
8958
        while( CYC_O !== 1 )
8959
            @(posedge wb_clock) ;
8960
 
8961
        while( CYC_O === 1 )
8962
        begin
8963
            if ( (STB_O === 1) && (ACK_I === 1) )
8964
                transfer_counter = transfer_counter + 1 ;
8965
            @(posedge wb_clock) ;
8966
        end
8967
 
8968
        if ( check_transfers === 1 )
8969
        begin
8970
            if ( transfer_counter !== num_of_transfers )
8971
            begin
8972
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8973
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8974
                ok = 0 ;
8975
            end
8976
        end
8977
    end //transfer_checker
8978
    join
8979
 
8980
    in_use = 0 ;
8981
end
8982
endtask // wb_transaction_progress_monitor
8983
 
8984
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
8985
// so they are not re-entered
8986
task wb_transaction_progress_monitor_backup ;
8987
    input [31:0] address ;
8988
    input        write ;
8989
    input [31:0] num_of_transfers ;
8990
    input check_transfers ;
8991
    output ok ;
8992
    reg in_use ;
8993
    integer deadlock_counter ;
8994
    integer transfer_counter ;
8995
    integer deadlock_max_val ;
8996
begin:main
8997
    if ( in_use === 1 )
8998
    begin
8999
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9000
        ok = 0 ;
9001
        disable main ;
9002
    end
9003
 
9004
    // number of cycles on WB bus for maximum transaction length
9005
    deadlock_max_val = 4 - tb_init_waits + 100 +
9006
                       `PCIW_DEPTH *
9007
                       (4 - tb_subseq_waits + 1) ;
9008
 
9009
    // time used for maximum transaction length on PCI
9010
    `ifdef PCI33
9011
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9012
    `else
9013
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9014
    `endif
9015
 
9016
    // maximum wb clock cycles
9017
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9018
 
9019
    in_use = 1 ;
9020
    ok     = 1 ;
9021
 
9022
    fork
9023
    begin:wait_start
9024
        deadlock_counter = 0 ;
9025
        @(posedge wb_clock) ;
9026
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9027
        begin
9028 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9029
                deadlock_counter = deadlock_counter + 1 ;
9030
            else
9031
                deadlock_counter = 0;
9032 15 mihad
            @(posedge wb_clock) ;
9033
        end
9034
        if ( CYC_O !== 0 )
9035
        begin
9036
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9037
            in_use = 0 ;
9038
            ok     = 0 ;
9039
            disable main ;
9040
        end
9041
 
9042
        deadlock_counter = 0 ;
9043
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9044
        begin
9045
            deadlock_counter = deadlock_counter + 1 ;
9046
            @(posedge wb_clock) ;
9047
        end
9048
 
9049
        if ( CYC_O !== 1 )
9050
        begin
9051
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9052
            in_use = 0 ;
9053
            ok     = 0 ;
9054
            disable main ;
9055
        end
9056
    end //wait_start
9057
    begin:addr_monitor
9058
        @(posedge wb_clock) ;
9059
        while ( CYC_O !== 0 )
9060
            @(posedge wb_clock) ;
9061
 
9062
        while( CYC_O !== 1 )
9063
            @(posedge wb_clock) ;
9064
 
9065
        while (STB_O !== 1 )
9066
            @(posedge wb_clock) ;
9067
 
9068
        if ( WE_O !== write )
9069
        begin
9070
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9071
            if ( write !== 1 )
9072
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9073
            else
9074
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9075
        end
9076
 
9077
        if ( ADR_O !== address )
9078
        begin
9079
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9080
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9081
            ok = 0 ;
9082
        end
9083
    end
9084
    begin:transfer_checker
9085
        transfer_counter = 0 ;
9086
        @(posedge wb_clock) ;
9087
        while ( CYC_O !== 0 )
9088
            @(posedge wb_clock) ;
9089
 
9090
        while( CYC_O !== 1 )
9091
            @(posedge wb_clock) ;
9092
 
9093
        while( CYC_O === 1 )
9094
        begin
9095
            if ( (STB_O === 1) && (ACK_I === 1) )
9096
                transfer_counter = transfer_counter + 1 ;
9097
            @(posedge wb_clock) ;
9098
        end
9099
 
9100
        if ( check_transfers === 1 )
9101
        begin
9102
            if ( transfer_counter !== num_of_transfers )
9103
            begin
9104
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9105
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9106
                ok = 0 ;
9107
            end
9108
        end
9109
    end //transfer_checker
9110
    join
9111
 
9112
    in_use = 0 ;
9113
end
9114
endtask // wb_transaction_progress_monitor_backup
9115
 
9116
task wb_transaction_stop ;
9117
    input [31:0] num_of_transfers ;
9118
    integer transfer_counter ;
9119
begin:main
9120
    begin:transfer_checker
9121
        transfer_counter = 0 ;
9122
        @(posedge wb_clock) ;
9123
        while ( CYC_O !== 0 )
9124
            @(posedge wb_clock) ;
9125
 
9126
        while( CYC_O !== 1 )
9127
            @(posedge wb_clock) ;
9128
 
9129
        if ( (STB_O === 1) && (ACK_I === 1) )
9130
            transfer_counter = transfer_counter + 1 ;
9131
 
9132
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9133
        begin
9134
            @(posedge wb_clock) ;
9135
            if ( (STB_O === 1) && (ACK_I === 1) )
9136
                transfer_counter = transfer_counter + 1 ;
9137
        end
9138
    end //transfer_checker
9139
end
9140
endtask // wb_transaction_stop
9141
 
9142
task musnt_respond ;
9143
    output ok ;
9144
    reg in_use ;
9145
    integer i ;
9146
begin:main
9147
    if ( in_use === 1 )
9148
    begin
9149
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9150
        #20 $stop ;
9151
        ok = 0 ;
9152
        disable main ;
9153
    end
9154
 
9155
    in_use = 1 ;
9156
    ok = 1 ;
9157
 
9158
    fork
9159
    begin:wait_start
9160
        @(negedge FRAME) ;
9161
        disable count ;
9162
    end
9163
    begin:count
9164
        i = 0 ;
9165
        while ( i < 1000 )
9166
        begin
9167
            @(posedge pci_clock) ;
9168
            i = i + 1 ;
9169
        end
9170
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9171
        ok = 0 ;
9172
        disable wait_start ;
9173
    end
9174
    join
9175
 
9176
    @(posedge pci_clock) ;
9177
    while ( FRAME === 0 && ok )
9178
    begin
9179
        if ( DEVSEL !== 1 )
9180
        begin
9181
            ok = 0 ;
9182
        end
9183
        @(posedge pci_clock) ;
9184
    end
9185
 
9186
    while ( IRDY === 0 && ok )
9187
    begin
9188
        if ( DEVSEL !== 1 )
9189
        begin
9190
            ok = 0 ;
9191
        end
9192
        @(posedge pci_clock) ;
9193
    end
9194
    in_use = 0 ;
9195
end
9196
endtask
9197
 
9198
function [31:0] wb_to_pci_addr_convert ;
9199
    input [31:0] wb_address ;
9200
    input [31:0] translation_address ;
9201
    input [31:0] translate ;
9202
 
9203
    reg   [31:0] temp_address ;
9204
begin
9205
    if ( translate !== 1 )
9206
    begin
9207
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9208
    end
9209
    else
9210
    begin
9211
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9212
    end
9213
 
9214
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9215
    wb_to_pci_addr_convert = temp_address ;
9216
end
9217
endfunction //wb_to_pci_addr_convert
9218
 
9219
task find_pci_devices ;
9220
    integer device_num ;
9221
    reg     found ;
9222
    reg [11:0] pci_ctrl_offset ;
9223
    reg ok ;
9224
    reg [31:0] data ;
9225
begin:main
9226
    pci_ctrl_offset = 12'h004 ;
9227
 
9228
    // enable master & target operation
9229
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9230
 
9231
    if ( ok !== 1 )
9232
    begin
9233
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9234
        $stop ;
9235
        disable main ;
9236
    end
9237
    // find all possible devices on pci bus by performing configuration cycles
9238
    for ( device_num = 0 ; device_num <= 20 ; device_num = device_num + 1 )
9239
    begin
9240
        find_device ( device_num, found ) ;
9241
 
9242
        // check pci status register - if device is not present, Received Master Abort bit must be set
9243
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9244
 
9245
        if ( (data[29] !== 0) && (found !== 0) )
9246
    begin
9247
            $display( "Time %t ", $time ) ;
9248
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9249
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9250
            #20 $stop ;
9251
        end
9252
 
9253
        if ( (data[29] !== 1) && (found !== 1) )
9254
        begin
9255
            $display( "Time %t ", $time ) ;
9256
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9257
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9258
            #20 $stop ;
9259
        end
9260
 
9261
        // clear Master Abort status if set
9262
        if ( data[29] !== 0 )
9263
        begin
9264
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9265
        end
9266
    end
9267
end //main
9268
endtask //find_pci_devices
9269
 
9270
task find_device ;
9271
    input [31:0] device_num ;
9272
    output  found ;
9273
 
9274
    reg [31:0] read_data ;
9275
begin
9276
    found = 1'b0 ;
9277
 
9278
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9279
    if ( read_data == 32'hFFFF_FFFF)
9280
        $display("Device %d not present on PCI bus!", device_num) ;
9281
    else
9282
    begin
9283
        $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]) ;
9284
        found = 1'b1 ;
9285
    end
9286
end
9287
endtask //find_device
9288
 
9289
/*task set_bridge_parameters ;
9290
    reg [11:0] current_offset ;
9291
    reg [2:0] result ;
9292
    reg [31:0] write_data ;
9293
begin
9294
    // set burst size
9295
    // set latency timer
9296
    current_offset = 12'h00C ;
9297
    // set burst size to 16 and latency timer to 8
9298
    write_data     = {24'h0000_08, system_burst_size} ;
9299
    config_write(current_offset, write_data, 4'b1111) ;
9300
 
9301
    // set io image
9302
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9303
    write_data = 32'h0000_000_3 ;
9304
    config_write(current_offset, write_data, 4'b1111) ;
9305
 
9306
 
9307
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9308
    write_data = 32'h0001_000_1 ;
9309
    config_write(current_offset, write_data, 4'b1111) ;
9310
 
9311
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9312
    write_data = 32'hFFFF_0000 ;
9313
    config_write(current_offset, write_data, 4'b1111) ;
9314
 
9315
    // set memory image
9316
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9317
    write_data = 32'h0000_000_7 ;
9318
    config_write(current_offset, write_data, 4'b1111) ;
9319
 
9320
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9321
    write_data = 32'h0002_000_0 ;
9322
    config_write(current_offset, write_data, 4'b1111) ;
9323
 
9324
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9325
    write_data = 32'h0001_0000 ;
9326
    config_write(current_offset, write_data, 4'b1111) ;
9327
 
9328
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9329
    write_data = 32'hFFFF_0000 ;
9330
    config_write(current_offset, write_data, 4'b1111) ;
9331
 
9332
    // set parameters for bridge's target unit
9333
    // image control 0
9334
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9335
    write_data     = 32'h0000_0002 ;
9336
    config_write(current_offset, write_data, 4'b0001) ;
9337
 
9338
    // base_address 0
9339
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9340
    write_data      = 32'h2000_0000 ;
9341
    config_write(current_offset, write_data, 4'b1111) ;
9342
 
9343
    // address mask 0
9344
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9345
    write_data     = 32'hFFFF_F000 ;
9346
    config_write(current_offset, write_data, 4'b1111) ;
9347
 
9348
    // command register - enable response to io and mem space and PCI master
9349
    current_offset = 12'h004 ;
9350
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9351
    config_write(current_offset, write_data, 4'b1111) ;
9352
end
9353
endtask // set_bridge_parameters
9354
*/
9355
 
9356
task configuration_cycle_write ;
9357
    input [7:0]  bus_num ;
9358
    input [4:0]  device_num ;
9359
    input [2:0]  func_num ;
9360
    input [5:0]  reg_num ;
9361
    input [1:0]  type ;
9362
    input [3:0]  byte_enables ;
9363
    input [31:0] data ;
9364
 
9365
    `ifdef HOST
9366
    reg `WRITE_STIM_TYPE write_data ;
9367
    reg `WB_TRANSFER_FLAGS write_flags ;
9368
    reg `WRITE_RETURN_TYPE write_status ;
9369
    `endif
9370
 
9371
    reg [31:0] write_address ;
9372
    reg [31:0] temp_var ;
9373
    reg in_use ;
9374
    reg ok ;
9375
begin:main
9376
 
9377
    if ( in_use === 1 )
9378
    begin
9379
        $display(" Task conf_write re-entered! Time %t ", $time ) ;
9380
        disable main ;
9381
    end
9382
 
9383
    if ( device_num > 20 )
9384
    begin
9385
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9386
        disable main ;
9387
    end
9388
 
9389
    in_use = 1 ;
9390
 
9391
    if ( type )
9392
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9393
    else
9394
    begin
9395
        write_address = 0 ;
9396
        write_address[10:0] = { func_num, reg_num, type } ;
9397
        write_address[11 + device_num] = 1'b1 ;
9398
    end
9399
 
9400
fork
9401
begin
9402
    `ifdef HOST
9403
    // setup write flags
9404
    write_flags                    = 0 ;
9405
    write_flags`INIT_WAITS         = tb_init_waits ;
9406
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
9407
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
9408
 
9409
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9410
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9411
 
9412
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9413
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9414
    write_data`WRITE_SEL      = 4'hF ;
9415
    write_data`WRITE_TAG_STIM = 0 ;
9416
 
9417
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9418
 
9419
    // check if write succeeded
9420
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9421
    begin
9422
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9423
        $stop ;
9424
    end
9425
 
9426
    // write to configuration data register
9427
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
9428
 
9429
    write_data`WRITE_ADDRESS = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9430
    write_data`WRITE_DATA    = data ;
9431
    write_data`WRITE_SEL     = byte_enables ;
9432
 
9433
    wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
9434
 
9435
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9436
    begin
9437
        $display("Configuration cycle generation failed! Time %t ", $time) ;
9438
        $stop ;
9439
    end
9440
 
9441
    `else
9442
    `ifdef GUEST
9443
 
9444
     if ( type )
9445
         write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9446
     else
9447
     begin
9448
         write_address = 0 ;
9449
         write_address[10:0] = { func_num, reg_num, type } ;
9450
         write_address[11 + device_num] = 1'b1 ;
9451
     end
9452
     PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9453
                 write_address,
9454
                 data, ~byte_enables,
9455
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9456
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9457
     do_pause(1) ;
9458
    `endif
9459
    `endif
9460
end
9461
begin
9462
    pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9463
end
9464
join
9465
 
9466
    in_use = 0 ;
9467
end
9468
endtask // configuration_cycle_write
9469
 
9470
task configuration_cycle_read ;
9471
    input [7:0]  bus_num ;
9472
    input [4:0]  device_num ;
9473
    input [2:0]  func_num ;
9474
    input [5:0]  reg_num ;
9475
    input [1:0]  type ;
9476
    input [3:0]  byte_enables ;
9477
    output [31:0] data ;
9478
 
9479
    reg `READ_STIM_TYPE read_data ;
9480
    reg `WB_TRANSFER_FLAGS  flags ;
9481
    reg `READ_RETURN_TYPE   read_status ;
9482
 
9483
    reg `WRITE_STIM_TYPE   write_data ;
9484
    reg `WRITE_RETURN_TYPE write_status ;
9485
 
9486
    reg [31:0] read_address ;
9487
    reg in_use ;
9488
 
9489
    reg [31:0] temp_var ;
9490
    reg master_check_data_prev ;
9491
begin:main
9492
 
9493
    if ( in_use === 1 )
9494
    begin
9495
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9496
        data = 32'hxxxx_xxxx ;
9497
        disable main ;
9498
    end
9499
 
9500
    if ( device_num > 20 )
9501
    begin
9502
        $display("Configuration cycle generation only supports access to 20 devices!") ;
9503
        data = 32'hxxxx_xxxx ;
9504
        disable main ;
9505
    end
9506
 
9507
    in_use = 1 ;
9508
 
9509
    `ifdef HOST
9510
    // setup flags
9511
    flags = 0 ;
9512
 
9513
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9514
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9515
 
9516
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9517
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9518
    write_data`WRITE_SEL      = 4'hF ;
9519
    write_data`WRITE_TAG_STIM = 0 ;
9520
 
9521
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9522
 
9523
    // check if write succeeded
9524
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9525
    begin
9526
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9527
        $stop ;
9528
        data = 32'hFFFF_FFFF ;
9529
        disable main ;
9530
    end
9531
 
9532
    // read from configuration data register
9533
    // setup flags for wb master to handle retries
9534
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9535
 
9536
    read_data`READ_ADDRESS  = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9537
    read_data`READ_SEL      = 4'hF ;
9538
    read_data`READ_TAG_STIM = 0 ;
9539
 
9540
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
9541
 
9542
    // check if read succeeded
9543
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
9544
    begin
9545
        $display("Configuration cycle generation failed! Configuration read not processed correctly by the bridge! Time %t ", $time) ;
9546
        $stop ;
9547
        data = 32'hFFFF_FFFF ;
9548
        disable main ;
9549
    end
9550
 
9551
 
9552
    data = read_status`READ_DATA ;
9553
    `else
9554
    `ifdef GUEST
9555
     master_check_data_prev = master1_check_received_data ;
9556
     if ( type )
9557
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9558
     else
9559
     begin
9560
         read_address = 0 ;
9561
         read_address[10:0] = { func_num, reg_num, type } ;
9562
         read_address[11 + device_num] = 1'b1 ;
9563
     end
9564
 
9565
     fork
9566
     begin
9567
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9568
                 read_address,
9569
                 data, ~byte_enables,
9570
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9571
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9572
         do_pause(1) ;
9573
     end
9574
     begin
9575
         @(master1_received_data_valid) ;
9576
         data = master1_received_data ;
9577
     end
9578
     join
9579
 
9580
    master1_check_received_data = master_check_data_prev ;
9581
    `endif
9582
    `endif
9583
 
9584
    in_use = 0 ;
9585
 
9586
end //main
9587
endtask // configuration_cycle_read
9588
 
9589
task display_warning;
9590
    input [31:0] error_address ;
9591
    input [31:0] expected_data ;
9592
    input [31:0] actual ;
9593
begin
9594
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
9595
end
9596
endtask // display warning
9597
 
9598
/*############################################################################
9599
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
9600
=====================
9601
############################################################################*/
9602
 
9603
// Task reslease the PCI bus for 'delay' clocks
9604
task do_pause;
9605
  input  [15:0] delay;
9606
  reg    [15:0] cnt;
9607
  begin
9608
    test_start <= 1'b0;  // no device is allowed to take this
9609
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
9610
    begin
9611
      if (~pci_reset_comb)
9612
      begin
9613
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9614
      end
9615
      `NO_ELSE;
9616
    end
9617
  end
9618
endtask // do_pause
9619
 
9620
// Reference task for using pci_behavioral_master! (from Blue Beaver)
9621
task DO_REF;
9622
  input  [79:0] name;
9623
  input  [2:0] master_number;
9624
  input  [PCI_BUS_DATA_RANGE:0] address;
9625
  input  [3:0] command;
9626
  input  [PCI_BUS_DATA_RANGE:0] data;
9627
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
9628
  input  [9:0] size;
9629
  input   make_addr_par_error, make_data_par_error;
9630
  input  [7:0] master_wait_states;
9631
  input  [7:0] target_wait_states;
9632
  input  [1:0] target_devsel_speed;
9633
  input   fast_back_to_back;
9634
  input  [2:0] target_termination;
9635
  input   expect_master_abort;
9636
  reg     waiting;
9637
  begin
9638
// Cautiously wait for previous command to be done
9639
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
9640
    begin
9641
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
9642
      begin
9643
        if (~pci_reset_comb)
9644
        begin
9645
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9646
        end
9647
        `NO_ELSE;
9648
      end
9649
      else
9650
      begin
9651
        waiting = 1'b0;  // ready to do next command
9652
      end
9653
    end
9654
    next_test_name[79:0] <= name[79:0];
9655
    test_master_number <= master_number[2:0];
9656
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
9657
    test_command[3:0] <= command[3:0] ;
9658
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
9659
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
9660
    test_size <= size;
9661
    test_make_addr_par_error <= make_addr_par_error;
9662
    test_make_data_par_error <= make_data_par_error;
9663
    test_master_initial_wait_states <= 4 - tb_init_waits ;
9664
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
9665
    test_target_initial_wait_states <= target_wait_states[7:4];
9666
    test_target_subsequent_wait_states <= target_wait_states[3:0];
9667
    test_target_devsel_speed <= target_devsel_speed[1:0];
9668
    test_fast_back_to_back <= fast_back_to_back;
9669
    test_target_termination <= target_termination[2:0];
9670
    test_expect_master_abort <= expect_master_abort;
9671
    test_start <= 1'b1;
9672
    if (~pci_reset_comb)
9673
    begin
9674
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9675
    end
9676
    `NO_ELSE;
9677
// wait for new command to start
9678
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
9679
    begin
9680
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
9681
      begin
9682
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
9683
      end
9684
      else
9685
      begin
9686
        waiting = 1'b0;  // ready to do next command
9687
      end
9688
    end
9689
  end
9690
endtask // DO_REF
9691
 
9692
// Use Macros defined in pci_defines.vh as paramaters
9693
 
9694
// DO_REF (name[79:0], master_number[2:0],
9695
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
9696
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
9697
//          make_addr_par_error, make_data_par_error,
9698
//          master_wait_states[8:0], target_wait_states[8:0],
9699
//          target_devsel_speed[1:0], fast_back_to_back,
9700
//          target_termination[2:0],
9701
//          expect_master_abort);
9702
//
9703
// Example:
9704
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
9705
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
9706
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
9707
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
9708
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
9709
 
9710
// Access a location with no high-order bits set, assuring that no device responds
9711
task PCIU_CONFIG_READ_MASTER_ABORT;
9712
  input  [79:0] name;
9713
  input  [2:0] master_number;
9714
  input  [9:0] size;
9715
  begin
9716
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9717
               PCI_COMMAND_CONFIG_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9718
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9719
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9720
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9721
  end
9722
endtask // PCIU_CONFIG_READ_MASTER_ABORT
9723
 
9724
// Access a location with no high-order bits set, assuring that no device responds
9725
task PCIU_CONFIG_WRITE_MASTER_ABORT;
9726
  input  [79:0] name;
9727
  input  [2:0] master_number;
9728
  input  [9:0] size;
9729
  begin
9730
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9731
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9732
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
9733
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9734
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9735
  end
9736
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
9737
 
9738
// Access a location with no high-order bits set, assuring that no device responds
9739
task PCIU_MEM_READ_MASTER_ABORT;
9740
  input  [79:0] name;
9741
  input  [2:0] master_number;
9742
  input  [9:0] size;
9743
  begin
9744
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9745
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
9746
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9747
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9748
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9749
  end
9750
endtask // PCIU_MEM_READ_MASTER_ABORT
9751
 
9752
// Access a location with no high-order bits set, assuring that no device responds
9753
task PCIU_MEM_WRITE_MASTER_ABORT;
9754
  input  [79:0] name;
9755
  input  [2:0] master_number;
9756
  input  [9:0] size;
9757
  begin
9758
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
9759
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
9760
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
9761
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
9762
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
9763
  end
9764
endtask // PCIU_MEM_WRITE_MASTER_ABORT
9765
 
9766
// Do variable length transfers with various paramaters
9767
task PCIU_CONFIG_READ;
9768
  input  [79:0] name;
9769
  input  [2:0] master_number;
9770
  input  [PCI_BUS_DATA_RANGE:0] address;
9771
  input  [PCI_BUS_DATA_RANGE:0] data;
9772
  input  [3:0] be ;
9773
  input  [9:0] size;
9774
  input  [7:0] master_wait_states;
9775
  input  [7:0] target_wait_states;
9776
  input  [1:0] target_devsel_speed;
9777
  input  [2:0] target_termination;
9778
  begin
9779
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9780
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
9781
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9782
              8'h0_0, target_wait_states[7:0],
9783
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9784
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9785
  end
9786
endtask // PCIU_CONFIG_READ
9787
 
9788
task PCIU_CONFIG_WRITE;
9789
  input  [79:0] name;
9790
  input  [2:0] master_number;
9791
  input  [PCI_BUS_DATA_RANGE:0] address;
9792
  input  [PCI_BUS_DATA_RANGE:0] data;
9793
  input  [3:0] be ;
9794
  input  [9:0] size;
9795
  input  [7:0] master_wait_states;
9796
  input  [7:0] target_wait_states;
9797
  input  [1:0] target_devsel_speed;
9798
  input  [2:0] target_termination;
9799
  begin
9800
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9801
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
9802
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9803
              8'h0_0, target_wait_states[7:0],
9804
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9805
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9806
  end
9807
endtask // PCIU_CONFIG_WRITE
9808
 
9809
task PCIU_READ;
9810
  input  [2:0] master_number;
9811
  input  [PCI_BUS_DATA_RANGE:0] address;
9812
  input  [3:0] command;
9813
  input  [PCI_BUS_DATA_RANGE:0] data;
9814
  input  [3:0] byte_en;
9815
  input  [9:0] size;
9816
  input  [7:0] master_wait_states;
9817
  input  [7:0] target_wait_states;
9818
  input  [1:0] target_devsel_speed;
9819
  input  [2:0] target_termination;
9820
  reg    [79:0] name;
9821
  begin
9822
    if (command == `BC_MEM_READ)
9823
        name = "MEM_READ  " ;
9824
    else if (command == `BC_MEM_READ_LN)
9825
        name = "MEM_RD_LN " ;
9826
    else if (command == `BC_MEM_READ_MUL )
9827
        name = "MEM_RD_MUL" ;
9828
    else
9829
        name = "WRONG_READ" ;
9830
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9831
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9832
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9833
              8'h0_0, target_wait_states[7:0],
9834
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9835
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9836
  end
9837
endtask // PCIU_READ
9838
 
9839
task PCIU_MEM_READ;
9840
  input  [79:0] name;
9841
  input  [2:0] master_number;
9842
  input  [PCI_BUS_DATA_RANGE:0] address;
9843
  input  [PCI_BUS_DATA_RANGE:0] data;
9844
  input  [9:0] size;
9845
  input  [7:0] master_wait_states;
9846
  input  [7:0] target_wait_states;
9847
  input  [1:0] target_devsel_speed;
9848
  input  [2:0] target_termination;
9849
  begin
9850
 
9851
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9852
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9853
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9854
              8'h0_0, target_wait_states[7:0],
9855
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9856
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9857
  end
9858
endtask // PCIU_MEM_READ
9859
 
9860
task PCIU_IO_READ;
9861
  input  [2:0] master_number;
9862
  input  [PCI_BUS_DATA_RANGE:0] address;
9863
  input  [PCI_BUS_DATA_RANGE:0] data;
9864
  input  [3:0] byte_en ;
9865
  input  [9:0] size;
9866
  input  [2:0] target_termination ;
9867
  begin
9868
 
9869
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9870
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9871
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9872
              8'h0_0, `Test_One_Zero_Target_WS,
9873
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9874
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9875
  end
9876
endtask // PCIU_IO_READ
9877
 
9878
task PCIU_IO_READ_MAKE_PERR;
9879
  input  [2:0] master_number;
9880
  input  [PCI_BUS_DATA_RANGE:0] address;
9881
  input  [PCI_BUS_DATA_RANGE:0] data;
9882
  input  [3:0] byte_en ;
9883
  input  [9:0] size;
9884
  input  [2:0] target_termination ;
9885
  begin
9886
 
9887
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9888
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
9889
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9890
              8'h0_0, `Test_One_Zero_Target_WS,
9891
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9892
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9893
  end
9894
endtask // PCIU_IO_READ_MAKE_PERR
9895
 
9896
task PCIU_MEM_READ_LN;
9897
  input  [79:0] name;
9898
  input  [2:0] master_number;
9899
  input  [PCI_BUS_DATA_RANGE:0] address;
9900
  input  [PCI_BUS_DATA_RANGE:0] data;
9901
  input  [9:0] size;
9902
  input  [7:0] master_wait_states;
9903
  input  [7:0] target_wait_states;
9904
  input  [1:0] target_devsel_speed;
9905
  input  [2:0] target_termination;
9906
  begin
9907
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9908
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9909
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9910
              8'h0_0, target_wait_states[7:0],
9911
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9912
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9913
  end
9914
endtask // PCIU_MEM_READ_LN
9915
 
9916
task PCIU_MEM_READ_MUL;
9917
  input  [79:0] name;
9918
  input  [2:0] master_number;
9919
  input  [PCI_BUS_DATA_RANGE:0] address;
9920
  input  [PCI_BUS_DATA_RANGE:0] data;
9921
  input  [9:0] size;
9922
  input  [7:0] master_wait_states;
9923
  input  [7:0] target_wait_states;
9924
  input  [1:0] target_devsel_speed;
9925
  input  [2:0] target_termination;
9926
  begin
9927
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9928
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9929
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9930
              8'h0_0, target_wait_states[7:0],
9931
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9932
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9933
  end
9934
endtask // PCIU_MEM_READ_MUL
9935
 
9936
task PCIU_MEM_READ_MAKE_PERR;
9937
  input  [79:0] name;
9938
  input  [2:0] master_number;
9939
  input  [PCI_BUS_DATA_RANGE:0] address;
9940
  input  [PCI_BUS_DATA_RANGE:0] data;
9941
  input  [9:0] size;
9942
  input  [7:0] master_wait_states;
9943
  input  [7:0] target_wait_states;
9944
  input  [1:0] target_devsel_speed;
9945
  input  [2:0] target_termination;
9946
  begin
9947
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9948
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
9949
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
9950
              8'h0_0, target_wait_states[7:0],
9951
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9952
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9953
  end
9954
endtask // PCIU_MEM_READ_MAKE_PERR
9955
 
9956
task PCIU_MEM_WRITE;
9957
  input  [79:0] name;
9958
  input  [2:0] master_number;
9959
  input  [PCI_BUS_DATA_RANGE:0] address;
9960
  input  [PCI_BUS_DATA_RANGE:0] data;
9961
  input  [3:0] byte_en;
9962
  input  [9:0] size;
9963
  input  [7:0] master_wait_states;
9964
  input  [7:0] target_wait_states;
9965
  input  [1:0] target_devsel_speed;
9966
  input  [2:0] target_termination;
9967
  begin
9968
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9969
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9970
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9971
              8'h0_0, target_wait_states[7:0],
9972
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
9973
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9974
  end
9975
endtask // PCIU_MEM_WRITE
9976
 
9977
task PCIU_IO_WRITE;
9978
  input  [2:0] master_number;
9979
  input  [PCI_BUS_DATA_RANGE:0] address;
9980
  input  [PCI_BUS_DATA_RANGE:0] data;
9981
  input  [3:0] byte_en;
9982
  input  [9:0] size;
9983
  input  [2:0] target_termination ;
9984
  begin
9985
 
9986
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
9987
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
9988
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
9989
              8'h0_0, `Test_One_Zero_Target_WS,
9990
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
9991
              target_termination[2:0], `Test_Expect_No_Master_Abort);
9992
  end
9993
endtask // PCIU_IO_WRITE
9994
 
9995
task PCIU_IO_WRITE_MAKE_PERR ;
9996
  input  [2:0] master_number;
9997
  input  [PCI_BUS_DATA_RANGE:0] address;
9998
  input  [PCI_BUS_DATA_RANGE:0] data;
9999
  input  [3:0] byte_en;
10000
  input  [9:0] size;
10001
  input  [2:0] target_termination ;
10002
  begin
10003
 
10004
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10005
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
10006
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
10007
              8'h0_0, `Test_One_Zero_Target_WS,
10008
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
10009
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10010
  end
10011
endtask // PCIU_IO_WRITE
10012
 
10013
task PCIU_MEM_WRITE_MAKE_SERR;
10014
  input  [79:0] name;
10015
  input  [2:0] master_number;
10016
  input  [PCI_BUS_DATA_RANGE:0] address;
10017
  input  [PCI_BUS_DATA_RANGE:0] data;
10018
  input  [9:0] size;
10019
  input  [7:0] master_wait_states;
10020
  input  [7:0] target_wait_states;
10021
  input  [1:0] target_devsel_speed;
10022
  input  [2:0] target_termination;
10023
  begin
10024
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10025
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
10026
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
10027
              8'h0_0, target_wait_states[7:0],
10028
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10029
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10030
  end
10031
endtask // PCIU_MEM_WRITE_MAKE_SERR
10032
 
10033
task PCIU_MEM_WRITE_MAKE_PERR;
10034
  input  [79:0] name;
10035
  input  [2:0] master_number;
10036
  input  [PCI_BUS_DATA_RANGE:0] address;
10037
  input  [PCI_BUS_DATA_RANGE:0] data;
10038
  input  [9:0] size;
10039
  input  [7:0] master_wait_states;
10040
  input  [7:0] target_wait_states;
10041
  input  [1:0] target_devsel_speed;
10042
  input  [2:0] target_termination;
10043
  begin
10044
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
10045
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
10046
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
10047
              8'h0_0, target_wait_states[7:0],
10048
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
10049
              target_termination[2:0], `Test_Expect_No_Master_Abort);
10050
  end
10051
endtask // PCIU_MEM_WRITE
10052
 
10053
/*--------------------------------------------------------------------------
10054
Initialization CASES
10055
--------------------------------------------------------------------------*/
10056
 
10057
// Initialize the basic Config Registers of the PCI bridge target device
10058
task configure_bridge_target;
10059
    reg [11:0] offset ;
10060
    reg [31:0] data ;
10061
    `ifdef HOST
10062
    reg `WRITE_STIM_TYPE   write_data ;
10063
    reg `WB_TRANSFER_FLAGS write_flags ;
10064
    reg `WRITE_RETURN_TYPE write_status ;
10065
    `else
10066
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10067
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10068
    `endif
10069
 
10070
    reg [31:0] temp_var ;
10071
begin
10072
`ifdef HOST //  set Header
10073
    offset  = 12'h4 ; // PCI Header Command register
10074
    data    = 32'h0000_0007 ; // enable master & target operation
10075
 
10076
    write_flags                      = 0 ;
10077
    write_flags`INIT_WAITS           = tb_init_waits ;
10078
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10079
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10080
 
10081
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
10082
    write_data`WRITE_SEL      = 4'h1 ;
10083
    write_data`WRITE_TAG_STIM = 0 ;
10084
    write_data`WRITE_DATA     = data ;
10085
 
10086
    next_test_name[79:0] <= "Init_Tar_R";
10087
 
10088
    $display(" bridge target - Enabling master and target operation!");
10089
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10090
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10091
    begin
10092
        $display("Write to configuration space failed! Time %t ", $time) ;
10093
    end
10094
 
10095
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10096
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10097
 
10098
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10099
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10100
 
10101
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10102
    write_data`WRITE_SEL      = 4'hf ;
10103
    write_data`WRITE_TAG_STIM = 0 ;
10104
    write_data`WRITE_DATA     = data ;
10105
 
10106
 `ifdef  NO_CNF_IMAGE
10107
  `ifdef PCI_IMAGE0 //      set P_BA0
10108
 
10109
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10110
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10111
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10112
    begin
10113
        $display("Write to configuration space failed! Time %t ", $time) ;
10114
    end
10115
  `endif
10116
 `else //      set P_BA0
10117
 
10118
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10119
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10120
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10121
    begin
10122
        $display("Write to configuration space failed! Time %t ", $time) ;
10123
    end
10124
 `endif
10125
 
10126
`else // GUEST, set Header, set P_BA0
10127
    data            = 32'h0000_0007 ; // enable master & target operation
10128
    byte_enables    = 4'hF ;
10129
    $display(" bridge target - Enabling master and target operation!");
10130
    configuration_cycle_write(0,             // bus number
10131
                              0,             // device number
10132
                              0,             // function number
10133
                              1,             // register number
10134
                              0,             // type of configuration cycle
10135
                              byte_enables,  // byte enables
10136
                              data           // data
10137
                             ) ;
10138
 
10139
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10140
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10141
    byte_enables = 4'hf ;
10142
    configuration_cycle_write(0,             // bus number
10143
                              0,             // device number
10144
                              0,             // function number
10145
                              4,             // register number
10146
                              0,             // type of configuration cycle
10147
                              byte_enables,  // byte enables
10148
                              data           // data
10149
                             ) ;
10150
 
10151
`endif
10152
end
10153
endtask // configure_bridge_target
10154
 
10155
// Initialize the basic Config Registers of the PCI bridge target device
10156
task configure_bridge_target_base_addresses;
10157
    reg [11:0] offset ;
10158
    reg [31:0] data ;
10159
    `ifdef HOST
10160
    reg `WRITE_STIM_TYPE   write_data ;
10161
    reg `WB_TRANSFER_FLAGS write_flags ;
10162
    reg `WRITE_RETURN_TYPE write_status ;
10163
    `else
10164
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
10165
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
10166
    `endif
10167
 
10168
    reg [31:0] temp_var ;
10169
begin
10170
`ifdef HOST //  set Header
10171
    offset  = 12'h4 ; // PCI Header Command register
10172
    data    = 32'h0000_0007 ; // enable master & target operation
10173
 
10174
    write_flags                    = 0 ;
10175
    write_flags`INIT_WAITS         = tb_init_waits ;
10176
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
10177
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
10178
 
10179
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10180
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10181
 
10182
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10183
    write_data`WRITE_SEL      = 4'h1 ;
10184
    write_data`WRITE_TAG_STIM = 0 ;
10185
    write_data`WRITE_DATA     = data ;
10186
 
10187
    next_test_name[79:0] <= "Init_Tar_R";
10188
 
10189
    $display(" bridge target - Enabling master and target operation!");
10190
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10191
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10192
    begin
10193
        $display("Write to configuration space failed! Time %t ", $time) ;
10194
    end
10195
 
10196
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
10197
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10198
 
10199
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10200
    write_data`WRITE_SEL      = 4'hf ;
10201
    write_data`WRITE_TAG_STIM = 0 ;
10202
    write_data`WRITE_DATA     = data ;
10203
 
10204
 `ifdef  NO_CNF_IMAGE
10205
  `ifdef PCI_IMAGE0 //      set P_BA0
10206
 
10207
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10208
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10209
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10210
    begin
10211
        $display("Write to configuration space failed! Time %t ", $time) ;
10212
    end
10213
  `endif
10214
 `else //      set P_BA0
10215
 
10216
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10217
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10218
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10219
    begin
10220
        $display("Write to configuration space failed! Time %t ", $time) ;
10221
    end
10222
 `endif
10223
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
10224
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10225
 
10226
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10227
    write_data`WRITE_SEL      = 4'hf ;
10228
    write_data`WRITE_TAG_STIM = 0 ;
10229
    write_data`WRITE_DATA     = data ;
10230
 
10231
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10232
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10233
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10234
    begin
10235
        $display("Write to configuration space failed! Time %t ", $time) ;
10236
    end
10237
 `ifdef PCI_IMAGE2
10238
 
10239
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
10240
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10241
 
10242
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10243
    write_data`WRITE_SEL      = 4'hf ;
10244
    write_data`WRITE_TAG_STIM = 0 ;
10245
    write_data`WRITE_DATA     = data ;
10246
 
10247
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10248
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10249
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10250
    begin
10251
        $display("Write to configuration space failed! Time %t ", $time) ;
10252
    end
10253
 `endif
10254
 `ifdef PCI_IMAGE3
10255
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
10256
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10257
 
10258
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10259
    write_data`WRITE_SEL      = 4'hf ;
10260
    write_data`WRITE_TAG_STIM = 0 ;
10261
    write_data`WRITE_DATA     = data ;
10262
 
10263
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10264
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10265
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10266
    begin
10267
        $display("Write to configuration space failed! Time %t ", $time) ;
10268
    end
10269
 `endif
10270
 `ifdef PCI_IMAGE4
10271
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
10272
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10273
 
10274
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10275
    write_data`WRITE_SEL      = 4'hf ;
10276
    write_data`WRITE_TAG_STIM = 0 ;
10277
    write_data`WRITE_DATA     = data ;
10278
 
10279
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10280
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10281
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10282
    begin
10283
        $display("Write to configuration space failed! Time %t ", $time) ;
10284
    end
10285
 `endif
10286
 `ifdef PCI_IMAGE5
10287
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
10288
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10289
 
10290
    write_data`WRITE_ADDRESS  = temp_var + offset ;
10291
    write_data`WRITE_SEL      = 4'hf ;
10292
    write_data`WRITE_TAG_STIM = 0 ;
10293
    write_data`WRITE_DATA     = data ;
10294
 
10295
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10296
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
10297
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10298
    begin
10299
        $display("Write to configuration space failed! Time %t ", $time) ;
10300
    end
10301
 `endif
10302
 
10303
`else // GUEST, set Header, set P_BA0
10304
    data            = 32'h0000_0007 ; // enable master & target operation
10305
    byte_enables    = 4'hF ;
10306
    $display(" bridge target - Enabling master and target operation!");
10307
    configuration_cycle_write(0,             // bus number
10308
                              0,             // device number
10309
                              0,             // function number
10310
                              1,             // register number
10311
                              0,             // type of configuration cycle
10312
                              byte_enables,  // byte enables
10313
                              data           // data
10314
                             ) ;
10315
 
10316
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
10317
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
10318
    byte_enables = 4'hf ;
10319
    configuration_cycle_write(0,             // bus number
10320
                              0,             // device number
10321
                              0,             // function number
10322
                              4,             // register number
10323
                              0,             // type of configuration cycle
10324
                              byte_enables,  // byte enables
10325
                              data           // data
10326
                             ) ;
10327
 
10328
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
10329
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
10330
    byte_enables = 4'hf ;
10331
    configuration_cycle_write(0,             // bus number
10332
                              0,             // device number
10333
                              0,             // function number
10334
                              5,             // register number
10335
                              0,             // type of configuration cycle
10336
                              byte_enables,  // byte enables
10337
                              data           // data
10338
                             ) ;
10339
 `ifdef PCI_IMAGE2
10340
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
10341
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
10342
    byte_enables = 4'hf ;
10343
    configuration_cycle_write(0,             // bus number
10344
                              0,             // device number
10345
                              0,             // function number
10346
                              6,             // register number
10347
                              0,             // type of configuration cycle
10348
                              byte_enables,  // byte enables
10349
                              data           // data
10350
                             ) ;
10351
 `endif
10352
 `ifdef PCI_IMAGE3
10353
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
10354
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
10355
    byte_enables = 4'hf ;
10356
    configuration_cycle_write(0,             // bus number
10357
                              0,             // device number
10358
                              0,             // function number
10359
                              7,             // register number
10360
                              0,             // type of configuration cycle
10361
                              byte_enables,  // byte enables
10362
                              data           // data
10363
                             ) ;
10364
 `endif
10365
 `ifdef PCI_IMAGE4
10366
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
10367
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
10368
    byte_enables = 4'hf ;
10369
    configuration_cycle_write(0,             // bus number
10370
                              0,             // device number
10371
                              0,             // function number
10372
                              8,             // register number
10373
                              0,             // type of configuration cycle
10374
                              byte_enables,  // byte enables
10375
                              data           // data
10376
                             ) ;
10377
 `endif
10378
 `ifdef PCI_IMAGE5
10379
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
10380
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
10381
    byte_enables = 4'hf ;
10382
    configuration_cycle_write(0,             // bus number
10383
                              0,             // device number
10384
                              0,             // function number
10385
                              9,             // register number
10386
                              0,             // type of configuration cycle
10387
                              byte_enables,  // byte enables
10388
                              data           // data
10389
                             ) ;
10390
 `endif
10391
`endif
10392
end
10393
endtask // configure_bridge_target_base_addresses
10394
 
10395
/*--------------------------------------------------------------------------
10396
Test CASES
10397
--------------------------------------------------------------------------*/
10398
 
10399
// function converts PCI address to WB with the same data as the pci_decoder does
10400
function [31:0] pci_to_wb_addr_convert ;
10401
 
10402
    input [31:0] pci_address ;
10403
    input [31:0] translation_address ;
10404
    input [31:0] translate ;
10405
 
10406
    reg   [31:0] temp_address ;
10407
begin
10408
    if ( translate !== 1 )
10409
    begin
10410
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10411
    end
10412
    else
10413
    begin
10414
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
10415
    end
10416
 
10417
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
10418
    pci_to_wb_addr_convert = temp_address ;
10419
end
10420
endfunction // pci_to_wb_addr_convert
10421
 
10422
// Test normal write and read to WB slave
10423
task test_normal_wr_rd;
10424
  input  [2:0]  Master_ID;
10425
  input  [PCI_BUS_DATA_RANGE:0] Address;
10426
  input  [PCI_BUS_DATA_RANGE:0] Data;
10427
  input  [3:0]  Be;
10428
  input  [2:0]  Image_num;
10429
  input  [9:0]  Set_size;
10430
  input         Set_addr_translation;
10431
  input         Set_prefetch_enable;
10432
  input  [7:0]  Cache_lsize;
10433
  input         Set_wb_wait_states;
10434
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
10435
 
10436
  reg    [31:0] rd_address;
10437
  reg    [31:0] rd_data;
10438
  reg    [3:0]  rd_be;
10439
  reg    [11:0] addr_offset;
10440
  reg    [31:0] read_data;
10441
  reg           continue ;
10442
  reg           ok   ;
10443
  reg    [31:0] expect_address ;
10444
  reg    [31:0] expect_rd_address ;
10445
  reg           expect_we ;
10446
  reg    [9:0]  expect_length_wr ;
10447
  reg    [9:0]  expect_length_rd ;
10448
  reg    [9:0]  expect_length_rd1 ;
10449
  reg    [9:0]  expect_length_rd2 ;
10450
  reg    [3:0]  use_rd_cmd ;
10451
  integer       i ;
10452
begin:main
10453
 
10454
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
10455
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10456
    $display(" - errors will be reported, but they should not occur!");
10457
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
10458
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10459
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
10460
    if ( ok !== 1 )
10461
    begin
10462
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10463
        test_fail("write to P_ERR_CS register didn't succeede") ;
10464
        disable main;
10465
    end
10466
 
10467
    `ifdef  ADDR_TRAN_IMPL
10468
 
10469
    // set or clear address translation
10470
    if (Set_addr_translation)
10471
    begin
10472
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10473
        $display(" - address translation will be performed!");
10474
    end
10475
    else
10476
    begin
10477
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10478
        $display(" - address translation will not be performed!");
10479
    end
10480
    // set or clear pre-fetch enable
10481
    if (Set_prefetch_enable)
10482
    begin
10483
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10484
        $display(" - bursts can be performed!");
10485
    end
10486
    else
10487
    begin
10488
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10489
        $display(" - bursts can not be performed!");
10490
    end
10491
 
10492
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10493
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10494
    if ( ok !== 1 )
10495
    begin
10496
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10497
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10498
        disable main;
10499
    end
10500
 
10501
    // predict the address and control signals on WB bus
10502
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
10503
    expect_we      = 1'b1 ; // WRITE
10504
 
10505
    `else
10506
 
10507
    // address translation is not implemented
10508
    $display("Address translation is NOT implemented for PCI images!");
10509
    // set or clear pre-fetch enable
10510
    if (Set_prefetch_enable)
10511
    begin
10512
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10513
        $display(" - bursts can be performed!");
10514
    end
10515
    else
10516
    begin
10517
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
10518
        $display(" - bursts can not be performed!");
10519
    end
10520
 
10521
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10522
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
10523
    if ( ok !== 1 )
10524
    begin
10525
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
10526
        test_fail("write to P_IMG_CTRL didn't succeede") ;
10527
        disable main;
10528
    end
10529
 
10530
    // predict the address and control signals on WB bus
10531
    expect_address = Address ;
10532
    expect_we      = 1'b1 ; // WRITE
10533
 
10534
    `endif
10535
 
10536
    // set WB SLAVE parameters
10537
    if (Set_wb_wait_states)
10538
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
10539
    else
10540
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
10541
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
10542
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
10543
 
10544
    if ( Set_size > (`PCIW_DEPTH - 2) )
10545
    begin
10546
        expect_length_wr = `PCIW_DEPTH - 2 ;
10547
    end
10548
    else
10549
    begin
10550
        expect_length_wr = Set_size ;
10551
    end
10552
    // write through the PCI bridge to WB slave
10553
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
10554
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
10555
 
10556
    fork
10557
    begin
10558
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
10559
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
10560
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10561
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10562
        do_pause( 1 ) ;
10563
    end
10564
    begin
10565
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
10566
       if ( ok !== 1 )
10567
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
10568
       else
10569
           test_ok ;
10570
    end
10571
    join
10572
 
10573
    // predict the address and control signals on WB bus
10574
    expect_we      = 1'b0 ; // READ
10575
 
10576
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
10577
    $display("Memory read through PCI bridge to WB slave!");
10578
 
10579
    if ( expect_length_wr == 1 )
10580
    begin
10581
        if (Set_prefetch_enable)
10582
        begin
10583
            expect_length_rd1 = Cache_lsize ;
10584
            expect_length_rd2 = 0 ;
10585
                // If PCI behavioral master must check received DATA
10586
                master2_check_received_data = 0 ;
10587
                    master1_check_received_data = 0 ;
10588
        end
10589
        else
10590
        begin
10591
            expect_length_rd1 = 1 ;
10592
            expect_length_rd2 = 0 ;
10593
                // If PCI behavioral master must check received DATA
10594
                master2_check_received_data = 1 ;
10595
                    master1_check_received_data = 1 ;
10596
        end
10597
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10598
        expect_length_rd  = expect_length_rd1 ;
10599
    end
10600
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
10601
    begin
10602
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10603
        expect_length_rd2 = 0 ;
10604
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10605
        expect_length_rd  = expect_length_rd1 ;
10606
                // If PCI behavioral master must check received DATA
10607
        master2_check_received_data = 1 ;
10608
            master1_check_received_data = 1 ;
10609
    end
10610
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
10611
    begin
10612
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
10613
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
10614
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10615
        expect_length_rd  = expect_length_rd1 ;
10616
                // If PCI behavioral master must check received DATA
10617
                master2_check_received_data = 1 ;
10618
            master1_check_received_data = 1 ;
10619
    end
10620
    else
10621
    begin
10622
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10623
        begin
10624
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10625
            expect_length_rd2 = 0 ;
10626
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10627
            expect_length_rd  = expect_length_rd1 ;
10628
                // If PCI behavioral master must check received DATA
10629
                master2_check_received_data = 0 ;
10630
                    master1_check_received_data = 0 ;
10631
        end
10632
        else
10633
        begin
10634
            if ( expect_length_wr > Cache_lsize )
10635
            begin
10636
                expect_length_rd1 = Cache_lsize ;
10637
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
10638
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10639
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10640
                else
10641
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10642
                expect_length_rd  = expect_length_rd1 ;
10643
                        // If PCI behavioral master must check received DATA
10644
                        master2_check_received_data = 1 ;
10645
                            master1_check_received_data = 1 ;
10646
            end
10647
            else
10648
            begin
10649
                expect_length_rd1 = Cache_lsize ;
10650
                expect_length_rd2 = 0 ;
10651
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10652
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10653
                else
10654
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10655
                expect_length_rd  = expect_length_wr ;
10656
                                if ( expect_length_wr == Cache_lsize )
10657
                        begin
10658
                                // If PCI behavioral master must check received DATA
10659
                                master2_check_received_data = 1 ;
10660
                                    master1_check_received_data = 1 ;
10661
                                end
10662
                                else
10663
                                begin
10664
                                // If PCI behavioral master must check received DATA
10665
                                master2_check_received_data = 0 ;
10666
                                    master1_check_received_data = 0 ;
10667
                end
10668
            end
10669
        end
10670
    end
10671
 
10672
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
10673
    expect_rd_address = expect_address ;
10674
    rd_data[31:0] = Data[31:0];
10675
    rd_be[3:0] = Be[3:0];
10676
 
10677
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
10678
    while (expect_length_rd2 > 0)
10679
    begin
10680
        // do read
10681
        $display("Read %d words!", expect_length_rd);
10682
 
10683
        fork
10684
        begin
10685
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10686
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10687
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10688
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10689
 
10690
            wb_transaction_stop( expect_length_rd - 1) ;
10691
 
10692
            do_pause( 1 ) ;
10693
        end
10694
        begin
10695
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10696
            if ( ok !== 1 )
10697
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
10698
 
10699
            repeat( 3 )
10700
                @(posedge pci_clock) ;
10701
 
10702
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10703
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10704
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10705
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10706
 
10707
            do_pause( 1 ) ;
10708
            while ( FRAME === 0 )
10709
                @(posedge pci_clock) ;
10710
 
10711
            while ( IRDY === 0 )
10712
                @(posedge pci_clock) ;
10713
 
10714
            disable monitor_error_event1 ;
10715
        end
10716
        begin:monitor_error_event1
10717
            @(error_event_int) ;
10718
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10719
            ok = 0 ;
10720
        end
10721
        join
10722
 
10723
        // increasing the starting address for PCI master and for WB transaction monitor
10724
        rd_address = rd_address + (4 * expect_length_rd) ;
10725
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
10726
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
10727
        rd_data[31:24] = Data[31:24] + expect_length_rd;
10728
        rd_data[23:16] = Data[23:16] + expect_length_rd;
10729
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
10730
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
10731
        for (i=0; i<expect_length_rd; i=i+1)
10732
            rd_be[3:0] = {Be[2:0], Be[3]};
10733
 
10734
        // set parameters for next read
10735
        if ( expect_length_rd2 == 1 )
10736
        begin
10737
                if (Set_prefetch_enable)
10738
                begin
10739
                    expect_length_rd1 = Cache_lsize ;
10740
                    expect_length_rd2 = 0 ;
10741
                        // If PCI behavioral master must check received DATA
10742
                        master2_check_received_data = 0 ;
10743
                            master1_check_received_data = 0 ;
10744
                end
10745
                else
10746
                begin
10747
                    expect_length_rd1 = 1 ;
10748
                    expect_length_rd2 = 0 ;
10749
                        // If PCI behavioral master must check received DATA
10750
                        master2_check_received_data = 1 ;
10751
                            master1_check_received_data = 1 ;
10752
                end
10753
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10754
            expect_length_rd  = expect_length_rd1 ;
10755
        end
10756
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
10757
        begin
10758
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10759
            expect_length_rd2 = 0 ;
10760
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10761
            expect_length_rd  = expect_length_rd1 ;
10762
                        // If PCI behavioral master must check received DATA
10763
                        master2_check_received_data = 1 ;
10764
                    master1_check_received_data = 1 ;
10765
        end
10766
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
10767
        begin
10768
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
10769
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
10770
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10771
            expect_length_rd  = expect_length_rd1 ;
10772
                        // If PCI behavioral master must check received DATA
10773
                        master2_check_received_data = 1 ;
10774
                    master1_check_received_data = 1 ;
10775
        end
10776
        else
10777
        begin
10778
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
10779
            begin
10780
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
10781
                expect_length_rd2 = 0 ;
10782
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
10783
                expect_length_rd  = expect_length_rd1 ;
10784
                        // If PCI behavioral master must check received DATA
10785
                        master2_check_received_data = 0 ;
10786
                            master1_check_received_data = 0 ;
10787
            end
10788
            else
10789
            begin
10790
                if ( expect_length_rd2 > Cache_lsize )
10791
                begin
10792
                    expect_length_rd1 = Cache_lsize ;
10793
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
10794
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10795
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10796
                    else
10797
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10798
                    expect_length_rd  = expect_length_rd1 ;
10799
                                // If PCI behavioral master must check received DATA
10800
                                master2_check_received_data = 1 ;
10801
                                    master1_check_received_data = 1 ;
10802
                end
10803
                else
10804
                begin
10805
                    expect_length_rd  = expect_length_rd2 ;
10806
                    expect_length_rd1 = Cache_lsize ;
10807
                    expect_length_rd2 = 0 ;
10808
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
10809
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
10810
                    else
10811
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
10812
                                        if ( expect_length_rd2 == Cache_lsize )
10813
                                begin
10814
                                        // If PCI behavioral master must check received DATA
10815
                                        master2_check_received_data = 1 ;
10816
                                            master1_check_received_data = 1 ;
10817
                                        end
10818
                                        else
10819
                                        begin
10820
                                        // If PCI behavioral master must check received DATA
10821
                                        master2_check_received_data = 0 ;
10822
                                            master1_check_received_data = 0 ;
10823
                        end
10824
                end
10825
            end
10826
        end
10827
    end
10828
    // do last read
10829
    $display("Read %d words!", expect_length_rd);
10830
 
10831
    fork
10832
    begin
10833
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10834
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10835
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10836
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
10837
 
10838
        wb_transaction_stop(expect_length_rd - 1) ;
10839
        do_pause( 1 ) ;
10840
    end
10841
    begin
10842
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
10843
 
10844
        do_pause(3) ;
10845
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
10846
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
10847
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
10848
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
10849
        do_pause(1) ;
10850
 
10851
        while ( FRAME === 0 )
10852
            @(posedge pci_clock) ;
10853
 
10854
        while ( IRDY === 0 )
10855
            @(posedge pci_clock) ;
10856
 
10857
        disable monitor_error_event2 ;
10858
    end
10859
    begin:monitor_error_event2
10860
        @(error_event_int) ;
10861
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
10862
        ok = 0 ;
10863
    end
10864
    join
10865
 
10866
    if ( ok )
10867
        test_ok ;
10868
 
10869
    // Check that no ERRORs were reported
10870
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
10871
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
10872
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10873
    config_read( addr_offset, 4'hF, read_data ) ;
10874
    if ( read_data[8] !== 0 )
10875
    begin
10876
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
10877
        test_fail("error status was set even though no errors occured on WB bus") ;
10878
    end
10879
    else
10880
    begin
10881
        $display("No error was signaled, as expected!");
10882
        test_ok ;
10883
    end
10884
 
10885
end // main
10886
endtask // test_normal_wr_rd
10887
 
10888
// Test erroneous write to WB slave
10889
task test_wb_error_wr;
10890
  input  [2:0]  Master_ID;
10891
  input  [PCI_BUS_DATA_RANGE:0] Address;
10892
  input  [PCI_BUS_DATA_RANGE:0] Data;
10893
  input  [3:0]  Be;
10894
  input  [2:0]  Image_num;
10895
  input  [9:0]  Set_size;
10896
  input         Set_err_and_int_report;
10897
  input         Set_wb_wait_states;
10898
  input  [1:0]  Imm_BefLast_Last_error;
10899
 
10900
  reg    [11:0] addr_offset;
10901
  reg    [31:0] read_data;
10902
  reg           continue ;
10903
  reg           ok   ;
10904
  reg    [9:0]  expect_length ;
10905
  reg    [31:0] expect_address ;
10906
  reg    [0:0]  expect_we ;
10907
  reg    [31:0] rd_address;
10908
  reg    [31:0] rd_data;
10909
  reg    [3:0]  rd_be;
10910
  integer       i ;
10911
begin:main
10912
    if (Set_err_and_int_report)
10913
    begin
10914
        // enable ERROR reporting, because error must be reported and interrupt if required!
10915
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10916
        $display(" - errors will be reported when they will occur!");
10917
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
10918
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10919
        $display(" - interrupt will be reported when error will occur!");
10920
    end
10921
    else
10922
    begin
10923
        // disable ERROR reporting, because error and interrupt must not be reported!
10924
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
10925
        $display(" - errors will NOT be reported when they will occur!");
10926
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
10927
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
10928
        $display(" - interrupt will NOT be reported when error will occur!");
10929
    end
10930
    // enable/disable ERROR reporting
10931
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
10932
 
10933
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
10934
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
10935
    if ( ok !== 1 )
10936
    begin
10937
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
10938
        test_fail("PCI Error Control and Status register could not be written") ;
10939
        disable main;
10940
    end
10941
    // enable/disable INTERRUPT reporting
10942
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
10943
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
10944
    if ( ok !== 1 )
10945
    begin
10946
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
10947
        test_fail("Interrupt Control register could not be written") ;
10948
        disable main;
10949
    end
10950
 
10951
    `ifdef  ADDR_TRAN_IMPL
10952
 
10953
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
10954
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
10955
    config_read( addr_offset, 4'hF, read_data ) ;
10956
    if ( read_data[2] !== 0 )
10957
    begin
10958
        $display("Address translation is set for PCI image%d!", Image_num);
10959
        // predict the address and control signals on WB bus
10960
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
10961
        expect_we      = 1'b1 ; // WRITE
10962
    end
10963
    else
10964
    begin
10965
        $display("Address translation is NOT set for PCI image%d!", Image_num);
10966
        // predict the address and control signals on WB bus
10967
        expect_address = Address ;
10968
        expect_we      = 1'b1 ; // WRITE
10969
    end
10970
 
10971
    `else
10972
 
10973
    // address translation is not implemented
10974
    $display("Address translation is NOT implemented for PCI images!");
10975
    // predict the address and control signals on WB bus
10976
    expect_address = Address ;
10977
    expect_we      = 1'b1 ; // WRITE
10978
 
10979
    `endif
10980
 
10981
    if ( Set_size > (`PCIW_DEPTH - 2) )
10982
    begin
10983
        expect_length = `PCIW_DEPTH - 2 ;
10984
    end
10985
    else
10986
    begin
10987
        expect_length = Set_size ;
10988
    end
10989
 
10990
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
10991
    begin
10992
        $display("ERR termination with first data!");
10993
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
10994
    end
10995
    else if (Imm_BefLast_Last_error == 1)
10996
    begin
10997
        $display("ERR termination before last data!");
10998
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
10999
    end
11000
    else
11001
    begin
11002
        $display("ERR termination with last data!");
11003
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
11004
    end
11005
 
11006
    // write through the PCI bridge to WB slave
11007
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
11008
    fork
11009
    begin
11010
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
11011
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
11012
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11013
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
11014
        do_pause( 1 ) ;
11015
    end
11016
    begin
11017
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11018
        begin
11019
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
11020
            if ( ok !== 1 )
11021
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11022
        end
11023
        else if (Imm_BefLast_Last_error == 1)
11024
        begin
11025
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
11026
            if ( ok !== 1 )
11027
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11028
        end
11029
        else
11030
        begin
11031
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
11032
            if ( ok !== 1 )
11033
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
11034
        end
11035
    end
11036
    begin
11037
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11038
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11039
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11040
        else if (Imm_BefLast_Last_error == 1)
11041
        begin
11042
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
11043
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11044
            wb_transaction_stop(expect_length-2) ;
11045
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11046
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11047
        end
11048
        else
11049
        begin
11050
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
11051
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11052
            wb_transaction_stop(expect_length-1) ;
11053
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11054
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11055
        end
11056
    end
11057
    join
11058
 
11059
    if ( ok )
11060
        test_ok ;
11061
 
11062
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
11063
    begin
11064
        rd_data[31:0] = Data[31:0];
11065
        rd_address[31:0] = expect_address;
11066
        rd_be[3:0] = Be[3:0];
11067
    end
11068
    else if (Imm_BefLast_Last_error == 1)
11069
    begin
11070
        rd_data[31:24] = Data[31:24] + expect_length - 2;
11071
        rd_data[23:16] = Data[23:16] + expect_length - 2;
11072
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
11073
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
11074
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
11075
        rd_be[3:0] = Be[3:0];
11076
        for (i=0; i<(expect_length-2); i=i+1)
11077
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11078
    end
11079
    else
11080
    begin
11081
        rd_data[31:24] = Data[31:24] + expect_length - 1;
11082
        rd_data[23:16] = Data[23:16] + expect_length - 1;
11083
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
11084
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
11085
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
11086
        rd_be[3:0] = Be[3:0];
11087
        for (i=0; i<(expect_length-1); i=i+1)
11088
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
11089
    end
11090
 
11091
    master2_check_received_data = 0 ;
11092
    master1_check_received_data = 0 ;
11093
 
11094
    // Check if ERRORs were reported
11095
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
11096
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11097
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
11098
 
11099
    ok = 1 ;
11100
    config_read( addr_offset, 4'hF, read_data ) ;
11101
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
11102
    begin
11103
        $display("Error was signaled and reported, as expected!");
11104
        if (read_data[31:28] === rd_be)
11105
            $display("Byte enables written into P_ERR_CS register are as expected!");
11106
        else
11107
        begin
11108
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
11109
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
11110
            ok = 0 ;
11111
        end
11112
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
11113
            $display("Bus command written into P_ERR_CS register is as expected!");
11114
        else
11115
        begin
11116
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
11117
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
11118
            ok = 0 ;
11119
        end
11120
 
11121
        if ( ok )
11122
            test_ok ;
11123
 
11124
        $display("Reading the PCI Error Data register P_ERR_DATA.");
11125
 
11126
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11127
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
11128
        config_read( addr_offset, 4'hF, read_data ) ;
11129
        if (read_data === rd_data)
11130
        begin
11131
            $display("Data written into P_ERR_DATA register is as expected!");
11132
            test_ok ;
11133
        end
11134
        else
11135
        begin
11136
            $display("Data written into P_ERR_DATA register is NOT as expected!");
11137
            test_fail("PCI Erroneous Data register value was wrong") ;
11138
        end
11139
 
11140
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
11141
 
11142
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11143
 
11144
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
11145
        config_read( addr_offset, 4'hF, read_data ) ;
11146
        if (read_data === rd_address)
11147
        begin
11148
            $display("Address written into P_ERR_ADDR register is as expected!");
11149
            test_ok ;
11150
        end
11151
        else
11152
        begin
11153
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
11154
            test_fail("PCI Erroneous Address register value was wrong") ;
11155
        end
11156
    end
11157
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
11158
    begin
11159
        $display("Error was signaled and not reported, as expected!");
11160
        test_ok ;
11161
    end
11162
    else
11163
    begin
11164
        $display("Error was signaled and reported, as NOT expected!");
11165
        test_fail("Error status bit was set event though error reporting was disabled") ;
11166
    end
11167
 
11168
    // Check if Interrupts were reported
11169
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
11170
 
11171
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11172
    ok = 1 ;
11173
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11174
    config_read( addr_offset, 4'hF, read_data ) ;
11175
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
11176
    begin
11177
        $display("Interrupts was signaled and reported, as expected!");
11178
    end
11179
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
11180
    begin
11181
        $display("Interrupts was signaled and not reported, as expected!");
11182
    end
11183
    else
11184
    begin
11185
        $display("Interrupt was signaled and reported, as NOT expected!");
11186
        test_fail("PCI Error Interrupt status was set when not expected") ;
11187
        ok = 0 ;
11188
    end
11189
 
11190
    `ifdef HOST
11191
    repeat( 4 )
11192
        @(posedge wb_clock) ;
11193
 
11194
    if ( INT_O === Set_err_and_int_report )
11195
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
11196
    else
11197
    begin
11198
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
11199
        test_fail("Interrupt request didn't have expected value") ;
11200
        ok = 0 ;
11201
    end
11202
 
11203
    `else // GUEST
11204
    repeat( 4 )
11205
        @(posedge pci_clock) ;
11206
 
11207
    if ( INTA === !Set_err_and_int_report )
11208
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
11209
    else
11210
    begin
11211
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
11212
        test_fail("Interrupt request didn't have expected value") ;
11213
        ok = 0 ;
11214
    end
11215
 
11216
    `endif
11217
 
11218
    if ( ok )
11219
        test_ok ;
11220
 
11221
    if (Set_err_and_int_report)
11222
    begin
11223
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
11224
        $display("Error and Interrupt must be cleared!");
11225
        // clear  ERROR reporting bit
11226
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11227
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
11228
        if ( ok !== 1 )
11229
        begin
11230
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11231
            test_fail("PCI Error Control and Status register could not be written to") ;
11232
            disable main;
11233
        end
11234
 
11235
        // clear INTERRUPT reporting bit
11236
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
11237
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
11238
        if ( ok !== 1 )
11239
        begin
11240
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
11241
            test_fail("Interrupt Status register could not be written to") ;
11242
            disable main;
11243
        end
11244
 
11245
        test_ok ;
11246
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
11247
        `ifdef HOST
11248
 
11249
        repeat(4)
11250
            @(posedge wb_clock) ;
11251
        if ( INT_O === 1'b0 )
11252
        begin
11253
            $display("Interrupt pin INT_O was correctly cleared!");
11254
            test_ok ;
11255
        end
11256
        else
11257
        begin
11258
            $display("Interrupt pin INT_O was NOT correctly cleared!");
11259
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11260
            disable main;
11261
        end
11262
 
11263
        `else // GUEST
11264
 
11265
        repeat(4)
11266
            @(posedge pci_clock) ;
11267
        if ( INTA === 1'b1 )
11268
        begin
11269
            $display("Interrupt pin INTA was correctly cleared!");
11270
            test_ok ;
11271
        end
11272
        else
11273
        begin
11274
            $display("Interrupt pin INTA was NOT correctly cleared!");
11275
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
11276
            disable main;
11277
        end
11278
 
11279
        `endif
11280
 
11281
    end
11282
    else
11283
    begin
11284
        $display("Error and Interrupt don't need to be cleared!");
11285
    end
11286
end // main
11287
endtask // test_wb_error_wr
11288
 
11289
task test_wb_error_rd;
11290
    reg    [11:0] addr_offset ;
11291
    reg    [11:0] ctrl_offset ;
11292
    reg    [11:0] ba_offset ;
11293
    reg    [11:0] am_offset ;
11294
    reg    [11:0] ta_offset ;
11295
    reg    [31:0] read_data;
11296
    reg           ok   ;
11297
    reg    [9:0]  expect_length ;
11298
    reg    [31:0] expect_address ;
11299
    reg    [0:0]  expect_we ;
11300
    reg    [31:0] rd_address;
11301
    reg    [31:0] rd_data;
11302
    reg    [3:0]  rd_be;
11303
    integer       i ;
11304
    reg           do_mem_aborts ;
11305
    reg           do_io_aborts ;
11306
begin:main
11307
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
11308
 
11309
    if ( target_mem_image !== -1 )
11310
    begin
11311
        do_mem_aborts = 1 ;
11312
 
11313
        if (target_mem_image === 1)
11314
        begin
11315
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
11316
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
11317
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
11318
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
11319
        end
11320
        else if (target_mem_image === 2)
11321
        begin
11322
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
11323
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
11324
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
11325
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
11326
        end
11327
        else if (target_mem_image === 3)
11328
        begin
11329
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
11330
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
11331
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
11332
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
11333
        end
11334
        else if (target_mem_image === 4)
11335
        begin
11336
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
11337
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
11338
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
11339
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
11340
        end
11341
        else if (target_mem_image === 5)
11342
        begin
11343
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
11344
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
11345
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
11346
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
11347
        end
11348
    end
11349
    else
11350
        do_mem_aborts = 0 ;
11351
 
11352
    if ( do_mem_aborts )
11353
    begin
11354
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
11355
 
11356
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11357
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
11358
        if ( ok !== 1 )
11359
        begin
11360
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
11361
            test_fail("PCI Error Control and Status register could not be written") ;
11362
            disable main;
11363
        end
11364
 
11365
        // enable INTERRUPT reporting
11366
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
11367
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
11368
        if ( ok !== 1 )
11369
        begin
11370
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
11371
            test_fail("Interrupt Control register could not be written") ;
11372
            disable main;
11373
        end
11374
 
11375
        addr_offset = 12'h010 + (4*target_mem_image) ;
11376
 
11377
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
11378
        if ( ok !== 1 )
11379
        begin
11380
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
11381
            test_fail("PCI Base Address register could not be written") ;
11382
            disable main;
11383
        end
11384
 
11385
        // disable address translation and enable prefetch so read bursts can be performed
11386
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
11387
        if ( ok !== 1 )
11388
        begin
11389
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
11390
            test_fail("PCI Image Control register could not be written") ;
11391
            disable main;
11392
        end
11393
 
11394
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
11395
        if ( ok !== 1 )
11396
        begin
11397
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
11398
            test_fail("PCI Address Mask register could not be written") ;
11399
            disable main;
11400
        end
11401
 
11402
        addr_offset = 12'h00C ;
11403
 
11404
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
11405
        if ( ok !== 1 )
11406
        begin
11407
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
11408
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
11409
            disable main;
11410
        end
11411
 
11412
        // disable PCI master data checking
11413
        master1_check_received_data = 0 ;
11414
 
11415
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
11416
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11417
 
11418
 
11419
        // do a single read error terminated on WB bus
11420
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
11421
 
11422
        fork
11423
        begin
11424
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11425
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11426
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11427
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
11428
 
11429
            do_pause( 1 ) ;
11430
        end
11431
        begin
11432
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11433
 
11434
            if ( ok !== 1 )
11435
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11436
 
11437
            do_pause(3) ;
11438
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11439
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11440
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11441
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11442
            do_pause(1) ;
11443
 
11444
            while ( FRAME === 0 )
11445
                @(posedge pci_clock) ;
11446
 
11447
            while ( IRDY === 0 )
11448
                @(posedge pci_clock) ;
11449
 
11450
            disable monitor_error_event1 ;
11451
        end
11452
        begin:monitor_error_event1
11453
            @(error_event_int) ;
11454
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11455
            ok = 0 ;
11456
        end
11457
        join
11458
 
11459
        if ( ok )
11460
            test_ok ;
11461 26 mihad
 
11462
        @(posedge pci_clock) ;
11463
        @(posedge pci_clock) ;
11464
        @(posedge wb_clock) ;
11465
        @(posedge wb_clock) ;
11466 15 mihad
 
11467
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11468
        addr_offset = 12'h004 ;
11469
        config_read(addr_offset, 4'hF, read_data) ;
11470
        ok = 1 ;
11471
        if ( read_data[27] !== 1 )
11472
        begin
11473
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11474
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11475
            ok = 0 ;
11476
        end
11477
        if ( read_data[28] !== 0 )
11478
        begin
11479
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11480
            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") ;
11481
            ok = 0 ;
11482
        end
11483
        if ( read_data[29] !== 0 )
11484
        begin
11485
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11486
            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") ;
11487
            ok = 0 ;
11488
        end
11489
 
11490
        // clear statuses
11491
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11492
        if ( !ok )
11493
        begin
11494
            test_fail("write to PCI Device Status register failed") ;
11495
            $display("Couldn't write PCI Device Status register") ;
11496
            disable main ;
11497
        end
11498
 
11499
        if ( ok )
11500
            test_ok ;
11501
 
11502
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11503
 
11504
        ok = 1 ;
11505
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11506
 
11507
        config_read(addr_offset, 4'hF, read_data) ;
11508
        if (read_data[8] !== 0)
11509
        begin
11510
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11511
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11512
            ok = 0 ;
11513
        end
11514
        else
11515
            test_ok ;
11516
 
11517
        if ( ok !== 1 )
11518
        begin
11519
            config_write(addr_offset, read_data, 4'hF, ok) ;
11520
            if ( !ok )
11521
            begin
11522
                test_fail("PCI Error Control and Status register could not be written") ;
11523
                disable main ;
11524
            end
11525
        end
11526
 
11527
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11528
        fork
11529
        begin
11530
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11531
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11532
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11533
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11534
 
11535
            do_pause( 1 ) ;
11536
        end
11537
        begin
11538
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11539
 
11540
            if ( ok !== 1 )
11541
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11542
 
11543
            do_pause(3) ;
11544
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11545
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
11546
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11547
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11548
            do_pause(1) ;
11549
 
11550
            while ( FRAME === 0 )
11551
                @(posedge pci_clock) ;
11552
 
11553
            while ( IRDY === 0 )
11554
                @(posedge pci_clock) ;
11555
 
11556
            disable monitor_error_event2 ;
11557
        end
11558
        begin:monitor_error_event2
11559
            @(error_event_int) ;
11560
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11561
            ok = 0 ;
11562
        end
11563
        join
11564
 
11565
        if ( ok )
11566
            test_ok ;
11567
 
11568 26 mihad
        @(posedge pci_clock) ;
11569
        @(posedge pci_clock) ;
11570
        @(posedge wb_clock) ;
11571
        @(posedge wb_clock) ;
11572
 
11573 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11574
        addr_offset = 12'h004 ;
11575
        config_read(addr_offset, 4'hF, read_data) ;
11576
        ok = 1 ;
11577
        if ( read_data[27] !== 1 )
11578
        begin
11579
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11580
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11581
            ok = 0 ;
11582
        end
11583
        if ( read_data[28] !== 0 )
11584
        begin
11585
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11586
            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") ;
11587
            ok = 0 ;
11588
        end
11589
        if ( read_data[29] !== 0 )
11590
        begin
11591
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11592
            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") ;
11593
            ok = 0 ;
11594
        end
11595
 
11596
        // clear statuses
11597
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11598
        if ( !ok )
11599
        begin
11600
            test_fail("write to PCI Device Status register failed") ;
11601
            $display("Couldn't write PCI Device Status register") ;
11602
            disable main ;
11603
        end
11604
 
11605
        if ( ok )
11606
            test_ok ;
11607
 
11608
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11609
 
11610
        ok = 1 ;
11611
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11612
 
11613
        config_read(addr_offset, 4'hF, read_data) ;
11614
        if (read_data[8] !== 0)
11615
        begin
11616
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11617
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11618
            ok = 0 ;
11619
        end
11620
        else
11621
            test_ok ;
11622
 
11623
        if ( ok !== 1 )
11624
        begin
11625
            config_write(addr_offset, read_data, 4'hF, ok) ;
11626
            if ( !ok )
11627
            begin
11628
                test_fail("PCI Error Control and Status register could not be written") ;
11629
                disable main ;
11630
            end
11631
        end
11632
 
11633
        // do a single read error terminated on WB bus
11634
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
11635
 
11636
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11637
 
11638
        fork
11639
        begin
11640
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11641
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11642
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11643
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11644
 
11645
            do_pause( 1 ) ;
11646
        end
11647
        begin
11648
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
11649
 
11650
            if ( ok !== 1 )
11651
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11652
 
11653
            do_pause(3) ;
11654
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11655
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11656
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11657
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11658
            do_pause(1) ;
11659
 
11660
            while ( FRAME === 0 )
11661
                @(posedge pci_clock) ;
11662
 
11663
            while ( IRDY === 0 )
11664
                @(posedge pci_clock) ;
11665
 
11666
            disable monitor_error_event3 ;
11667
        end
11668
        begin:monitor_error_event3
11669
            @(error_event_int) ;
11670
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11671
            ok = 0 ;
11672
        end
11673
        join
11674
 
11675
        if ( ok )
11676
            test_ok ;
11677
 
11678 26 mihad
        @(posedge pci_clock) ;
11679
        @(posedge pci_clock) ;
11680
        @(posedge wb_clock) ;
11681
        @(posedge wb_clock) ;
11682
 
11683 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11684
        addr_offset = 12'h004 ;
11685
        config_read(addr_offset, 4'hF, read_data) ;
11686
        ok = 1 ;
11687
        if ( read_data[27] !== 1 )
11688
        begin
11689
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11690
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11691
            ok = 0 ;
11692
        end
11693
        if ( read_data[28] !== 0 )
11694
        begin
11695
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11696
            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") ;
11697
            ok = 0 ;
11698
        end
11699
        if ( read_data[29] !== 0 )
11700
        begin
11701
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11702
            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") ;
11703
            ok = 0 ;
11704
        end
11705
 
11706
        // clear statuses
11707
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11708
        if ( !ok )
11709
        begin
11710
            test_fail("write to PCI Device Status register failed") ;
11711
            $display("Couldn't write PCI Device Status register") ;
11712
            disable main ;
11713
        end
11714
 
11715
        if ( ok )
11716
            test_ok ;
11717
 
11718
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11719
 
11720
        ok = 1 ;
11721
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11722
 
11723
        config_read(addr_offset, 4'hF, read_data) ;
11724
        if (read_data[8] !== 0)
11725
        begin
11726
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11727
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11728
            ok = 0 ;
11729
        end
11730
        else
11731
            test_ok ;
11732
 
11733
        if ( ok !== 1 )
11734
        begin
11735
            config_write(addr_offset, read_data, 4'hF, ok) ;
11736
            if ( !ok )
11737
            begin
11738
                test_fail("PCI Error Control and Status register could not be written") ;
11739
                disable main ;
11740
            end
11741
        end
11742
 
11743
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
11744
 
11745
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11746
 
11747
        fork
11748
        begin
11749
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11750
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11751
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11752
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11753
 
11754
            do_pause( 1 ) ;
11755
        end
11756
        begin
11757
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
11758
 
11759
            if ( ok !== 1 )
11760
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11761
 
11762
            do_pause(3) ;
11763
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11764
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11765
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11766
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11767
            do_pause(1) ;
11768
 
11769
            while ( FRAME === 0 )
11770
                @(posedge pci_clock) ;
11771
 
11772
            while ( IRDY === 0 )
11773
                @(posedge pci_clock) ;
11774
 
11775
            disable monitor_error_event4 ;
11776
        end
11777
        begin:monitor_error_event4
11778
            @(error_event_int) ;
11779
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11780
            ok = 0 ;
11781
        end
11782
        begin
11783
            wb_transaction_stop( 1 ) ;
11784
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11785
        end
11786
        join
11787
 
11788
        if ( ok )
11789
            test_ok ;
11790
 
11791 26 mihad
        @(posedge pci_clock) ;
11792
        @(posedge pci_clock) ;
11793
        @(posedge wb_clock) ;
11794
        @(posedge wb_clock) ;
11795
 
11796 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11797
        addr_offset = 12'h004 ;
11798
        config_read(addr_offset, 4'hF, read_data) ;
11799
        ok = 1 ;
11800
        if ( read_data[27] !== 1 )
11801
        begin
11802
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11803
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11804
            ok = 0 ;
11805
        end
11806
        if ( read_data[28] !== 0 )
11807
        begin
11808
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11809
            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") ;
11810
            ok = 0 ;
11811
        end
11812
        if ( read_data[29] !== 0 )
11813
        begin
11814
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11815
            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") ;
11816
            ok = 0 ;
11817
        end
11818
 
11819
        // clear statuses
11820
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11821
        if ( !ok )
11822
        begin
11823
            test_fail("write to PCI Device Status register failed") ;
11824
            $display("Couldn't write PCI Device Status register") ;
11825
            disable main ;
11826
        end
11827
 
11828
        if ( ok )
11829
            test_ok ;
11830
 
11831
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11832
 
11833
        ok = 1 ;
11834
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11835
 
11836
        config_read(addr_offset, 4'hF, read_data) ;
11837
        if (read_data[8] !== 0)
11838
        begin
11839
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11840
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11841
            ok = 0 ;
11842
        end
11843
        else
11844
            test_ok ;
11845
 
11846
        if ( ok !== 1 )
11847
        begin
11848
            config_write(addr_offset, read_data, 4'hF, ok) ;
11849
            if ( !ok )
11850
            begin
11851
                test_fail("PCI Error Control and Status register could not be written") ;
11852
                disable main ;
11853
            end
11854
        end
11855
 
11856
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
11857
 
11858
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11859
 
11860
        fork
11861
        begin
11862
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11863
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11864
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11865
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11866
 
11867
            do_pause( 1 ) ;
11868
        end
11869
        begin
11870
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11871
 
11872
            if ( ok !== 1 )
11873
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11874
 
11875
            do_pause(3) ;
11876
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11877
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11878
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11879
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
11880
            do_pause(1) ;
11881
 
11882
            while ( FRAME === 0 )
11883
                @(posedge pci_clock) ;
11884
 
11885
            while ( IRDY === 0 )
11886
                @(posedge pci_clock) ;
11887
 
11888
            disable monitor_error_event5 ;
11889
        end
11890
        begin:monitor_error_event5
11891
            @(error_event_int) ;
11892
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
11893
            ok = 0 ;
11894
        end
11895
        begin
11896
            wb_transaction_stop( 3 ) ;
11897
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
11898
        end
11899
        join
11900
 
11901
        if ( ok )
11902
            test_ok ;
11903
 
11904 26 mihad
        @(posedge pci_clock) ;
11905
        @(posedge pci_clock) ;
11906
        @(posedge wb_clock) ;
11907
        @(posedge wb_clock) ;
11908
 
11909 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
11910
        addr_offset = 12'h004 ;
11911
        config_read(addr_offset, 4'hF, read_data) ;
11912
        ok = 1 ;
11913
        if ( read_data[27] !== 1 )
11914
        begin
11915
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
11916
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
11917
            ok = 0 ;
11918
        end
11919
        if ( read_data[28] !== 0 )
11920
        begin
11921
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11922
            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") ;
11923
            ok = 0 ;
11924
        end
11925
        if ( read_data[29] !== 0 )
11926
        begin
11927
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
11928
            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") ;
11929
            ok = 0 ;
11930
        end
11931
 
11932
        // clear statuses
11933
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
11934
        if ( !ok )
11935
        begin
11936
            test_fail("write to PCI Device Status register failed") ;
11937
            $display("Couldn't write PCI Device Status register") ;
11938
            disable main ;
11939
        end
11940
 
11941
        if ( ok )
11942
            test_ok ;
11943
 
11944
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
11945
 
11946
        ok = 1 ;
11947
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
11948
 
11949
        config_read(addr_offset, 4'hF, read_data) ;
11950
        if (read_data[8] !== 0)
11951
        begin
11952
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
11953
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
11954
            ok = 0 ;
11955
        end
11956
        else
11957
            test_ok ;
11958
 
11959
        if ( ok !== 1 )
11960
        begin
11961
            config_write(addr_offset, read_data, 4'hF, ok) ;
11962
            if ( !ok )
11963
            begin
11964
                test_fail("PCI Error Control and Status register could not be written") ;
11965
                disable main ;
11966
            end
11967
        end
11968
 
11969
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
11970
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
11971
        fork
11972
        begin
11973
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11974
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11975
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11976
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
11977
 
11978
            do_pause( 1 ) ;
11979
        end
11980
        begin
11981
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
11982
 
11983
            if ( ok !== 1 )
11984
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
11985
 
11986
            do_pause(3) ;
11987
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
11988
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
11989
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
11990
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
11991
            do_pause(1) ;
11992
 
11993
            while ( FRAME === 0 )
11994
                @(posedge pci_clock) ;
11995
 
11996
            while ( IRDY === 0 )
11997
                @(posedge pci_clock) ;
11998
 
11999
            disable monitor_error_event6 ;
12000
        end
12001
        begin:monitor_error_event6
12002
            @(error_event_int) ;
12003
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12004
            ok = 0 ;
12005
        end
12006
        begin
12007
            wb_transaction_stop( 3 ) ;
12008
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12009
        end
12010
        join
12011
 
12012
        if ( ok )
12013
            test_ok ;
12014
 
12015 26 mihad
        @(posedge pci_clock) ;
12016
        @(posedge pci_clock) ;
12017
        @(posedge wb_clock) ;
12018
        @(posedge wb_clock) ;
12019
 
12020 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12021
        addr_offset = 12'h004 ;
12022
        config_read(addr_offset, 4'hF, read_data) ;
12023
        ok = 1 ;
12024
        if ( read_data[27] !== 1 )
12025
        begin
12026
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12027
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12028
            ok = 0 ;
12029
        end
12030
        if ( read_data[28] !== 0 )
12031
        begin
12032
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12033
            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") ;
12034
            ok = 0 ;
12035
        end
12036
        if ( read_data[29] !== 0 )
12037
        begin
12038
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12039
            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") ;
12040
            ok = 0 ;
12041
        end
12042
 
12043
        // clear statuses
12044
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12045
        if ( !ok )
12046
        begin
12047
            test_fail("write to PCI Device Status register failed") ;
12048
            $display("Couldn't write PCI Device Status register") ;
12049
            disable main ;
12050
        end
12051
 
12052
        if ( ok )
12053
            test_ok ;
12054
 
12055
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12056
 
12057
        ok = 1 ;
12058
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12059
 
12060
        config_read(addr_offset, 4'hF, read_data) ;
12061
        if (read_data[8] !== 0)
12062
        begin
12063
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12064
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12065
            ok = 0 ;
12066
        end
12067
        else
12068
            test_ok ;
12069
 
12070
        if ( ok !== 1 )
12071
        begin
12072
            config_write(addr_offset, read_data, 4'hF, ok) ;
12073
            if ( !ok )
12074
            begin
12075
                test_fail("PCI Error Control and Status register could not be written") ;
12076
                disable main ;
12077
            end
12078
        end
12079
 
12080
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
12081
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12082
        fork
12083
        begin
12084
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12085
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12086
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12087
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12088
 
12089
            do_pause( 1 ) ;
12090
        end
12091
        begin
12092
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12093
 
12094
            if ( ok !== 1 )
12095
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12096
 
12097
            do_pause(3) ;
12098
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12099
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12100
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12101
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
12102
            do_pause(1) ;
12103
 
12104
            while ( FRAME === 0 )
12105
                @(posedge pci_clock) ;
12106
 
12107
            while ( IRDY === 0 )
12108
                @(posedge pci_clock) ;
12109
 
12110
            disable monitor_error_event7 ;
12111
        end
12112
        begin:monitor_error_event7
12113
            @(error_event_int) ;
12114
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12115
            ok = 0 ;
12116
        end
12117
        begin
12118
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12119
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12120
        end
12121
        join
12122
 
12123
        if ( ok )
12124
            test_ok ;
12125
 
12126 26 mihad
        @(posedge pci_clock) ;
12127
        @(posedge pci_clock) ;
12128
        @(posedge wb_clock) ;
12129
        @(posedge wb_clock) ;
12130
 
12131 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12132
        addr_offset = 12'h004 ;
12133
        config_read(addr_offset, 4'hF, read_data) ;
12134
        ok = 1 ;
12135
        if ( read_data[27] !== 1 )
12136
        begin
12137
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12138
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12139
            ok = 0 ;
12140
        end
12141
        if ( read_data[28] !== 0 )
12142
        begin
12143
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12144
            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") ;
12145
            ok = 0 ;
12146
        end
12147
        if ( read_data[29] !== 0 )
12148
        begin
12149
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12150
            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") ;
12151
            ok = 0 ;
12152
        end
12153
 
12154
        // clear statuses
12155
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12156
        if ( !ok )
12157
        begin
12158
            test_fail("write to PCI Device Status register failed") ;
12159
            $display("Couldn't write PCI Device Status register") ;
12160
            disable main ;
12161
        end
12162
 
12163
        if ( ok )
12164
            test_ok ;
12165
 
12166
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12167
 
12168
        ok = 1 ;
12169
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12170
 
12171
        config_read(addr_offset, 4'hF, read_data) ;
12172
        if (read_data[8] !== 0)
12173
        begin
12174
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12175
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12176
            ok = 0 ;
12177
        end
12178
        else
12179
            test_ok ;
12180
 
12181
        if ( ok !== 1 )
12182
        begin
12183
            config_write(addr_offset, read_data, 4'hF, ok) ;
12184
            if ( !ok )
12185
            begin
12186
                test_fail("PCI Error Control and Status register could not be written") ;
12187
                disable main ;
12188
            end
12189
        end
12190
 
12191
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
12192
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12193
        fork
12194
        begin
12195
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12196
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12197
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12198
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12199
 
12200
            do_pause( 1 ) ;
12201
        end
12202
        begin
12203
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
12204
 
12205
            if ( ok !== 1 )
12206
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12207
 
12208
            do_pause(3) ;
12209
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12210
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
12211
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12212
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
12213
            do_pause(1) ;
12214
 
12215
            while ( FRAME === 0 )
12216
                @(posedge pci_clock) ;
12217
 
12218
            while ( IRDY === 0 )
12219
                @(posedge pci_clock) ;
12220
 
12221
            disable monitor_error_event8 ;
12222
        end
12223
        begin:monitor_error_event8
12224
            @(error_event_int) ;
12225
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12226
            ok = 0 ;
12227
        end
12228
        begin
12229
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
12230
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12231
        end
12232
        join
12233
 
12234
        if ( ok )
12235
            test_ok ;
12236
 
12237 26 mihad
        @(posedge pci_clock) ;
12238
        @(posedge pci_clock) ;
12239
        @(posedge wb_clock) ;
12240
        @(posedge wb_clock) ;
12241
 
12242 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12243
 
12244
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12245
        addr_offset = 12'h004 ;
12246
        config_read(addr_offset, 4'hF, read_data) ;
12247
        ok = 1 ;
12248
        if ( read_data[27] !== 1 )
12249
        begin
12250
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12251
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12252
            ok = 0 ;
12253
        end
12254
        if ( read_data[28] !== 0 )
12255
        begin
12256
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12257
            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") ;
12258
            ok = 0 ;
12259
        end
12260
        if ( read_data[29] !== 0 )
12261
        begin
12262
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12263
            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") ;
12264
            ok = 0 ;
12265
        end
12266
 
12267
        // clear statuses
12268
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12269
        if ( !ok )
12270
        begin
12271
            test_fail("write to PCI Device Status register failed") ;
12272
            $display("Couldn't write PCI Device Status register") ;
12273
            disable main ;
12274
        end
12275
 
12276
        if ( ok )
12277
            test_ok ;
12278
 
12279
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12280
 
12281
        ok = 1 ;
12282
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12283
 
12284
        config_read(addr_offset, 4'hF, read_data) ;
12285
        if (read_data[8] !== 0)
12286
        begin
12287
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12288
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12289
            ok = 0 ;
12290
        end
12291
        else
12292
            test_ok ;
12293
 
12294
        if ( ok !== 1 )
12295
        begin
12296
            config_write(addr_offset, read_data, 4'hF, ok) ;
12297
            if ( !ok )
12298
            begin
12299
                test_fail("PCI Error Control and Status register could not be written") ;
12300
                disable main ;
12301
            end
12302
        end
12303
 
12304
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
12305
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12306
        fork
12307
        begin
12308
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12309
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12310
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12311
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
12312
 
12313
            do_pause( 1 ) ;
12314
        end
12315
        begin
12316
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
12317
 
12318
            if ( ok !== 1 )
12319
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12320
 
12321
            do_pause(3) ;
12322
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
12323
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
12324
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12325
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12326
            do_pause(1) ;
12327
 
12328
            while ( FRAME === 0 )
12329
                @(posedge pci_clock) ;
12330
 
12331
            while ( IRDY === 0 )
12332
                @(posedge pci_clock) ;
12333
 
12334
            disable monitor_error_event9 ;
12335
        end
12336
        begin:monitor_error_event9
12337
            @(error_event_int) ;
12338
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12339
            ok = 0 ;
12340
        end
12341
        begin
12342
            wb_transaction_stop( 3 ) ;
12343
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12344
        end
12345
        join
12346
 
12347
        if ( ok )
12348
            test_ok ;
12349
 
12350
        // now check all other statuses too
12351
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
12352
        ok = 1 ;
12353
 
12354
        addr_offset = 12'h004 ;
12355
        config_read(addr_offset, 4'hF, read_data) ;
12356
        if (read_data[31] !== 0)
12357
        begin
12358
            $display("Detected Parity Error bit set for no reason") ;
12359
            test_fail("Detected Parity Error bit was set for no reason") ;
12360
            ok = 0 ;
12361
        end
12362
 
12363
        if (read_data[30] !== 0)
12364
        begin
12365
            $display("Signaled System Error bit set for no reason") ;
12366
            test_fail("Signaled System Error bit was set for no reason") ;
12367
            ok = 0 ;
12368
        end
12369
 
12370
        if (read_data[29] !== 0)
12371
        begin
12372
            $display("Received Master Abort bit set for no reason") ;
12373
            test_fail("Received Master Abort bit was set for no reason") ;
12374
            ok = 0 ;
12375
        end
12376
 
12377
        if (read_data[28] !== 0)
12378
        begin
12379
            $display("Received Target Abort bit set for no reason");
12380
            test_fail("Received Target Abort bit was set for no reason") ;
12381
            ok = 0 ;
12382
        end
12383
 
12384
        if (read_data[27] !== 0)
12385
        begin
12386
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
12387
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
12388
            ok = 0 ;
12389
        end
12390
 
12391
        if (read_data[24] !== 0)
12392
        begin
12393
            $display("Master Data Parity Error bit set for no reason") ;
12394
            test_fail("Master Data Parity Error bit was set for no reason") ;
12395
            ok = 0 ;
12396
        end
12397
 
12398
        if ( ok )
12399
            test_ok ;
12400
 
12401
        test_name = "DISABLE IMAGE" ;
12402
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12403
        if ( ok !== 1 )
12404
        begin
12405
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12406
            test_fail("PCI Address Mask register could not be written") ;
12407
            disable main;
12408
        end
12409
    end
12410
 
12411
    if ( target_io_image !== -1 )
12412
    begin
12413
        do_io_aborts = 1 ;
12414
 
12415
        if (target_io_image === 1)
12416
        begin
12417
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12418
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12419
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12420
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12421
        end
12422
        else if (target_io_image === 2)
12423
        begin
12424
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12425
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12426
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12427
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12428
        end
12429
        else if (target_io_image === 3)
12430
        begin
12431
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12432
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12433
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12434
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12435
        end
12436
        else if (target_io_image === 4)
12437
        begin
12438
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12439
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12440
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12441
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12442
        end
12443
        else if (target_io_image === 5)
12444
        begin
12445
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12446
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12447
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12448
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12449
        end
12450
    end
12451
    else
12452
        do_io_aborts = 0 ;
12453
 
12454
    if ( do_io_aborts )
12455
    begin
12456
 
12457
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
12458
 
12459
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12460
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
12461
        if ( ok !== 1 )
12462
        begin
12463
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12464
            test_fail("PCI Error Control and Status register could not be written") ;
12465
            disable main;
12466
        end
12467
 
12468
        // enable INTERRUPT reporting
12469
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12470
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
12471
        if ( ok !== 1 )
12472
        begin
12473
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
12474
            test_fail("Interrupt Control register could not be written") ;
12475
            disable main;
12476
        end
12477
 
12478
        addr_offset = 12'h010 + (4*target_io_image) ;
12479
 
12480
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
12481
        if ( ok !== 1 )
12482
        begin
12483
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
12484
            test_fail("PCI Base Address register could not be written") ;
12485
            disable main;
12486
        end
12487
 
12488
        // disable address translation and enable prefetch so read bursts can be performed
12489
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
12490
        if ( ok !== 1 )
12491
        begin
12492
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
12493
            test_fail("PCI Image Control register could not be written") ;
12494
            disable main;
12495
        end
12496
 
12497
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
12498
        if ( ok !== 1 )
12499
        begin
12500
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12501
            test_fail("PCI Address Mask register could not be written") ;
12502
            disable main;
12503
        end
12504
 
12505
        addr_offset = 12'h00C ;
12506
 
12507
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
12508
        if ( ok !== 1 )
12509
        begin
12510
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
12511
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
12512
            disable main;
12513
        end
12514
 
12515
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12516
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12517
 
12518
        // do a single read error terminated on WB bus
12519
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
12520
 
12521
        fork
12522
        begin
12523
            PCIU_IO_READ
12524
             (
12525
                `Test_Master_1,
12526
                Target_Base_Addr_R[target_io_image],
12527
                32'hAAAA_5555,
12528
                4'h0,
12529
                1,
12530
                `Test_Target_Retry_On
12531
             );
12532
 
12533
            do_pause( 1 ) ;
12534
        end
12535
        begin
12536
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
12537
 
12538
            if ( ok !== 1 )
12539
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
12540
 
12541
            do_pause(3) ;
12542
 
12543
            PCIU_IO_READ
12544
             (
12545
                `Test_Master_1,
12546
                Target_Base_Addr_R[target_io_image],
12547
                32'hAAAA_5555,
12548
                4'h0,
12549
                1,
12550
                `Test_Target_Abort_On
12551
             );
12552
 
12553
            do_pause( 1 ) ;
12554
 
12555
            while ( FRAME === 0 )
12556
                @(posedge pci_clock) ;
12557
 
12558
            while ( IRDY === 0 )
12559
                @(posedge pci_clock) ;
12560
 
12561
            disable monitor_error_event10 ;
12562
        end
12563
        begin:monitor_error_event10
12564
            @(error_event_int) ;
12565
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12566
            ok = 0 ;
12567
        end
12568
        join
12569
 
12570
        if ( ok )
12571
            test_ok ;
12572
 
12573 26 mihad
        @(posedge pci_clock) ;
12574
        @(posedge pci_clock) ;
12575
        @(posedge wb_clock) ;
12576
        @(posedge wb_clock) ;
12577
 
12578 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
12579
        addr_offset = 12'h004 ;
12580
        config_read(addr_offset, 4'hF, read_data) ;
12581
        ok = 1 ;
12582
        if ( read_data[27] !== 1 )
12583
        begin
12584
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
12585
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
12586
            ok = 0 ;
12587
        end
12588
        if ( read_data[28] !== 0 )
12589
        begin
12590
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12591
            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") ;
12592
            ok = 0 ;
12593
        end
12594
        if ( read_data[29] !== 0 )
12595
        begin
12596
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
12597
            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") ;
12598
            ok = 0 ;
12599
        end
12600
 
12601
        // clear statuses
12602
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
12603
        if ( !ok )
12604
        begin
12605
            test_fail("write to PCI Device Status register failed") ;
12606
            $display("Couldn't write PCI Device Status register") ;
12607
            disable main ;
12608
        end
12609
 
12610
        if ( ok )
12611
            test_ok ;
12612
 
12613
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12614
 
12615
        ok = 1 ;
12616
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
12617
 
12618
        config_read(addr_offset, 4'hF, read_data) ;
12619
        if (read_data[8] !== 0)
12620
        begin
12621
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
12622
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
12623
            ok = 0 ;
12624
        end
12625
        else
12626
            test_ok ;
12627
 
12628
        if ( ok !== 1 )
12629
        begin
12630
            config_write(addr_offset, read_data, 4'hF, ok) ;
12631
            if ( !ok )
12632
            begin
12633
                test_fail("PCI Error Control and Status register could not be written") ;
12634
                disable main ;
12635
            end
12636
        end
12637
 
12638
        test_name = "DISABLE IMAGE" ;
12639
        config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
12640
        if ( ok !== 1 )
12641
        begin
12642
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
12643
            test_fail("PCI Address Mask register could not be written") ;
12644
            disable main;
12645
        end
12646
 
12647
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12648
 
12649
    end
12650
end // main
12651
endtask // test_wb_error_rd
12652
 
12653
task test_target_abort ;
12654
    input [2:0]  image_num ;
12655
    reg   [11:0] pci_ctrl_offset ;
12656
    reg   [11:0] ctrl_offset ;
12657
    reg   [11:0] ba_offset ;
12658
    reg   [11:0] am_offset ;
12659
    reg   [11:0] ta_offset ;
12660
    reg   [31:0] pci_address ;
12661
    reg   [3:0]  byte_enables ;
12662
    reg          ok ;
12663
begin:main
12664
    pci_ctrl_offset = 12'h4 ;
12665
    if (image_num === 0)
12666
    begin
12667
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
12668
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
12669
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
12670
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
12671
    end
12672
    else if (image_num === 1)
12673
    begin
12674
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
12675
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
12676
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
12677
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
12678
    end
12679
    else if (image_num === 2)
12680
    begin
12681
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
12682
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
12683
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
12684
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
12685
    end
12686
    else if (image_num === 3)
12687
    begin
12688
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
12689
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
12690
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
12691
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
12692
    end
12693
    else if (image_num === 4)
12694
    begin
12695
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
12696
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
12697
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
12698
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
12699
    end
12700
    else if (image_num === 5)
12701
    begin
12702
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
12703
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
12704
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
12705
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
12706
    end
12707
 
12708
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
12709
 
12710
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
12711
    if ( ok !== 1 )
12712
    begin
12713
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
12714
        test_fail("PCI Base Address register could not be written") ;
12715
        disable main ;
12716
    end
12717
 
12718
    // Set Address Mask of IMAGE
12719
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
12720
    if ( ok !== 1 )
12721
    begin
12722
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
12723
        test_fail("PCI Address Mask register could not be written") ;
12724
        disable main ;
12725
    end
12726
 
12727
    // Set Translation Address of IMAGE
12728
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
12729
    if ( ok !== 1 )
12730
    begin
12731
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
12732
        test_fail("PCI Translation Address Register could not be written") ;
12733
        disable main ;
12734
    end
12735
 
12736
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
12737
    if ( ok !== 1 )
12738
    begin
12739
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
12740
        test_fail("PCI Image Control register could not be written") ;
12741
        disable main ;
12742
    end
12743
 
12744
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
12745
 
12746
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
12747
 
12748
    pci_address  = Target_Base_Addr_R[image_num] ;
12749
    byte_enables = 4'b0001 ;
12750
 
12751
    fork
12752
    begin
12753
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12754
        do_pause ( 1 ) ;
12755
    end
12756
    begin:monitor_error_event1
12757
        @(error_event_int) ;
12758
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12759
        ok = 0 ;
12760
    end
12761
    begin
12762
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12763
        @(posedge pci_clock) ;
12764
        disable monitor_error_event1 ;
12765
    end
12766
    join
12767
 
12768
    if ( ok )
12769
        test_ok ;
12770
 
12771
    ok = 1 ;
12772
 
12773
    fork
12774
    begin
12775
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12776
        do_pause ( 1 ) ;
12777
    end
12778
    begin:monitor_error_event2
12779
        @(error_event_int) ;
12780
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12781
        ok = 0 ;
12782
    end
12783
    begin
12784
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12785
        @(posedge pci_clock) ;
12786
        disable monitor_error_event2 ;
12787
    end
12788
    join
12789
 
12790
    if ( ok )
12791
        test_ok ;
12792
 
12793
    ok = 1 ;
12794
 
12795
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
12796
    byte_enables = 4'b0011 ;
12797
 
12798
    fork
12799
    begin
12800
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12801
        do_pause ( 1 ) ;
12802
    end
12803
    begin:monitor_error_event3
12804
        @(error_event_int) ;
12805
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12806
        ok = 0 ;
12807
    end
12808
    begin
12809
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12810
        @(posedge pci_clock) ;
12811
        disable monitor_error_event3 ;
12812
    end
12813
    join
12814
 
12815
    if ( ok )
12816
        test_ok ;
12817
 
12818
    ok = 1 ;
12819
 
12820
    byte_enables = 4'b0000 ;
12821
 
12822
    fork
12823
    begin
12824
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12825
        do_pause ( 1 ) ;
12826
    end
12827
    begin:monitor_error_event4
12828
        @(error_event_int) ;
12829
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12830
        ok = 0 ;
12831
    end
12832
    begin
12833
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12834
        @(posedge pci_clock) ;
12835
        disable monitor_error_event4 ;
12836
    end
12837
    join
12838
 
12839
    if ( ok )
12840
        test_ok ;
12841
 
12842
    ok = 1 ;
12843
 
12844
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
12845
    byte_enables = 4'b0111 ;
12846
 
12847
    fork
12848
    begin
12849
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12850
        do_pause ( 1 ) ;
12851
    end
12852
    begin:monitor_error_event5
12853
        @(error_event_int) ;
12854
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12855
        ok = 0 ;
12856
    end
12857
    begin
12858
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12859
        @(posedge pci_clock) ;
12860
        disable monitor_error_event5 ;
12861
    end
12862
    join
12863
 
12864
    if ( ok )
12865
        test_ok ;
12866
 
12867
    ok = 1 ;
12868
 
12869
    byte_enables = 4'b0010 ;
12870
 
12871
    fork
12872
    begin
12873
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12874
        do_pause ( 1 ) ;
12875
    end
12876
    begin:monitor_error_event6
12877
        @(error_event_int) ;
12878
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12879
        ok = 0 ;
12880
    end
12881
    begin
12882
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12883
        @(posedge pci_clock) ;
12884
        disable monitor_error_event6 ;
12885
    end
12886
    join
12887
 
12888
    if ( ok )
12889
        test_ok ;
12890
 
12891
    ok = 1 ;
12892
    byte_enables = 4'b0001 ;
12893
 
12894
    fork
12895
    begin
12896
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12897
        do_pause ( 1 ) ;
12898
    end
12899
    begin:monitor_error_event7
12900
        @(error_event_int) ;
12901
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12902
        ok = 0 ;
12903
    end
12904
    begin
12905
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12906
        @(posedge pci_clock) ;
12907
        disable monitor_error_event7 ;
12908
    end
12909
    join
12910
 
12911
    if ( ok )
12912
        test_ok ;
12913
 
12914
    ok = 1 ;
12915
    byte_enables = 4'b0000 ;
12916
 
12917
    fork
12918
    begin
12919
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
12920
        do_pause ( 1 ) ;
12921
    end
12922
    begin:monitor_error_event8
12923
        @(error_event_int) ;
12924
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12925
        ok = 0 ;
12926
    end
12927
    begin
12928
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12929
        @(posedge pci_clock) ;
12930
        disable monitor_error_event8 ;
12931
    end
12932
    join
12933
 
12934
    if ( ok )
12935
        test_ok ;
12936
 
12937
    ok = 1 ;
12938
 
12939
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
12940
    byte_enables = 4'b0110 ;
12941
 
12942
    fork
12943
    begin
12944
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
12945
        do_pause ( 1 ) ;
12946
    end
12947
    begin:monitor_error_event9
12948
        @(error_event_int) ;
12949
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12950
        ok = 0 ;
12951
    end
12952
    begin
12953
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12954
        @(posedge pci_clock) ;
12955
        disable monitor_error_event9 ;
12956
    end
12957
    join
12958
 
12959
    if ( ok )
12960
        test_ok ;
12961
 
12962
    ok = 1 ;
12963
    fork
12964
    begin
12965
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
12966
        do_pause ( 1 ) ;
12967
    end
12968
    begin:monitor_error_event10
12969
        @(error_event_int) ;
12970
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12971
        ok = 0 ;
12972
    end
12973
    begin
12974
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12975
        @(posedge pci_clock) ;
12976
        disable monitor_error_event10 ;
12977
    end
12978
    join
12979
 
12980
    if ( ok )
12981
        test_ok ;
12982
 
12983
    ok = 1 ;
12984
 
12985
    byte_enables = 4'b0001 ;
12986
 
12987
    fork
12988
    begin
12989
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
12990
        do_pause ( 1 ) ;
12991
    end
12992
    begin:monitor_error_event11
12993
        @(error_event_int) ;
12994
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
12995
        ok = 0 ;
12996
    end
12997
    begin
12998
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
12999
        @(posedge pci_clock) ;
13000
        disable monitor_error_event11 ;
13001
    end
13002
    join
13003
 
13004
    if ( ok )
13005
        test_ok ;
13006
 
13007
    ok = 1 ;
13008
 
13009
    byte_enables = 4'b0101 ;
13010
 
13011
    fork
13012
    begin
13013
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13014
        do_pause ( 1 ) ;
13015
    end
13016
    begin:monitor_error_event12
13017
        @(error_event_int) ;
13018
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13019
        ok = 0 ;
13020
    end
13021
    begin
13022
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13023
        @(posedge pci_clock) ;
13024
        disable monitor_error_event12 ;
13025
    end
13026
    join
13027
 
13028
    if ( ok )
13029
        test_ok ;
13030
 
13031
    ok = 1 ;
13032
 
13033
    byte_enables = 4'b0011 ;
13034
 
13035
    fork
13036
    begin
13037
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
13038
        do_pause ( 1 ) ;
13039
    end
13040
    begin:monitor_error_event13
13041
        @(error_event_int) ;
13042
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
13043
        ok = 0 ;
13044
    end
13045
    begin
13046
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
13047
        @(posedge pci_clock) ;
13048
        disable monitor_error_event13 ;
13049
    end
13050
    join
13051
 
13052
    if ( ok )
13053
        test_ok ;
13054
 
13055
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13056
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
13057
    ok = 1 ;
13058
    if ( pci_address[27] !== 1 )
13059
    begin
13060
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
13061
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
13062
        ok = 0 ;
13063
    end
13064
    if ( pci_address[28] !== 0 )
13065
    begin
13066
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
13067
        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") ;
13068
        ok = 0 ;
13069
    end
13070
    if ( pci_address[29] !== 0 )
13071
    begin
13072
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
13073
        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") ;
13074
        ok = 0 ;
13075
    end
13076
 
13077
    // clear statuses
13078
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
13079
    if ( !ok )
13080
    begin
13081
        test_fail("write to PCI Device Status register failed") ;
13082
        $display("Couldn't write PCI Device Status register") ;
13083
        disable main ;
13084
    end
13085
 
13086
    if ( ok )
13087
        test_ok ;
13088
 
13089
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
13090
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
13091
    if ( pci_address[8] !== 0 )
13092
    begin
13093
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
13094
    end
13095
    else
13096
        test_ok ;
13097
 
13098
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13099
 
13100
    test_name = "DISABLE IMAGE" ;
13101
 
13102
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
13103
    if ( ok !== 1 )
13104
    begin
13105
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
13106
        test_fail("PCI Address Mask register could not be written") ;
13107
        disable main ;
13108
    end
13109
end
13110
endtask // test_target_abort
13111
 
13112
task test_target_io_wr_rd ;
13113
    input [2:0]  image_num ;
13114
    input        translate_address ;
13115
    input [11:0] img_ctrl_offset ;
13116
    reg   [31:0] expect_address ;
13117
    reg   [31:0] pci_address ;
13118
    reg          translation ;
13119
    reg   [31:0] read_data ;
13120
    reg   [3:0]  byte_enables ;
13121
    reg          ok ;
13122
    reg          pci_ok ;
13123
    reg          wb_ok ;
13124
    integer      i ;
13125
begin:main
13126
    `ifdef ADDR_TRAN_IMPL
13127
        translation = translate_address ;
13128
    `else
13129
        translation = 0 ;
13130
    `endif
13131
 
13132
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
13133
 
13134
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13135
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13136
    if ( translation )
13137
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13138
    else
13139
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13140
 
13141
    if ( !ok )
13142
    begin
13143
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13144
        test_fail("PCI Image Control register could not be written") ;
13145
    end
13146
 
13147
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
13148
    pci_address  = Target_Base_Addr_R[image_num] ;
13149
    byte_enables = 4'b0000 ;
13150
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13151
 
13152
    fork
13153
    begin
13154
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
13155
        do_pause ( 1 ) ;
13156
    end
13157
    begin
13158
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13159
        if ( wb_ok !== 1 )
13160
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13161
 
13162
        disable monitor_pci_error_1 ;
13163
    end
13164
    begin:monitor_pci_error_1
13165
        pci_ok = 1 ;
13166
        @(error_event_int) ;
13167
        pci_ok = 0 ;
13168
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
13169
    end
13170
    join
13171
 
13172
    byte_enables = 4'b1111 ;
13173
    for ( i = 0 ; i < 4 ; i = i + 1 )
13174
    begin:loop_1
13175
        byte_enables[i] = 0 ;
13176
        if ( i > 0 )
13177
            byte_enables[i - 1] = 1 ;
13178
        fork
13179
        begin
13180
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13181
            do_pause ( 1 ) ;
13182
        end
13183
        begin
13184
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
13185
            if ( wb_ok !== 1 )
13186
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13187
 
13188
            disable monitor_pci_error_2 ;
13189
        end
13190
        begin:monitor_pci_error_2
13191
            pci_ok = 1 ;
13192
            @(error_event_int) ;
13193
            pci_ok = 0 ;
13194
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13195
        end
13196
        join
13197
 
13198
        if ( !pci_ok || !wb_ok )
13199
            disable loop_1 ;
13200
 
13201
        pci_address = pci_address + 1 ;
13202
        expect_address = expect_address + 1 ;
13203
    end
13204
 
13205
    if ( pci_ok && wb_ok )
13206
        test_ok ;
13207
 
13208
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
13209
    pci_address  = Target_Base_Addr_R[image_num] ;
13210
    byte_enables = 4'b1100 ;
13211
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13212
 
13213
    master1_check_received_data = 1 ;
13214
    fork
13215
    begin
13216
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13217
        do_pause( 1 ) ;
13218
    end
13219
    begin
13220
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13221
        if ( wb_ok !== 1 )
13222
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13223
 
13224
        do_pause ( 2 ) ;
13225
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13226
        do_pause ( 16 ) ;
13227
 
13228
        disable monitor_pci_error_3 ;
13229
    end
13230
    begin:monitor_pci_error_3
13231
        pci_ok = 1 ;
13232
        @(error_event_int) ;
13233
        pci_ok = 0 ;
13234
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13235
    end
13236
    join
13237
 
13238
    if ( !pci_ok || !wb_ok )
13239
    begin
13240
        disable main ;
13241
    end
13242
 
13243
    pci_address  = Target_Base_Addr_R[image_num] + 2;
13244
    byte_enables = 4'b0011 ;
13245
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13246
 
13247
    master1_check_received_data = 1 ;
13248
    fork
13249
    begin
13250
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13251
        do_pause( 1 ) ;
13252
    end
13253
    begin
13254
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13255
        if ( wb_ok !== 1 )
13256
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13257
 
13258
        do_pause ( 2 ) ;
13259
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13260
        do_pause ( 16 ) ;
13261
 
13262
        disable monitor_pci_error_4 ;
13263
    end
13264
    begin:monitor_pci_error_4
13265
        pci_ok = 1 ;
13266
        @(error_event_int) ;
13267
        pci_ok = 0 ;
13268
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13269
    end
13270
    join
13271
 
13272
    if ( !pci_ok || !wb_ok )
13273
    begin
13274
        disable main ;
13275
    end
13276
 
13277
    pci_address  = Target_Base_Addr_R[image_num] ;
13278
    byte_enables = 4'b0000 ;
13279
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13280
 
13281
    master1_check_received_data = 1 ;
13282
    fork
13283
    begin
13284
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
13285
        do_pause( 1 ) ;
13286
    end
13287
    begin
13288
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
13289
        if ( wb_ok !== 1 )
13290
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
13291
 
13292
        do_pause ( 2 ) ;
13293
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13294
        do_pause ( 16 ) ;
13295
 
13296
        disable monitor_pci_error_5 ;
13297
    end
13298
    begin:monitor_pci_error_5
13299
        pci_ok = 1 ;
13300
        @(error_event_int) ;
13301
        pci_ok = 0 ;
13302
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
13303
    end
13304
    join
13305
 
13306
    if ( pci_ok && wb_ok )
13307
        test_ok ;
13308
end
13309
endtask // test_target_io_wr_rd
13310
 
13311
task test_target_io_err_wr ;
13312
    input [2:0]  image_num ;
13313
    input        translate_address ;
13314
    input [11:0] img_ctrl_offset ;
13315
    input        enable_error_report ;
13316
    input        enable_error_interrupt ;
13317
 
13318
    reg   [31:0] expect_address ;
13319
    reg   [31:0] pci_address ;
13320
    reg          translation ;
13321
    reg   [31:0] read_data ;
13322
    reg   [3:0]  byte_enables ;
13323
    reg          ok ;
13324
    reg          pci_ok ;
13325
    reg          wb_ok ;
13326
    integer      i ;
13327
    reg   [11:0] offset ;
13328
begin:main
13329
    `ifdef ADDR_TRAN_IMPL
13330
        translation = translate_address ;
13331
    `else
13332
        translation = 0 ;
13333
    `endif
13334
 
13335
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
13336
 
13337
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
13338
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
13339
    if ( translation )
13340
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
13341
    else
13342
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
13343
 
13344
    if ( !ok )
13345
    begin
13346
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
13347
        test_fail("PCI Image Control register could not be written") ;
13348
    end
13349
 
13350
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
13351
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13352
    if ( enable_error_report )
13353
    begin
13354
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
13355
        if ( !ok )
13356
        begin
13357
            test_fail("PCI Error Control and Status register could not be written") ;
13358
            disable main ;
13359
        end
13360
    end
13361
    else
13362
    begin
13363
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13364
        if ( !ok )
13365
        begin
13366
            test_fail("PCI Error Control and Status register could not be written") ;
13367
            disable main ;
13368
        end
13369
    end
13370
 
13371
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
13372
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
13373
    if ( enable_error_interrupt )
13374
    begin
13375
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
13376
        if ( !ok )
13377
        begin
13378
            test_fail("Interrupt Control register could not be written") ;
13379
            disable main ;
13380
        end
13381
    end
13382
    else
13383
    begin
13384
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
13385
        if ( !ok )
13386
        begin
13387
            test_fail("Interrupt Control register could not be written") ;
13388
            disable main ;
13389
        end
13390
    end
13391
 
13392
    pci_address  = Target_Base_Addr_R[image_num] ;
13393
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
13394
 
13395
    byte_enables = 4'b1111 ;
13396
 
13397
    for ( i = 0 ; i < 4 ; i = i + 1 )
13398
    begin:loop_1
13399
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
13400
        byte_enables[i] = 0 ;
13401
        if ( i > 0 )
13402
            byte_enables[i - 1] = 1 ;
13403
 
13404
        fork
13405
        begin
13406
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
13407
            do_pause ( 1 ) ;
13408
        end
13409
        begin
13410
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
13411
            if ( wb_ok !== 1 )
13412
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
13413
 
13414
            disable monitor_pci_error_2 ;
13415
        end
13416
        begin:monitor_pci_error_2
13417
            pci_ok = 1 ;
13418
            @(error_event_int) ;
13419
            pci_ok = 0 ;
13420
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
13421
        end
13422
        join
13423
 
13424
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13425
        `ifdef HOST
13426
 
13427
            repeat ( 4 )
13428
                @( posedge wb_clock ) ;
13429
 
13430
            if ( enable_error_interrupt && enable_error_report )
13431
            begin
13432
                if ( INT_O !== 1 )
13433
                begin
13434
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
13435
                end
13436
            end
13437
            else
13438
            begin
13439
                if ( INT_O !== 0 )
13440
                begin
13441
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
13442
                end
13443
            end
13444
        `else
13445
            repeat ( 4 )
13446
                @( posedge pci_clock ) ;
13447
 
13448
            if ( enable_error_interrupt && enable_error_report )
13449
            begin
13450
                if ( INTA !== 0 )
13451
                begin
13452
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
13453
                end
13454
            end
13455
            else
13456
            begin
13457
                if ( INTA !== 1 )
13458
                begin
13459
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
13460
                end
13461
            end
13462
        `endif
13463
 
13464
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
13465
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13466
        config_read( offset, 4'hF, read_data ) ;
13467
        ok = 1 ;
13468
        if ( enable_error_report )
13469
        begin
13470
            if ( read_data[8] !== 1 )
13471
            begin
13472
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
13473
                ok = 0 ;
13474
            end
13475
 
13476
            if ( read_data[9] !== 0 )
13477
            begin
13478
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
13479
                ok = 0 ;
13480
            end
13481
 
13482
            if ( read_data[31:28] !== byte_enables )
13483
            begin
13484
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
13485
                ok = 0 ;
13486
            end
13487
 
13488
            if ( read_data[27:24] !== `BC_IO_WRITE )
13489
            begin
13490
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
13491
                ok = 0 ;
13492
            end
13493
 
13494
            if ( ok )
13495
                test_ok ;
13496
 
13497
            test_name = "CLEAR ERROR STATUS" ;
13498
            config_write( offset, read_data, 4'hF, ok ) ;
13499
            if ( !ok )
13500
                test_fail("PCI Error Control and Status register could not be written") ;
13501
 
13502
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
13503
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13504
            config_read ( offset, 4'hf, read_data ) ;
13505
 
13506
            if ( read_data !== expect_address )
13507
            begin
13508
                test_fail("value in Erroneous Address register was incorrect") ;
13509
                ok = 0 ;
13510
            end
13511
 
13512
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13513
            config_read ( offset, 4'hf, read_data ) ;
13514
 
13515
            if ( read_data !== 32'hAAAA_AAAA )
13516
            begin
13517
                test_fail("value in Erroneous Data register was incorrect") ;
13518
                ok = 0 ;
13519
            end
13520
 
13521
            if ( ok )
13522
                test_ok ;
13523
 
13524
        end
13525
        else
13526
        begin
13527
            if ( read_data[8] !== 0 )
13528
            begin
13529
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
13530
                ok = 0 ;
13531
            end
13532
            else
13533
                test_ok ;
13534
        end
13535
 
13536
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
13537
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
13538
        ok = 1 ;
13539
 
13540
        config_read ( offset, 4'hF, read_data ) ;
13541
        if ( enable_error_report && enable_error_interrupt )
13542
        begin
13543
            if ( read_data[2] !== 1 )
13544
            begin
13545
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
13546
                ok = 0 ;
13547
            end
13548
 
13549
            test_name = "CLEARING INTERRUPT STATUS" ;
13550
            config_write( offset, read_data, 4'hF, ok ) ;
13551
            if ( !ok )
13552
                test_fail("Interrupt Status register could not be written") ;
13553
        end
13554
        else
13555
        begin
13556
            if ( read_data[2] !== 0 )
13557
            begin
13558
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
13559
                ok = 0 ;
13560
            end
13561
        end
13562
 
13563
        if ( ok )
13564
            test_ok ;
13565
 
13566
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
13567
        `ifdef HOST
13568
 
13569
            repeat ( 4 )
13570
                @( posedge wb_clock ) ;
13571
 
13572
            if ( INT_O !== 0 )
13573
            begin
13574
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
13575
            end
13576
            else
13577
                test_ok ;
13578
 
13579
        `else
13580
            repeat ( 4 )
13581
                @( posedge pci_clock ) ;
13582
 
13583
            if ( INTA !== 1 )
13584
            begin
13585
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
13586
            end
13587
            else
13588
                test_ok ;
13589
 
13590
        `endif
13591
 
13592
        pci_address = pci_address + 1 ;
13593
        expect_address = expect_address + 1 ;
13594
    end
13595
 
13596
end
13597
endtask // test_target_io_err_wr
13598
 
13599
task test_pci_image ;
13600
    input [2:0]  image_num ;
13601
    reg   [11:0] pci_ctrl_offset ;
13602
    reg   [11:0] ctrl_offset ;
13603
    reg   [11:0] ba_offset ;
13604
    reg   [11:0] am_offset ;
13605
    reg   [11:0] ta_offset ;
13606
    reg   [7:0]  cache_lsize ;
13607
    reg          ok ;
13608
    reg          test_io ;
13609
    reg          test_mem ;
13610
begin
13611
    pci_ctrl_offset = 12'h4 ;
13612
    if (image_num === 0)
13613
    begin
13614
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
13615
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
13616
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
13617
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
13618
    end
13619
    else if (image_num === 1)
13620
    begin
13621
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13622
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13623
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13624
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13625
    end
13626
    else if (image_num === 2)
13627
    begin
13628
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13629
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13630
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13631
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13632
    end
13633
    else if (image_num === 3)
13634
    begin
13635
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13636
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13637
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13638
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13639
    end
13640
    else if (image_num === 4)
13641
    begin
13642
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13643
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13644
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13645
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13646
    end
13647
    else if (image_num === 5)
13648
    begin
13649
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13650
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13651
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13652
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13653
    end
13654
 
13655
    `ifdef HOST
13656
        test_io  = 1 ;
13657
        test_mem = 1 ;
13658
    `else
13659
        if (image_num == 1)
13660
            test_io = `PCI_BA1_MEM_IO ;
13661
        else if ( image_num == 2 )
13662
            test_io = `PCI_BA2_MEM_IO ;
13663
        else if ( image_num == 3 )
13664
            test_io = `PCI_BA3_MEM_IO ;
13665
        else if ( image_num == 4 )
13666
            test_io = `PCI_BA4_MEM_IO ;
13667
        else if ( image_num == 5 )
13668
            test_io = `PCI_BA5_MEM_IO ;
13669
 
13670
        test_mem = !test_io ;
13671
    `endif
13672
 
13673
    $display(" ");
13674
    $display("########################################################################") ;
13675
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
13676
    test_name = "PCI IMAGE SETTINGS" ;
13677
 
13678
    // Set Base Address of IMAGE
13679
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
13680
    if ( ok !== 1 )
13681
    begin
13682
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13683
        test_fail("PCI Base Address register could not be written") ;
13684
    end
13685
 
13686
    // Set Address Mask of IMAGE
13687
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13688
    if ( ok !== 1 )
13689
    begin
13690
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13691
        test_fail("PCI Address Mask register could not be written") ;
13692
    end
13693
 
13694
    // Set Translation Address of IMAGE
13695
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13696
    if ( ok !== 1 )
13697
    begin
13698
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13699
        test_fail("PCI Translation Address register could not be written") ;
13700
    end
13701
 
13702
// Following are defines for byte enable signals !
13703
//      Byte Masks
13704
//      `Test_Byte_0                            (4'b1110)
13705
//      `Test_Byte_1                            (4'b1101)
13706
//      `Test_Byte_2                            (4'b1011)
13707
//      `Test_Byte_3                            (4'b0111)
13708
//      `Test_Half_0                            (4'b1100)
13709
//      `Test_Half_1                            (4'b0011)
13710
//      `Test_All_Bytes                         (4'b0000)
13711
 
13712
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
13713
    // Set Cache Line Size
13714
    cache_lsize = 8'h4 ;
13715
 
13716
    $display(" ");
13717
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13718
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13719
    if ( ok !== 1 )
13720
    begin
13721
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13722
        test_fail("PCI Device Control and Status register could not be written") ;
13723
    end
13724
 
13725
    if (test_mem)
13726
    begin
13727
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
13728
        // Task test_normal_wr_rd has the following parameters:
13729
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13730
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13731
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13732
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
13733
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
13734
 
13735
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13736
        // Set Cache Line Size
13737
        cache_lsize = 8'h4 ;
13738
 
13739
        $display(" ");
13740
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13741
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13742
        if ( ok !== 1 )
13743
        begin
13744
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13745
            test_fail("Cache Line Size register could not be written" ) ;
13746
        end
13747
 
13748
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
13749
        // Task test_normal_wr_rd has the following parameters:
13750
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13751
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13752
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13753
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
13754
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
13755
 
13756
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13757
        // Set Cache Line Size
13758
        cache_lsize = 8'h8 ;
13759
 
13760
        $display(" ");
13761
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13762
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13763
        if ( ok !== 1 )
13764
        begin
13765
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13766
            test_fail("Cache Line Size register could not be written" ) ;
13767
        end
13768
 
13769
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
13770
        // Task test_normal_wr_rd has the following parameters:
13771
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13772
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13773
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13774
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
13775
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13776
 
13777
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
13778
        // Set Cache Line Size
13779
        cache_lsize = 8'h4 ;
13780
 
13781
        $display(" ");
13782
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13783
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13784
        if ( ok !== 1 )
13785
        begin
13786
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13787
            test_fail("Cache Line Size register could not be written" ) ;
13788
        end
13789
 
13790
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
13791
        // Task test_normal_wr_rd has the following parameters:
13792
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
13793
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
13794
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
13795
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
13796
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
13797
 
13798
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13799
        $display(" ");
13800
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
13801
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13802
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13803
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
13804
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
13805
 
13806
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13807
        $display(" ");
13808
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
13809
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13810
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13811
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
13812
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
13813
 
13814
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
13815
        $display(" ");
13816
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
13817
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13818
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13819
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
13820
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
13821
 
13822
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
13823
        $display(" ");
13824
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
13825
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
13826
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
13827
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
13828
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
13829
    end
13830
 
13831
    if ( test_io )
13832
    begin
13833
        test_name = "PCI IMAGE SETTINGS" ;
13834
 
13835
        // Set Base Address of IMAGE
13836
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
13837
        if ( ok !== 1 )
13838
        begin
13839
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
13840
            test_fail("PCI Base Address register could not be written") ;
13841
        end
13842
 
13843
        // Set Address Mask of IMAGE
13844
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
13845
        if ( ok !== 1 )
13846
        begin
13847
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
13848
            test_fail("PCI Address Mask register could not be written") ;
13849
        end
13850
 
13851
        // Set Translation Address of IMAGE
13852
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
13853
        if ( ok !== 1 )
13854
        begin
13855
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
13856
            test_fail("PCI Translation Address register could not be written") ;
13857
        end
13858
 
13859
        // Set Cache Line Size
13860
        cache_lsize = 8'h4 ;
13861
 
13862
        $display(" ");
13863
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
13864
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
13865
        if ( ok !== 1 )
13866
        begin
13867
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
13868
            test_fail("Cache Line Size register could not be written" ) ;
13869
        end
13870
 
13871
        test_target_io_wr_rd
13872
        (
13873
            image_num,    // image number
13874
            0,            // test with address translation
13875
            ctrl_offset   // image control register offset
13876
        ) ;
13877
 
13878
        test_target_io_wr_rd
13879
        (
13880
            image_num,    // image number
13881
            1,            // test with address translation
13882
            ctrl_offset   // image control register offset
13883
        ) ;
13884
 
13885
        test_target_io_err_wr
13886
        (
13887
            image_num,      // image number
13888
            0,              // address translation on/off
13889
            ctrl_offset,    // image control register offset
13890
            0,              // enable error reporting
13891
 
13892
        ) ;
13893
 
13894
        test_target_io_err_wr
13895
        (
13896
            image_num,      // image number
13897
            1,              // address translation on/off
13898
            ctrl_offset,    // image control register offset
13899
            0,              // enable error reporting
13900
            1               // enable error interrupts
13901
        ) ;
13902
 
13903
        test_target_io_err_wr
13904
        (
13905
            image_num,      // image number
13906
            0,              // address translation on/off
13907
            ctrl_offset,    // image control register offset
13908
            1,              // enable error reporting
13909
 
13910
        ) ;
13911
 
13912
        test_target_io_err_wr
13913
        (
13914
            image_num,      // image number
13915
            1,              // address translation on/off
13916
            ctrl_offset,    // image control register offset
13917
            1,              // enable error reporting
13918
            1               // enable error interrupts
13919
        ) ;
13920
    end
13921
 
13922
    // Test master abort with NON supported commands
13923
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
13924
 
13925
    // disable the image
13926
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h7FFF_FFFF, 4'hF, ok ) ;
13927
end
13928
endtask //test_pci_image
13929
 
13930
task target_fast_back_to_back ;
13931
    reg   [11:0] pci_ctrl_offset ;
13932
    reg   [11:0] ctrl_offset ;
13933
    reg   [11:0] ba_offset ;
13934
    reg   [11:0] am_offset ;
13935
    reg   [11:0] ta_offset ;
13936
    reg   [11:0] cls_offset ;
13937
    reg          do_mem_fb2b ;
13938
    reg          do_io_fb2b ;
13939
    reg          ok ;
13940
begin:main
13941
 
13942
    if ( target_mem_image !== -1 )
13943
    begin
13944
        do_mem_fb2b = 1 ;
13945
 
13946
        if (target_mem_image === 1)
13947
        begin
13948
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13949
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13950
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13951
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13952
        end
13953
        else if (target_mem_image === 2)
13954
        begin
13955
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13956
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13957
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13958
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13959
        end
13960
        else if (target_mem_image === 3)
13961
        begin
13962
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13963
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13964
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13965
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13966
        end
13967
        else if (target_mem_image === 4)
13968
        begin
13969
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13970
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13971
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13972
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13973
        end
13974
        else if (target_mem_image === 5)
13975
        begin
13976
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13977
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13978
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13979
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13980
        end
13981
    end
13982
    else
13983
        do_mem_fb2b = 0 ;
13984
 
13985
    pci_ctrl_offset = 12'h4 ;
13986
    cls_offset      = 12'h00C ;
13987
 
13988
    if ( do_mem_fb2b )
13989
    begin
13990
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
13991
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13992
        if ( ok !== 1 )
13993
        begin
13994
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
13995
            test_fail("PCI Base Address register could not be written") ;
13996
            disable main ;
13997
        end
13998
 
13999
        // Set Address Mask of IMAGE
14000
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
14001
        if ( ok !== 1 )
14002
        begin
14003
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14004
            test_fail("PCI Address Mask register could not be written") ;
14005
            disable main ;
14006
        end
14007
 
14008
        // Set Translation Address of IMAGE
14009
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14010
        if ( ok !== 1 )
14011
        begin
14012
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14013
            test_fail("PCI Translation Address Register could not be written") ;
14014
            disable main ;
14015
        end
14016
 
14017
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14018
        if ( ok !== 1 )
14019
        begin
14020
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14021
            test_fail("PCI Image Control register could not be written") ;
14022
            disable main ;
14023
        end
14024
 
14025
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14026
        if ( ok !== 1 )
14027
        begin
14028
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14029
            test_fail("Cache Line Size register could not be written") ;
14030
            disable main ;
14031
        end
14032
 
14033
        // enable master 1 fast_b2b
14034
        configuration_cycle_write(0,             // bus number
14035
                                  1,             // device number
14036
                                  0,             // function number
14037
                                  1,             // register number
14038
                                  0,             // type of configuration cycle
14039
                                  4'b1111,       // byte enables
14040
                                  32'hFFFF_FFFF  // data
14041
                                 ) ;
14042
 
14043
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14044
 
14045
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
14046
        fork
14047
        begin
14048
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14049
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14050
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14051
                  0, `Test_One_Zero_Target_WS,
14052
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14053
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14054
 
14055
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14056
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14057
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14058
                  0, `Test_One_Zero_Target_WS,
14059
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14060
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14061
            do_pause(5) ;
14062
 
14063
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14064
        end
14065
        begin:wb_monitor1
14066
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14067
            if ( ok !== 1 )
14068
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14069
 
14070
            disable monitor_error_event1 ;
14071
        end
14072
        begin:monitor_error_event1
14073
            @(error_event_int) ;
14074
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14075
            ok = 0 ;
14076
            disable wb_monitor1 ;
14077
        end
14078
        join
14079
 
14080
        if ( ok )
14081
            test_ok ;
14082
 
14083
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
14084
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14085
        fork
14086
        begin
14087
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14088
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14089
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14090
                  0, `Test_One_Zero_Target_WS,
14091
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14092
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14093
 
14094
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
14095
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14096
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14097
                  0, `Test_One_Zero_Target_WS,
14098
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14099
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14100
            do_pause(5) ;
14101
 
14102
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14103
 
14104
        end
14105
        begin:wb_monitor2
14106
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
14107
            if ( ok !== 1 )
14108
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14109
            else
14110
            begin
14111
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
14112
                if ( ok !== 1 )
14113
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14114
            end
14115
 
14116
            disable monitor_error_event2 ;
14117
        end
14118
        begin:monitor_error_event2
14119
            @(error_event_int) ;
14120
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14121
            ok = 0 ;
14122
            disable wb_monitor2 ;
14123
        end
14124
        join
14125
 
14126
        if ( ok )
14127
            test_ok ;
14128
 
14129
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
14130
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14131
        fork
14132
        begin
14133
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14134
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
14135
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14136
                  0, `Test_One_Zero_Target_WS,
14137
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14138
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14139
 
14140
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14141
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14142
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14143
                  0, `Test_One_Zero_Target_WS,
14144
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14145
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14146
            do_pause(5) ;
14147
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14148
 
14149
        end
14150
        begin:wb_monitor3
14151
            fork
14152
            begin
14153
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14154
                if ( ok !== 1 )
14155
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14156
            end
14157
            begin
14158
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
14159
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
14160
                if ( ok !== 1 )
14161
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14162
            end
14163
            join
14164
 
14165
            if ( ok )
14166
            begin
14167
                fork
14168
                begin
14169
                    do_pause(3) ;
14170
 
14171
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
14172
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
14173
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14174
                        0, `Test_One_Zero_Target_WS,
14175
                        `Test_Devsel_Medium, `Test_Fast_B2B,
14176
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14177
 
14178
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
14179
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14180
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14181
                            0, `Test_One_Zero_Target_WS,
14182
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14183
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14184
 
14185
                    do_pause(1) ;
14186
                end
14187
                begin
14188
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
14189
                    if ( ok !== 1 )
14190
                    begin
14191
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14192
                        disable monitor_error_event3 ;
14193
                    end
14194
                    else
14195
                    begin
14196
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
14197
                        if ( ok !== 1 )
14198
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14199
                    end
14200
                end
14201 26 mihad
                begin
14202
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
14203
                        if ( ok !== 1 )
14204
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14205
                end
14206 15 mihad
                join
14207
            end
14208
            disable monitor_error_event3 ;
14209
        end
14210
        begin:monitor_error_event3
14211
            @(error_event_int) ;
14212
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14213
            ok = 0 ;
14214
            disable wb_monitor3 ;
14215
        end
14216
        join
14217
 
14218
        if ( ok )
14219
            test_ok ;
14220
 
14221
        test_name = "DISABLING MEM IMAGE" ;
14222
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14223
        if ( ok !== 1 )
14224
        begin
14225
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14226
            test_fail("PCI Address Mask register could not be written") ;
14227
            disable main ;
14228
        end
14229
    end
14230
 
14231
    if ( target_io_image !== -1 )
14232
    begin
14233
        do_io_fb2b = 1 ;
14234
 
14235
        if (target_io_image === 1)
14236
        begin
14237
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14238
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14239
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14240
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14241
        end
14242
        else if (target_io_image === 2)
14243
        begin
14244
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14245
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14246
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14247
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14248
        end
14249
        else if (target_io_image === 3)
14250
        begin
14251
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14252
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14253
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14254
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14255
        end
14256
        else if (target_io_image === 4)
14257
        begin
14258
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14259
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14260
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14261
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14262
        end
14263
        else if (target_io_image === 5)
14264
        begin
14265
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14266
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14267
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14268
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14269
        end
14270
    end
14271
    else
14272
        do_io_fb2b = 0 ;
14273
 
14274
    if ( do_io_fb2b )
14275
    begin
14276
 
14277
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
14278
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14279
        if ( ok !== 1 )
14280
        begin
14281
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14282
            test_fail("PCI Base Address register could not be written") ;
14283
            disable main ;
14284
        end
14285
 
14286
        // Set Address Mask of IMAGE
14287
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
14288
        if ( ok !== 1 )
14289
        begin
14290
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14291
            test_fail("PCI Address Mask register could not be written") ;
14292
            disable main ;
14293
        end
14294
 
14295
        // Set Translation Address of IMAGE
14296
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
14297
        if ( ok !== 1 )
14298
        begin
14299
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14300
            test_fail("PCI Translation Address Register could not be written") ;
14301
            disable main ;
14302
        end
14303
 
14304
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14305
        if ( ok !== 1 )
14306
        begin
14307
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14308
            test_fail("PCI Image Control register could not be written") ;
14309
            disable main ;
14310
        end
14311
 
14312
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
14313
        if ( ok !== 1 )
14314
        begin
14315
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14316
            test_fail("Cache Line Size register could not be written") ;
14317
            disable main ;
14318
        end
14319
 
14320
        // enable master 1 fast_b2b
14321
        configuration_cycle_write(0,             // bus number
14322
                                  1,             // device number
14323
                                  0,             // function number
14324
                                  1,             // register number
14325
                                  0,             // type of configuration cycle
14326
                                  4'b1111,       // byte enables
14327
                                  32'hFFFF_FFFF  // data
14328
                                 ) ;
14329
 
14330
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14331
 
14332
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
14333
        fork
14334
        begin
14335
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
14336
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
14337
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14338
                  0, `Test_One_Zero_Target_WS,
14339
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14340
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14341
 
14342
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
14343
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
14344
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14345
                  0, `Test_One_Zero_Target_WS,
14346
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14347
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14348
            do_pause(5) ;
14349
 
14350
        end
14351
        begin:wb_monitor4
14352
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
14353
            if ( ok !== 1 )
14354
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14355
 
14356
            if ( ok )
14357
            begin
14358
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
14359
                if ( ok !== 1 )
14360
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14361
            end
14362
 
14363
            disable monitor_error_event4 ;
14364
        end
14365
        begin:monitor_error_event4
14366
            @(error_event_int) ;
14367
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14368
            ok = 0 ;
14369
            disable wb_monitor4 ;
14370
        end
14371
        join
14372
 
14373
        if ( ok )
14374
            test_ok ;
14375
 
14376
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
14377
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
14378
        fork
14379
        begin
14380
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14381
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
14382
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14383
                  0, `Test_One_Zero_Target_WS,
14384
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14385
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14386
 
14387
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14388
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14389
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14390
                  0, `Test_One_Zero_Target_WS,
14391
                  `Test_Devsel_Medium, `Test_Fast_B2B,
14392
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14393
            do_pause(5) ;
14394
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
14395
        end
14396
        begin:wb_monitor5
14397
            fork
14398
            begin
14399
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
14400
                if ( ok !== 1 )
14401
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
14402
            end
14403
            begin
14404
                wb_transaction_stop( 1 ) ;
14405
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
14406
                if ( ok !== 1 )
14407
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
14408
            end
14409
            join
14410
 
14411
            if ( ok )
14412
            begin
14413
                fork
14414
                begin
14415
                    do_pause(3) ;
14416
 
14417
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
14418
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
14419
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14420
                            0, `Test_One_Zero_Target_WS,
14421
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14422
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14423
 
14424
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
14425
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
14426
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14427
                            0, `Test_One_Zero_Target_WS,
14428
                            `Test_Devsel_Medium, `Test_Fast_B2B,
14429
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
14430
 
14431
                    do_pause(1) ;
14432
                end
14433
                begin
14434
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
14435
                    if ( ok !== 1 )
14436
                    begin
14437
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14438
                        disable monitor_error_event5 ;
14439
                    end
14440
                    else
14441
                    begin
14442
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
14443
                        if ( ok !== 1 )
14444
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
14445
                    end
14446
                end
14447
                join
14448
            end
14449
            disable monitor_error_event5 ;
14450
        end
14451
        begin:monitor_error_event5
14452
            @(error_event_int) ;
14453
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
14454
            ok = 0 ;
14455
            disable wb_monitor5 ;
14456
        end
14457
        join
14458
 
14459
        if ( ok )
14460
            test_ok ;
14461
 
14462
        test_name = "DISABLING IO IMAGE" ;
14463
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
14464
        if ( ok !== 1 )
14465
        begin
14466
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14467
            test_fail("PCI Address Mask register could not be written") ;
14468
            disable main ;
14469
        end
14470
    end
14471
 
14472
end
14473
endtask //target_fast_back_to_back
14474
 
14475
task target_disconnects ;
14476
    reg   [11:0] pci_ctrl_offset ;
14477
    reg   [11:0] ctrl_offset ;
14478
    reg   [11:0] ba_offset ;
14479
    reg   [11:0] am_offset ;
14480
    reg   [11:0] ta_offset ;
14481
    reg   [11:0] cls_offset ;
14482
    reg          pci_ok ;
14483
    reg          wb_ok ;
14484
    reg          ok ;
14485
    reg   [31:0] pci_address ;
14486
    reg   [31:0] data ;
14487
    reg   [3:0]  byte_enables ;
14488
    reg   [9:0]  expect_length ;
14489
 
14490
    reg          do_mem_disconnects ;
14491
    reg          do_io_disconnects ;
14492
begin:main
14493
    if ( target_mem_image !== -1 )
14494
    begin
14495
        do_mem_disconnects = 1 ;
14496
 
14497
        if (target_mem_image === 1)
14498
        begin
14499
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14500
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14501
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14502
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14503
        end
14504
        else if (target_mem_image === 2)
14505
        begin
14506
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14507
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14508
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14509
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14510
        end
14511
        else if (target_mem_image === 3)
14512
        begin
14513
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14514
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14515
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14516
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14517
        end
14518
        else if (target_mem_image === 4)
14519
        begin
14520
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14521
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14522
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14523
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14524
        end
14525
        else if (target_mem_image === 5)
14526
        begin
14527
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14528
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14529
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14530
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14531
        end
14532
    end
14533
    else
14534
        do_mem_disconnects = 0 ;
14535
 
14536
    pci_ctrl_offset = 12'h4 ;
14537
    cls_offset = 12'h00C ;
14538
 
14539
    master1_check_received_data = 0 ;
14540
    master2_check_received_data = 0 ;
14541
 
14542
    `ifdef HOST
14543
        `ifdef NO_CNF_IMAGE
14544
        `else
14545
            `define TEST_BURST_CONFIG_READ
14546
        `endif
14547
    `else
14548
        `define TEST_BURST_CONFIG_READ
14549
        `define TEST_BURST_CONFIG_WRITE
14550
    `endif
14551
 
14552
    `ifdef TEST_BURST_CONFIG_WRITE
14553
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14554
 
14555
        data = 32'h0000_08_08 ;
14556
 
14557
        test_name = "TARGET DISCONNECT ON BURST WRITE TO CONFIGURATION SPACE" ;
14558
        byte_enables = 4'b0000 ;
14559
 
14560
        fork
14561
        begin
14562
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14563
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14564
                    byte_enables,
14565
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14566
                    8'h0_0, `Test_One_Zero_Target_WS,
14567
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14568
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14569
 
14570
            data = 32'h0000_04_04 ;
14571
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14572
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14573
                    byte_enables,
14574
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14575
                    8'h0_0, `Test_One_Zero_Target_WS,
14576
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14577
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14578
            do_pause( 1 ) ;
14579
            while ( FRAME !== 1 || IRDY !== 1 )
14580
                @(posedge pci_clock) ;
14581
 
14582
            disable monitor_error_event1 ;
14583
        end
14584
        begin:monitor_error_event1
14585
            ok = 1 ;
14586
            @(error_event_int) ;
14587
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14588
            ok = 0 ;
14589
        end
14590
        join
14591
 
14592
        config_read(pci_address, 4'hF, data) ;
14593
        if ( data [15:0] !== 16'h04_04 )
14594
        begin
14595
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14596
        end
14597
        else if ( ok )
14598
            test_ok ;
14599
 
14600
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14601
        data         = 32'h0000_0808 ;
14602
        byte_enables = 4'h0 ;
14603
        fork
14604
        begin
14605
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14606
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14607
                    byte_enables,
14608
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14609
                    8'h0_0, `Test_One_Zero_Target_WS,
14610
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14611
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14612
 
14613
            data = 32'h0000_04_04 ;
14614
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14615
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
14616
                    byte_enables,
14617
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14618
                    8'h0_0, `Test_One_Zero_Target_WS,
14619
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14620
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14621
 
14622
            do_pause( 1 ) ;
14623
            while ( FRAME !== 1 || IRDY !== 1 )
14624
                @(posedge pci_clock) ;
14625
 
14626
            disable monitor_error_event2 ;
14627
        end
14628
        begin:monitor_error_event2
14629
            ok = 1 ;
14630
            @(error_event_int) ;
14631
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14632
            ok = 0 ;
14633
        end
14634
        join
14635
 
14636
        config_read(pci_address, 4'hF, data) ;
14637
        if ( data [15:0] !== 16'h04_04 )
14638
        begin
14639
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
14640
        end
14641
        else if ( ok )
14642
            test_ok ;
14643
    `endif
14644
 
14645
    `ifdef TEST_BURST_CONFIG_READ
14646
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
14647
 
14648
        data = 32'h0000_04_04 ;
14649
 
14650
        test_name = "TARGET DISCONNECT ON BURST READ FROM CONFIGURATION SPACE" ;
14651
        byte_enables = 4'b0000 ;
14652
 
14653
        fork
14654
        begin
14655
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14656
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14657
                    byte_enables,
14658
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14659
                    8'h0_0, `Test_One_Zero_Target_WS,
14660
                    `Test_Devsel_Medium, `Test_Fast_B2B,
14661
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14662
            do_pause( 1 ) ;
14663
 
14664
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14665
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
14666
                    byte_enables,
14667
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14668
                    8'h0_0, `Test_One_Zero_Target_WS,
14669
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14670
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14671
            do_pause( 1 ) ;
14672
 
14673
            while ( FRAME !== 1 || IRDY !== 1 )
14674
                @(posedge pci_clock) ;
14675
 
14676
            disable monitor_error_event3 ;
14677
        end
14678
        begin:monitor_error_event3
14679
            ok = 1 ;
14680
            @(error_event_int) ;
14681
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14682
            ok = 0 ;
14683
        end
14684
        join
14685
 
14686
        if ( ok )
14687
            test_ok ;
14688
 
14689
        pci_address  = {20'h0000_0, 1'b1, 11'h00C} ;
14690
        fork
14691
        begin
14692
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14693
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14694
                    byte_enables,
14695
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14696
                    8'h0_0, `Test_One_Zero_Target_WS,
14697
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14698
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14699
            do_pause( 1 ) ;
14700
 
14701
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14702
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
14703
                    byte_enables,
14704
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14705
                    8'h0_0, `Test_One_Zero_Target_WS,
14706
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
14707
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14708
            do_pause( 1 ) ;
14709
 
14710
            while ( FRAME !== 1 || IRDY !== 1 )
14711
                @(posedge pci_clock) ;
14712
 
14713
            disable monitor_error_event4 ;
14714
        end
14715
        begin:monitor_error_event4
14716
            ok = 1 ;
14717
            @(error_event_int) ;
14718
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
14719
            ok = 0 ;
14720
        end
14721
        join
14722
 
14723
        if ( ok )
14724
            test_ok ;
14725
    `endif
14726
 
14727
    `ifdef TEST_BURST_CONFIG_READ
14728
        `undef TEST_BURST_CONFIG_READ
14729
    `endif
14730
 
14731
    `ifdef TEST_BURST_CONFIG_WRITE
14732
        `undef TEST_BURST_CONFIG_WRITE
14733
    `endif
14734
 
14735
    master1_check_received_data = 1 ;
14736
    master2_check_received_data = 1 ;
14737
 
14738
    if ( do_mem_disconnects )
14739
    begin
14740
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
14741
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
14742
        if ( ok !== 1 )
14743
        begin
14744
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14745
            test_fail("PCI Base Address register could not be written") ;
14746
            disable main ;
14747
        end
14748
 
14749
        // Set Address Mask of IMAGE
14750
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
14751
        if ( ok !== 1 )
14752
        begin
14753
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14754
            test_fail("PCI Address Mask register could not be written") ;
14755
            disable main ;
14756
        end
14757
 
14758
        // Set Translation Address of IMAGE
14759
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
14760
        if ( ok !== 1 )
14761
        begin
14762
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14763
            test_fail("PCI Translation Address Register could not be written") ;
14764
            disable main ;
14765
        end
14766
 
14767
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14768
        if ( ok !== 1 )
14769
        begin
14770
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14771
            test_fail("PCI Image Control register could not be written") ;
14772
            disable main ;
14773
        end
14774
 
14775
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
14776
        if ( ok !== 1 )
14777
        begin
14778
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
14779
            test_fail("Cache Line Size register could not be written") ;
14780
            disable main ;
14781
        end
14782
 
14783
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14784
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14785
        data = 32'hAAAA_AAAA ;
14786
        byte_enables = 4'h0 ;
14787
        expect_length = `PCIW_DEPTH - 2 ;
14788
 
14789
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14790
        fork
14791
        begin
14792
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14793
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14794
                        byte_enables,
14795
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
14796
                        8'h0_0, `Test_One_Zero_Target_WS,
14797
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14798
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14799
            do_pause( 3 ) ;
14800
 
14801
            while ( FRAME !== 1 || IRDY !== 1 )
14802
                @(posedge pci_clock) ;
14803
 
14804
            disable monitor_error_event5 ;
14805
        end
14806
        begin:monitor_error_event5
14807
            pci_ok = 1 ;
14808
            @(error_event_int) ;
14809
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14810
            pci_ok = 0 ;
14811
        end
14812
        begin
14813
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14814
            if ( wb_ok !== 1 )
14815
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14816
        end
14817
        join
14818
 
14819
        if ( wb_ok && pci_ok )
14820
            test_ok ;
14821
 
14822
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
14823
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14824
        data = 32'hAAAA_AAAA ;
14825
        byte_enables = 4'h0 ;
14826
        expect_length = `PCIW_DEPTH - 2 ;
14827
 
14828
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14829
        fork
14830
        begin
14831
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
14832
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14833
                        byte_enables,
14834
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
14835
                        8'h0_0, `Test_One_Zero_Target_WS,
14836
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14837
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14838
            do_pause( 3 ) ;
14839
 
14840
            while ( FRAME !== 1 || IRDY !== 1 )
14841
                @(posedge pci_clock) ;
14842
 
14843
            disable monitor_error_event6 ;
14844
        end
14845
        begin:monitor_error_event6
14846
            pci_ok = 1 ;
14847
            @(error_event_int) ;
14848
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14849
            pci_ok = 0 ;
14850
        end
14851
        begin
14852
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14853
            if ( wb_ok !== 1 )
14854
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14855
        end
14856
        join
14857
 
14858
        if ( wb_ok && pci_ok )
14859
            test_ok ;
14860
 
14861
        master1_check_received_data = 1 ;
14862
//        master2_check_received_data = 0 ;
14863
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
14864
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14865
        data = 32'hAAAA_AAAA ;
14866
        byte_enables = 4'h0 ;
14867
        expect_length = 4 ;
14868
 
14869
        fork
14870
        begin
14871
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14872
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14873
                        byte_enables,
14874
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14875
                        8'h0_0, `Test_One_Zero_Target_WS,
14876
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14877
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14878
            do_pause( 1 ) ;
14879
 
14880
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14881
            if ( wb_ok !== 1 )
14882
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14883
 
14884
            do_pause(2) ;
14885
 
14886
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14887
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14888
                        byte_enables,
14889
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14890
                        8'h0_0, `Test_One_Zero_Target_WS,
14891
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14892
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
14893
            do_pause( 3 ) ;
14894
 
14895
            while ( FRAME !== 1 || IRDY !== 1 )
14896
                @(posedge pci_clock) ;
14897
 
14898
            disable monitor_error_event7 ;
14899
        end
14900
        begin:monitor_error_event7
14901
            pci_ok = 1 ;
14902
            @(error_event_int) ;
14903
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14904
            pci_ok = 0 ;
14905
        end
14906
        join
14907
 
14908
        if ( wb_ok && pci_ok )
14909
            test_ok ;
14910
 
14911
        master1_check_received_data = 1 ;
14912
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
14913
        pci_address = Target_Base_Addr_R[target_mem_image] ;
14914
        data = 32'hAAAA_AAAA ;
14915
        byte_enables = 4'h0 ;
14916
        expect_length = 4 ;
14917
 
14918
        fork
14919
        begin
14920
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14921
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14922
                        byte_enables,
14923
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14924
                        8'h0_0, `Test_One_Zero_Target_WS,
14925
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14926
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
14927
            do_pause( 1 ) ;
14928
 
14929
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
14930
            if ( wb_ok !== 1 )
14931
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14932
 
14933
            do_pause(2) ;
14934
 
14935
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
14936
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
14937
                        byte_enables,
14938
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14939
                        8'h0_0, `Test_One_Zero_Target_WS,
14940
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14941
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
14942
            do_pause( 3 ) ;
14943
 
14944
            while ( FRAME !== 1 || IRDY !== 1 )
14945
                @(posedge pci_clock) ;
14946
 
14947
            disable monitor_error_event8 ;
14948
        end
14949
        begin:monitor_error_event8
14950
            pci_ok = 1 ;
14951
            @(error_event_int) ;
14952
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
14953
            pci_ok = 0 ;
14954
        end
14955
        join
14956
 
14957
        if ( wb_ok && pci_ok )
14958
            test_ok ;
14959
 
14960
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
14961
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
14962
        data = 32'hDEAF_BEAF ;
14963
        byte_enables = 4'h0 ;
14964
        expect_length = 1 ;
14965
 
14966
        fork
14967
        begin
14968
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
14969
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
14970
                        byte_enables,
14971
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
14972
                        8'h0_0, `Test_One_Zero_Target_WS,
14973
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
14974
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
14975
            do_pause( 3 ) ;
14976
 
14977
            while ( FRAME !== 1 || IRDY !== 1 )
14978
                @(posedge pci_clock) ;
14979
 
14980
            disable monitor_error_event9 ;
14981
        end
14982
        begin:monitor_error_event9
14983
            pci_ok = 1 ;
14984
            @(error_event_int) ;
14985
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
14986
            pci_ok = 0 ;
14987
        end
14988
        begin
14989
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
14990
            if ( wb_ok !== 1 )
14991
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
14992
        end
14993
        join
14994
 
14995
        if ( wb_ok && pci_ok )
14996
            test_ok ;
14997
 
14998
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
14999
        data = 32'hDEAD_BEAF ;
15000
        byte_enables = 4'h0 ;
15001
        expect_length = 1 ;
15002
 
15003
        fork
15004
        begin
15005
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15006
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15007
                        byte_enables,
15008
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15009
                        8'h0_0, `Test_One_Zero_Target_WS,
15010
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15011
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15012
            do_pause( 3 ) ;
15013
 
15014
            while ( FRAME !== 1 || IRDY !== 1 )
15015
                @(posedge pci_clock) ;
15016
 
15017
            disable monitor_error_event10 ;
15018
        end
15019
        begin:monitor_error_event10
15020
            pci_ok = 1 ;
15021
            @(error_event_int) ;
15022
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15023
            pci_ok = 0 ;
15024
        end
15025
        begin
15026
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15027
            if ( wb_ok !== 1 )
15028
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15029
        end
15030
        join
15031
 
15032
        if ( wb_ok && pci_ok )
15033
            test_ok ;
15034
 
15035
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15036
        data = 32'hAAAA_AAAA ;
15037
        byte_enables = 4'h0 ;
15038
        expect_length = 1 ;
15039
 
15040
        fork
15041
        begin
15042
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15043
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
15044
                        byte_enables,
15045
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15046
                        8'h0_0, `Test_One_Zero_Target_WS,
15047
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15048
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15049
            do_pause( 3 ) ;
15050
 
15051
            while ( FRAME !== 1 || IRDY !== 1 )
15052
                @(posedge pci_clock) ;
15053
 
15054
            disable monitor_error_event11 ;
15055
        end
15056
        begin:monitor_error_event11
15057
            pci_ok = 1 ;
15058
            @(error_event_int) ;
15059
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
15060
            pci_ok = 0 ;
15061
        end
15062
        begin
15063
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15064
            if ( wb_ok !== 1 )
15065
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15066
        end
15067
        join
15068
 
15069
        if ( wb_ok && pci_ok )
15070
            test_ok ;
15071
 
15072
        master1_check_received_data = 1 ;
15073
 
15074
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
15075
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
15076
        data = 32'hDEAF_BEAF ;
15077
        byte_enables = 4'h0 ;
15078
        expect_length = 1 ;
15079
 
15080
        fork
15081
        begin
15082
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15083
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15084
                        byte_enables,
15085
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15086
                        8'h0_0, `Test_One_Zero_Target_WS,
15087
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15088
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15089
            do_pause( 1 ) ;
15090
 
15091
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15092
            if ( wb_ok !== 1 )
15093
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15094
 
15095
            do_pause(3) ;
15096
 
15097
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
15098
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15099
                        byte_enables,
15100
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15101
                        8'h0_0, `Test_One_Zero_Target_WS,
15102
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15103
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
15104
            do_pause( 3 ) ;
15105
 
15106
            while ( FRAME !== 1 || IRDY !== 1 )
15107
                @(posedge pci_clock) ;
15108
 
15109
            disable monitor_error_event12 ;
15110
        end
15111
        begin:monitor_error_event12
15112
            pci_ok = 1 ;
15113
            @(error_event_int) ;
15114
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15115
            pci_ok = 0 ;
15116
        end
15117
        join
15118
 
15119
        if ( wb_ok && pci_ok )
15120
            test_ok ;
15121
 
15122
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
15123
        data = 32'hDEAD_BEAF ;
15124
        byte_enables = 4'h0 ;
15125
        expect_length = 1 ;
15126
 
15127
        fork
15128
        begin
15129
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15130
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15131
                        byte_enables,
15132
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15133
                        8'h0_0, `Test_One_Zero_Target_WS,
15134
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15135
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15136
            do_pause( 1 ) ;
15137
 
15138
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15139
            if ( wb_ok !== 1 )
15140
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15141
 
15142
            do_pause(3) ;
15143
 
15144
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
15145
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
15146
                        byte_enables,
15147
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15148
                        8'h0_0, `Test_One_Zero_Target_WS,
15149
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15150
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15151
            do_pause( 3 ) ;
15152
 
15153
            while ( FRAME !== 1 || IRDY !== 1 )
15154
                @(posedge pci_clock) ;
15155
 
15156
            disable monitor_error_event13 ;
15157
        end
15158
        begin:monitor_error_event13
15159
            pci_ok = 1 ;
15160
            @(error_event_int) ;
15161
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15162
            pci_ok = 0 ;
15163
        end
15164
        join
15165
 
15166
        if ( wb_ok && pci_ok )
15167
            test_ok ;
15168
 
15169
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
15170
        data = 32'hAAAA_AAAA ;
15171
        byte_enables = 4'h0 ;
15172
        expect_length = 1 ;
15173
 
15174
        fork
15175
        begin
15176
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15177
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15178
                        byte_enables,
15179
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15180
                        8'h0_0, `Test_One_Zero_Target_WS,
15181
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15182
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15183
            do_pause( 1 ) ;
15184
 
15185
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15186
            if ( wb_ok !== 1 )
15187
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15188
 
15189
            do_pause(3) ;
15190
 
15191
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
15192
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
15193
                        byte_enables,
15194
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
15195
                        8'h0_0, `Test_One_Zero_Target_WS,
15196
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
15197
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
15198
            do_pause( 3 ) ;
15199
 
15200
            while ( FRAME !== 1 || IRDY !== 1 )
15201
                @(posedge pci_clock) ;
15202
 
15203
            disable monitor_error_event14 ;
15204
        end
15205
        begin:monitor_error_event14
15206
            pci_ok = 1 ;
15207
            @(error_event_int) ;
15208
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15209
            pci_ok = 0 ;
15210
        end
15211
        join
15212
 
15213
        if ( wb_ok && pci_ok )
15214
            test_ok ;
15215
 
15216
        // disable the image
15217
        test_name = "DISABLING MEMORY IMAGE" ;
15218
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15219
        if ( ok !== 1 )
15220
        begin
15221
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15222
            test_fail("PCI Address Mask register could not be written") ;
15223
            disable main ;
15224
        end
15225
    end
15226
//*
15227
    if ( target_io_image !== -1 )
15228
    begin
15229
        do_io_disconnects = 1 ;
15230
 
15231
        if (target_io_image === 1)
15232
        begin
15233
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15234
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15235
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15236
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15237
        end
15238
        else if (target_io_image === 2)
15239
        begin
15240
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15241
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15242
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15243
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15244
        end
15245
        else if (target_io_image === 3)
15246
        begin
15247
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15248
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15249
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15250
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15251
        end
15252
        else if (target_io_image === 4)
15253
        begin
15254
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15255
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15256
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15257
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15258
        end
15259
        else if (target_io_image === 5)
15260
        begin
15261
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15262
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15263
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15264
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15265
        end
15266
    end
15267
    else
15268
        do_io_disconnects = 0 ;
15269
 
15270
    if ( do_io_disconnects )
15271
    begin
15272
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
15273
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
15274
        if ( ok !== 1 )
15275
        begin
15276
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15277
            test_fail("PCI Base Address register could not be written") ;
15278
            disable main ;
15279
        end
15280
 
15281
        // Set Address Mask of IMAGE
15282
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
15283
        if ( ok !== 1 )
15284
        begin
15285
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15286
            test_fail("PCI Address Mask register could not be written") ;
15287
            disable main ;
15288
        end
15289
 
15290
        // Set Translation Address of IMAGE
15291
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
15292
        if ( ok !== 1 )
15293
        begin
15294
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15295
            test_fail("PCI Translation Address Register could not be written") ;
15296
            disable main ;
15297
        end
15298
 
15299
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15300
        if ( ok !== 1 )
15301
        begin
15302
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
15303
            test_fail("PCI Image Control register could not be written") ;
15304
            disable main ;
15305
        end
15306
 
15307
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
15308
        if ( ok !== 1 )
15309
        begin
15310
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
15311
            test_fail("Cache Line Size register could not be written") ;
15312
            disable main ;
15313
        end
15314
 
15315
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
15316
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
15317
        data = 32'h5555_5555 ;
15318
        byte_enables = 4'h0 ;
15319
        expect_length = 1 ;
15320
 
15321
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15322
 
15323
        fork
15324
        begin
15325
            PCIU_IO_WRITE
15326
            (
15327
                `Test_Master_1,             // which master
15328
                pci_address,                // to what address
15329
                data,                       // data
15330
                byte_enables,               // byte enable
15331
                expect_length + 1,          // length to request
15332
                `Test_Target_Retry_On       // expected target termination
15333
            ) ;
15334
 
15335
            do_pause( 3 ) ;
15336
 
15337
            while ( FRAME !== 1 || IRDY !== 1 )
15338
                @(posedge pci_clock) ;
15339
 
15340
            disable monitor_error_event15 ;
15341
        end
15342
        begin:monitor_error_event15
15343
            pci_ok = 1 ;
15344
            @(error_event_int) ;
15345
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15346
            pci_ok = 0 ;
15347
        end
15348
        begin
15349
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15350
            if ( wb_ok !== 1 )
15351
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15352
        end
15353
        join
15354
 
15355
        if ( wb_ok && pci_ok )
15356
            test_ok ;
15357
 
15358
        data = 32'hAAAA_AAAA ;
15359
        fork
15360
        begin
15361
            PCIU_IO_WRITE
15362
            (
15363
                `Test_Master_1,             // which master
15364
                pci_address,                // to what address
15365
                data,                       // data
15366
                byte_enables,               // byte enable
15367
                expect_length + 2,          // length to request
15368
                `Test_Target_Retry_Before   // expected target termination
15369
            ) ;
15370
 
15371
            do_pause( 3 ) ;
15372
 
15373
            while ( FRAME !== 1 || IRDY !== 1 )
15374
                @(posedge pci_clock) ;
15375
 
15376
            disable monitor_error_event16 ;
15377
        end
15378
        begin:monitor_error_event16
15379
            pci_ok = 1 ;
15380
            @(error_event_int) ;
15381
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
15382
            pci_ok = 0 ;
15383
        end
15384
        begin
15385
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
15386
            if ( wb_ok !== 1 )
15387
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15388
        end
15389
        join
15390
 
15391
        if ( wb_ok && pci_ok )
15392
            test_ok ;
15393
 
15394
        master2_check_received_data = 1 ;
15395
 
15396
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
15397
 
15398
        fork
15399
        begin
15400
 
15401
             PCIU_IO_READ
15402
             (
15403
                `Test_Master_2,
15404
                pci_address[PCI_BUS_DATA_RANGE:0],
15405
                data,
15406
                byte_enables,
15407
                2,
15408
                `Test_Target_Retry_Before
15409
             );
15410
 
15411
            do_pause( 1 ) ;
15412
 
15413
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15414
            if ( wb_ok !== 1 )
15415
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15416
 
15417
            do_pause(3) ;
15418
 
15419
            PCIU_IO_READ
15420
             (
15421
                `Test_Master_2,
15422
                pci_address[PCI_BUS_DATA_RANGE:0],
15423
                data,
15424
                byte_enables,
15425
                expect_length + 1,
15426
                `Test_Target_Retry_On
15427
             );
15428
 
15429
            do_pause( 3 ) ;
15430
 
15431
            while ( FRAME !== 1 || IRDY !== 1 )
15432
                @(posedge pci_clock) ;
15433
 
15434
            disable monitor_error_event17 ;
15435
        end
15436
        begin:monitor_error_event17
15437
            pci_ok = 1 ;
15438
            @(error_event_int) ;
15439
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15440
            pci_ok = 0 ;
15441
        end
15442
        join
15443
 
15444
        if ( wb_ok && pci_ok )
15445
            test_ok ;
15446
 
15447
        fork
15448
        begin
15449
 
15450
             PCIU_IO_READ
15451
             (
15452
                `Test_Master_2,
15453
                pci_address[PCI_BUS_DATA_RANGE:0],
15454
                data,
15455
                byte_enables,
15456
                2,
15457
                `Test_Target_Retry_Before
15458
             );
15459
 
15460
            do_pause( 1 ) ;
15461
 
15462
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
15463
            if ( wb_ok !== 1 )
15464
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
15465
 
15466
            do_pause(3) ;
15467
 
15468
            PCIU_IO_READ
15469
             (
15470
                `Test_Master_2,
15471
                pci_address[PCI_BUS_DATA_RANGE:0],
15472
                data,
15473
                byte_enables,
15474
                expect_length + 2,
15475
                `Test_Target_Retry_Before
15476
             );
15477
 
15478
            do_pause( 3 ) ;
15479
 
15480
            while ( FRAME !== 1 || IRDY !== 1 )
15481
                @(posedge pci_clock) ;
15482
 
15483
            disable monitor_error_event18 ;
15484
        end
15485
        begin:monitor_error_event18
15486
            pci_ok = 1 ;
15487
            @(error_event_int) ;
15488
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
15489
            pci_ok = 0 ;
15490
        end
15491
        join
15492
 
15493
        if ( wb_ok && pci_ok )
15494
            test_ok ;
15495
 
15496
        test_name = "DISABLING IO IMAGE" ;
15497
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h7FFF_FFFF, 4'hF, ok ) ;
15498
        if ( ok !== 1 )
15499
        begin
15500
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15501
            test_fail("PCI Address Mask register could not be written") ;
15502
            disable main ;
15503
        end
15504
    end
15505
//*/
15506
end
15507
endtask // target_disconnects
15508
 
15509
task target_unsupported_cmds ;
15510
        input [31:0] Address;
15511
        input [2:0]  image_num ;
15512
    reg          ok ;
15513
begin:main
15514
        // PCI IACK behavioral Target must NOT respond!!!
15515
    irq_respond = 0 ;
15516
 
15517
    $display("  ") ;
15518
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
15519
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
15520
    ipci_unsupported_commands_master.master_reference
15521
    (
15522
        Address,                // first part of address in dual address cycle
15523
        Address,                // second part of address in dual address cycle
15524
        `BC_IACK,                       // dual address cycle command
15525
        `BC_IACK,               // normal command
15526
        4'h0,               // byte enables
15527
        32'h1234_5678,      // data
15528
        1'b0,               // make address parity error on first phase of dual address
15529
        1'b0,               // make address parity error on second phase of dual address
15530
        ok                  // result of operation
15531
    ) ;
15532
    if ( ok )
15533
        test_ok ;
15534
    else
15535
    begin
15536
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15537
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
15538
    end
15539
 
15540
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
15541
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
15542
    ipci_unsupported_commands_master.master_reference
15543
    (
15544
        Address,                // first part of address in dual address cycle
15545
        Address,                // second part of address in dual address cycle
15546
        `BC_SPECIAL,            // dual address cycle command
15547
        `BC_SPECIAL,            // normal command
15548
        4'h0,               // byte enables
15549
        32'h1234_5678,      // data
15550
        1'b0,               // make address parity error on first phase of dual address
15551
        1'b0,               // make address parity error on second phase of dual address
15552
        ok                  // result of operation
15553
    ) ;
15554
    if ( ok )
15555
        test_ok ;
15556
    else
15557
    begin
15558
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15559
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
15560
    end
15561
 
15562
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
15563
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
15564
    ipci_unsupported_commands_master.master_reference
15565
    (
15566
        Address,                // first part of address in dual address cycle
15567
        Address,                // second part of address in dual address cycle
15568
        `BC_RESERVED0,          // dual address cycle command
15569
        `BC_RESERVED0,      // normal command
15570
        4'h0,               // byte enables
15571
        32'h1234_5678,      // data
15572
        1'b0,               // make address parity error on first phase of dual address
15573
        1'b0,               // make address parity error on second phase of dual address
15574
        ok                  // result of operation
15575
    ) ;
15576
    if ( ok )
15577
        test_ok ;
15578
    else
15579
    begin
15580
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15581
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
15582
    end
15583
 
15584
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
15585
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
15586
    ipci_unsupported_commands_master.master_reference
15587
    (
15588
        Address,                // first part of address in dual address cycle
15589
        Address,                // second part of address in dual address cycle
15590
        `BC_RESERVED1,          // dual address cycle command
15591
        `BC_RESERVED1,      // normal command
15592
        4'h0,               // byte enables
15593
        32'h1234_5678,      // data
15594
        1'b0,               // make address parity error on first phase of dual address
15595
        1'b0,               // make address parity error on second phase of dual address
15596
        ok                  // result of operation
15597
    ) ;
15598
    if ( ok )
15599
        test_ok ;
15600
    else
15601
    begin
15602
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15603
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
15604
    end
15605
 
15606
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
15607
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
15608
    ipci_unsupported_commands_master.master_reference
15609
    (
15610
        Address,                // first part of address in dual address cycle
15611
        Address,                // second part of address in dual address cycle
15612
        `BC_RESERVED2,          // dual address cycle command
15613
        `BC_RESERVED2,      // normal command
15614
        4'h0,               // byte enables
15615
        32'h1234_5678,      // data
15616
        1'b0,               // make address parity error on first phase of dual address
15617
        1'b0,               // make address parity error on second phase of dual address
15618
        ok                  // result of operation
15619
    ) ;
15620
    if ( ok )
15621
        test_ok ;
15622
    else
15623
    begin
15624
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15625
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
15626
    end
15627
 
15628
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
15629
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
15630
    ipci_unsupported_commands_master.master_reference
15631
    (
15632
        Address,                // first part of address in dual address cycle
15633
        Address,                // second part of address in dual address cycle
15634
        `BC_RESERVED3,          // dual address cycle command
15635
        `BC_RESERVED3,      // normal command
15636
        4'h0,               // byte enables
15637
        32'h1234_5678,      // data
15638
        1'b0,               // make address parity error on first phase of dual address
15639
        1'b0,               // make address parity error on second phase of dual address
15640
        ok                  // result of operation
15641
    ) ;
15642
    if ( ok )
15643
        test_ok ;
15644
    else
15645
    begin
15646
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15647
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
15648
    end
15649
 
15650
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
15651
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
15652
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
15653
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
15654
    ipci_unsupported_commands_master.master_reference
15655
    (
15656
        Address,                // first part of address in dual address cycle
15657
        Address,                // second part of address in dual address cycle
15658
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
15659
        `BC_MEM_WRITE,      // normal command
15660
        4'h0,               // byte enables;
15661
        32'h1234_5678,      // data
15662
        1'b0,               // make address parity error on first phase of dual address
15663
        1'b0,               // make address parity error on second phase of dual address
15664
        ok                  // result of operation
15665
    ) ;
15666
    if ( ok )
15667
        test_ok ;
15668
    else
15669
    begin
15670
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
15671
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
15672
    end
15673
 
15674
    irq_respond = 1 ;
15675
 
15676
end
15677
endtask // target_unsupported_cmds
15678
 
15679
task target_completion_expiration ;
15680
    reg   [11:0] pci_ctrl_offset ;
15681
    reg   [11:0] pci_ba_offset ;
15682
    reg   [11:0] pci_am_offset ;
15683
    reg   [11:0] pci_device_ctrl_offset ;
15684
    reg   [11:0] pci_err_cs_offset ;
15685
    reg   [11:0] icr_offset ;
15686
    reg   [11:0] isr_offset ;
15687
    reg   [11:0] lat_tim_cls_offset ;
15688
 
15689
    reg [31:0] temp_val1 ;
15690
    reg [31:0] temp_val2 ;
15691
    reg        ok   ;
15692 33 mihad
    reg        ok_wb ;
15693
    reg        ok_pci ;
15694 15 mihad
 
15695
    reg [31:0] pci_image_base ;
15696
    integer i ;
15697 33 mihad
    integer clocks_after_completion ;
15698
    reg     error_monitor_done ;
15699
    reg     test_mem ;
15700 15 mihad
 
15701
begin:main
15702
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15703
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
15704
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
15705
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15706
 
15707
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
15708
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
15709
    lat_tim_cls_offset = 12'hC ;
15710
    pci_device_ctrl_offset    = 12'h4 ;
15711
 
15712 33 mihad
    `ifdef HOST
15713
        test_mem = 1'b1 ;
15714
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
15715
    `else
15716
        test_mem = !`PCI_BA1_MEM_IO ;
15717
        pci_image_base = Target_Base_Addr_R[1] ;
15718
    `endif
15719 15 mihad
 
15720
    // enable master & target operation
15721
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
15722
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
15723
    if ( ok !== 1 )
15724
    begin
15725
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
15726
        test_fail("write to PCI Device Control register failed") ;
15727
        disable main ;
15728
    end
15729
 
15730
    // prepare image control register
15731 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
15732 15 mihad
    if ( ok !== 1 )
15733
    begin
15734
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
15735
        test_fail("write to PCI Image Control register failed") ;
15736
        disable main ;
15737
    end
15738
 
15739
    // prepare base address register
15740
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
15741
    if ( ok !== 1 )
15742
    begin
15743
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
15744
        test_fail("write to PCI Base Address register failed") ;
15745
        disable main ;
15746
    end
15747
 
15748
    // write address mask register
15749
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15750
    if ( ok !== 1 )
15751
    begin
15752
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
15753
        test_fail("write to PCI Address Mask register failed") ;
15754
        disable main ;
15755
    end
15756
 
15757
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
15758
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
15759
    if ( ok !== 1 )
15760
    begin
15761
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
15762
        test_fail("write to PCI Error Control and Status register failed") ;
15763
        disable main ;
15764
    end
15765
 
15766 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
15767 15 mihad
    if ( ok !== 1 )
15768
    begin
15769
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
15770
        test_fail("write to Interrupt Control register failed") ;
15771
        disable main ;
15772
    end
15773
 
15774
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
15775
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
15776
    if ( ok !== 1 )
15777
    begin
15778
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
15779
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
15780
        disable main ;
15781
    end
15782
 
15783
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
15784
 
15785
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
15786 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
15787
    master1_check_received_data = 0 ;
15788 15 mihad
 
15789 33 mihad
    ok_pci = 1 ;
15790
    // start a delayed read request
15791
    fork
15792
    begin
15793
        if ( test_mem )
15794
 
15795
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
15796
                          pci_image_base, 32'h1234_5678,
15797
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
15798
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
15799
        else
15800
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
15801
 
15802
        do_pause( 1 ) ;
15803
    end
15804
    begin:error_monitor1
15805
        @(error_event_int) ;
15806
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
15807
        ok_pci = 0 ;
15808
    end
15809
    begin
15810
        if ( test_mem )
15811
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
15812
        else
15813
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
15814 15 mihad
 
15815 33 mihad
        if ( ok_wb !== 1 )
15816
        begin
15817
            test_fail("Bridge failed to process Target Memory read correctly") ;
15818
            disable main ;
15819
        end
15820
 
15821
        if ( ok_pci )
15822
            disable error_monitor1 ;
15823
    end
15824
    join
15825
 
15826
    clocks_after_completion = 0 ;
15827
    // now do another - different transaction
15828
    fork
15829
    begin
15830
        if ( test_mem )
15831
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
15832
                          pci_image_base + 4, 32'h1234_5678,
15833
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
15834
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
15835
        else
15836
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
15837
 
15838
        while ( clocks_after_completion < 32'h0000_FFF0 )
15839
        begin
15840
            @(posedge pci_clock) ;
15841
            clocks_after_completion = clocks_after_completion + 1 ;
15842
        end
15843
 
15844
        do_pause('hFF) ;
15845
 
15846
        if ( test_mem )
15847
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
15848
                          pci_image_base + 4, 32'h1234_5678,
15849
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
15850
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
15851
        else
15852
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
15853
 
15854
        do_pause( 1 ) ;
15855
    end
15856
    begin:error_monitor2
15857
        @(error_event_int) ;
15858
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
15859
        ok_pci = 0 ;
15860
    end
15861
    begin
15862
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
15863
        repeat( 'hFF )
15864
            @(posedge pci_clock) ;
15865
 
15866
        if ( test_mem )
15867
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
15868
        else
15869
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
15870
 
15871
        if ( ok_wb !== 1 )
15872
        begin
15873
            test_fail("Bridge failed to process Target Memory read correctly") ;
15874
            disable main ;
15875
        end
15876
 
15877
        repeat(4)
15878
            @(posedge pci_clock) ;
15879
 
15880
        fork
15881
        begin
15882
            if ( test_mem )
15883
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
15884
                              pci_image_base + 4, 32'h1234_5678,
15885
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
15886
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
15887
            else
15888
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
15889
 
15890
            do_pause(1) ;
15891
        end
15892
        begin
15893
           pci_transaction_progress_monitor( pci_image_base + 4, test_mem ? `BC_MEM_READ : `BC_IO_READ, test_mem ? 4 : 1, 0, 1'b1, 1'b0, 0, ok ) ;
15894
           if ( ok_pci )
15895
               disable error_monitor2 ;
15896
        end
15897
        join
15898
    end
15899
    join
15900
 
15901
    if ( ok && ok_pci && ok_wb )
15902
        test_ok ;
15903
 
15904
    if ( ok !== 1 )
15905
    begin
15906
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
15907
        test_fail("write to PCI Address Mask register failed") ;
15908
        disable main ;
15909
    end
15910
 
15911
    // check statuses after this situation - none should be set
15912
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
15913
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
15914
    if ( ok !== 1 )
15915
    begin
15916
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
15917
        test_fail("read from pci device status register failed") ;
15918
        disable main ;
15919
    end
15920
 
15921
    if ( temp_val1[31] )
15922
    begin
15923
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
15924
        test_fail("detected parity error bit was set for no reason") ;
15925
    end
15926
 
15927
    if ( temp_val1[30] )
15928
    begin
15929
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
15930
        test_fail("signaled system error bit was set for no reason") ;
15931
    end
15932
 
15933
    if ( temp_val1[29] )
15934
    begin
15935
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
15936
        test_fail("received master abort bit was set for no reason") ;
15937
    end
15938
 
15939
    if ( temp_val1[28] )
15940
    begin
15941
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
15942
        test_fail("received target abort bit was set for no reason") ;
15943
    end
15944
 
15945
    if ( temp_val1[27] )
15946
    begin
15947
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
15948
        test_fail("signaled target abort bit was set for no reason") ;
15949
    end
15950
 
15951
    if ( temp_val1[24] )
15952
    begin
15953
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
15954
        test_fail("Master Data parity error bit was set for no reason") ;
15955
    end
15956
 
15957
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
15958
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
15959
    if ( temp_val1[8] !== 0 )
15960
    begin
15961
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
15962
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
15963
    end
15964
    // test target retry counter expiration
15965
    // set wb slave to retry response
15966
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
15967
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
15968
    ok_pci = 1 ;
15969
 
15970
    fork
15971
    begin
15972
        if ( test_mem == 1 )
15973
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
15974
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
15975
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
15976
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
15977
        else
15978
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
15979
 
15980
        do_pause(1) ;
15981
 
15982
        // do another write with same address and different data
15983
        if ( test_mem == 1 )
15984
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
15985
                        pci_image_base, 32'h8765_4321, 4'h0,
15986
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
15987
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
15988
        else
15989
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
15990
 
15991
        do_pause(1) ;
15992
    end
15993
    begin
15994
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
15995
        begin
15996
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
15997
            if ( ok_wb !== 1 )
15998
            begin
15999
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16000
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16001
                disable main ;
16002
            end
16003
        end
16004
 
16005
        // set WB slave to normal completion
16006
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16007
 
16008
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
16009
        if ( ok_wb !== 1 )
16010
        begin
16011
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16012
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16013
            disable main ;
16014
        end
16015
 
16016
        if ( ok_pci )
16017
            disable error_monitor3 ;
16018
    end
16019
    begin:error_monitor3
16020
        @(error_event_int) ;
16021
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16022
        ok_pci = 0 ;
16023
    end
16024
    join
16025
 
16026
    if ( ok_wb && ok_pci )
16027
    begin
16028
        test_ok ;
16029
    end
16030
 
16031
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
16032
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16033
    if ( temp_val1[8] !== 1'b1 )
16034
    begin
16035
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
16036
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
16037
    end
16038
 
16039
    if ( temp_val1[9] !== 1 )
16040
    begin
16041
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Error Source bit when retry counter expires during a write! Time %t", $time) ;
16042
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
16043
    end
16044
 
16045
    if ( temp_val1[10] !== 1 )
16046
    begin
16047
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Retry Expired bit when retry counter expires during a write! Time %t", $time) ;
16048
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
16049
    end
16050
 
16051
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
16052
    begin
16053
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in bus command field in error control and status register when retry counter expired during a write! Time %t", $time) ;
16054
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
16055
    end
16056
 
16057
    if ( temp_val1[31:28] !== 4'hA )
16058
    begin
16059
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in byte enable field in error control and status register when retry counter expired during a write! Time %t", $time) ;
16060
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
16061
    end
16062
 
16063
    // clear error status register
16064
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
16065
 
16066
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
16067
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
16068
    if ( temp_val1 !== pci_image_base )
16069
    begin
16070
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
16071
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
16072
    end
16073
 
16074
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
16075
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
16076
    if ( temp_val1 !== 32'hDEAD_BEAF )
16077
    begin
16078
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
16079
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
16080
    end
16081
 
16082
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
16083
    ok_pci = 1 ;
16084
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
16085
 
16086
    i = 0 ;
16087
    fork
16088
    begin
16089
        if ( test_mem )
16090
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16091
                          pci_image_base + 4, 32'h1234_5678,
16092
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
16093
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
16094
        else
16095
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
16096
 
16097
        do_pause( 1 ) ;
16098
 
16099
    end
16100
    begin
16101
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
16102
        begin
16103
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
16104
            if ( ok_wb !== 1 )
16105
            begin
16106
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16107
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16108
                disable main ;
16109
            end
16110
        end
16111
 
16112
        // set WB slave to normal completion
16113
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16114
 
16115
        fork
16116
        begin
16117
            repeat(4)
16118
                @(posedge pci_clock) ;
16119
 
16120
            if ( test_mem )
16121
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16122
                              pci_image_base, 32'h8765_4321,
16123
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
16124
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
16125
            else
16126
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
16127
 
16128
            do_pause(1) ;
16129
        end
16130
        begin
16131
 
16132
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
16133
            if ( ok_wb !== 1 )
16134
            begin
16135
                $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16136
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16137
                disable main ;
16138
            end
16139
        end
16140
        join
16141
 
16142
        repeat( 4 )
16143
            @(posedge pci_clock) ;
16144
 
16145
        if ( test_mem )
16146
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16147
                          pci_image_base, 32'h8765_4321,
16148
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
16149
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16150
        else
16151
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
16152
 
16153
        do_pause(1) ;
16154
 
16155
        if ( ok_pci )
16156
            disable error_monitor4 ;
16157
    end
16158
    begin:error_monitor4
16159
        @(error_event_int) ;
16160
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16161
        ok_pci = 0 ;
16162
    end
16163
    join
16164
 
16165
    if ( ok_wb && ok_pci )
16166
        test_ok ;
16167
 
16168
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
16169
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16170
    if ( temp_val1[8] !== 1'b0 )
16171
    begin
16172
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master shouldn't signal an error when retry counter expires during a read! Time %t", $time) ;
16173
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
16174
    end
16175
 
16176
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
16177
    ok_pci = 1 ;
16178
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
16179
 
16180
    fork
16181
    begin
16182
        if ( test_mem )
16183
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16184
                          pci_image_base + 4, 32'h1234_5678,
16185
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
16186
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
16187
        else
16188
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
16189
 
16190
        do_pause( 1 ) ;
16191
 
16192
    end
16193
    begin
16194
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
16195
        if ( ok_wb !== 1 )
16196
        begin
16197
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16198
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16199
            disable main ;
16200
        end
16201
 
16202
        repeat(4)
16203
            @(posedge pci_clock) ;
16204
 
16205
        fork
16206
        begin
16207
 
16208
            if ( test_mem )
16209
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
16210
                              pci_image_base + 4, 32'h8765_4321,
16211
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
16212
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
16213
            else
16214
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
16215
 
16216
            do_pause(1) ;
16217
 
16218
        end
16219
        begin
16220
 
16221
            pci_transaction_progress_monitor( pci_image_base + 4, test_mem ? `BC_MEM_READ : `BC_IO_READ, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
16222
            if ( ok !== 1 )
16223
            begin
16224
                $display("WISHBONE Master Retry Counter expiration test failed! PCI transaction progress monitor detected invalid transaction or none at all on PCI bus! Time %t", $time) ;
16225
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
16226
                disable main ;
16227
            end
16228
        end
16229
        join
16230
 
16231
        if ( ok_pci )
16232
            disable error_monitor5 ;
16233
    end
16234
    begin:error_monitor5
16235
        @(error_event_int) ;
16236
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16237
        ok_pci = 0 ;
16238
    end
16239
    join
16240
 
16241
    if ( ok_wb && ok_pci )
16242
        test_ok ;
16243
 
16244
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
16245
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16246
    if ( temp_val1[8] !== 1'b0 )
16247
    begin
16248
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master shouldn't signal an error when retry counter expires during a read! Time %t", $time) ;
16249
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
16250
    end
16251
 
16252
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
16253
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
16254
    if ( temp_val1[25] !== 1'b1 )
16255
    begin
16256
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
16257
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
16258
    end
16259
 
16260
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
16261
 
16262
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
16263
    ok_pci = 1 ;
16264
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
16265
 
16266
    fork
16267
    begin
16268
        if ( test_mem == 1 )
16269
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
16270
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
16271
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
16272
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16273
        else
16274
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
16275
 
16276
        do_pause(1) ;
16277
 
16278
        // do another write with same address and different data
16279
        if ( test_mem == 1 )
16280
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
16281
                        pci_image_base, 32'h8765_6789, 4'h0,
16282
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
16283
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
16284
        else
16285
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
16286
 
16287
        do_pause(1) ;
16288
 
16289
        $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
16290
        $fdisplay(pciu_mon_log_file_desc,
16291
        "********************************************  Monitor will complain in following section for a few times - testbench is intentionally causing no response  *********************************************") ;
16292
    end
16293
    begin
16294
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
16295
        if ( ok_wb !== 1 )
16296
        begin
16297
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16298
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16299
            disable main ;
16300
        end
16301
 
16302
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
16303
 
16304
        if ( test_mem )
16305
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
16306
        else
16307
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
16308
 
16309
        if ( ok_wb !== 1 )
16310
        begin
16311
            $display("WISHBONE Master Retry Counter expiration test failed! WB transaction progress monitor detected invalid transaction or none at all on WB bus! Time %t", $time) ;
16312
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
16313
            disable main ;
16314
        end
16315
 
16316
        if ( ok_pci )
16317
            disable error_monitor6 ;
16318
    end
16319
    begin:error_monitor6
16320
        @(error_event_int) ;
16321
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
16322
        ok_pci = 0 ;
16323
    end
16324
    join
16325
 
16326
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
16327
    $fdisplay(pciu_mon_log_file_desc,
16328
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
16329
 
16330
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
16331
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
16332
    if ( temp_val1[8] !== 1'b1 )
16333
    begin
16334
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when no response counter expires during a write! Time %t", $time) ;
16335
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
16336
    end
16337
 
16338
    if ( temp_val1[9] !== 0 )
16339
    begin
16340
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should not set Error Source bit when no response counter expires during a write! Time %t", $time) ;
16341
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
16342
    end
16343
 
16344
    if ( temp_val1[10] !== 1 )
16345
    begin
16346
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should set Retry Expired bit when no response counter expires during a write! Time %t", $time) ;
16347
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
16348
    end
16349
 
16350
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
16351
    begin
16352
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in bus command field in error control and status register when no response counter expired during a write! Time %t", $time) ;
16353
        test_fail("bus command field in error control and status register was wrong when no response counter expired during posted write through PCI Target unit") ;
16354
    end
16355
 
16356
    if ( temp_val1[31:28] !== 4'h0 )
16357
    begin
16358
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in byte enable field in error control and status register when no response counter expired during a write! Time %t", $time) ;
16359
        test_fail("byte enable field in error control and status register was wrong when no response counter expired during posted write through PCI Target unit") ;
16360
    end
16361
 
16362
    // clear error status register
16363
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
16364
 
16365
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
16366
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
16367
    if ( temp_val1 !== pci_image_base )
16368
    begin
16369
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when no response counter expired during a write! Time %t", $time) ;
16370
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
16371
    end
16372
 
16373
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
16374
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
16375
    if ( temp_val1 !== 32'hBEAF_DEAD )
16376
    begin
16377
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when no response counter expired during a write! Time %t", $time) ;
16378
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
16379
    end
16380
 
16381
    // disable current image - write address mask register
16382
    config_write( pci_am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
16383 15 mihad
end
16384
endtask // target_completion_expired
16385
 
16386
task config_write ;
16387
    input [11:0] offset ;
16388
    input [31:0] data ;
16389
    input [3:0]  byte_enable ;
16390
    output       ok ;
16391
    `ifdef HOST
16392
    reg   `WRITE_STIM_TYPE   write_data ;
16393
    reg   `WB_TRANSFER_FLAGS write_flags ;
16394
    reg   `WRITE_RETURN_TYPE write_status ;
16395
    `else
16396
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
16397
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
16398
    `endif
16399
    reg in_use ;
16400
    reg [31:0] temp_var ;
16401
begin
16402
    if ( in_use === 1 )
16403
    begin
16404
        $display("config_read task re-entered! Time %t ", $time) ;
16405
        ok = 0 ;
16406
        #20 $stop ;
16407
    end
16408
    else
16409
    begin
16410
        ok = 1 ;
16411
        in_use = 1 ;
16412
    end
16413
    `ifdef HOST
16414
    write_flags                    = 0 ;
16415
    write_flags`INIT_WAITS         = tb_init_waits ;
16416
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
16417
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
16418
 
16419
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
16420
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
16421
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
16422
    write_data`WRITE_SEL                         = byte_enable ;
16423
    write_data`WRITE_TAG_STIM                    = 0 ;
16424
    write_data`WRITE_DATA                        = data ;
16425
 
16426
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
16427
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
16428
    begin
16429
        $display("Write to configuration space failed! Time %t ", $time) ;
16430
        ok = 0 ;
16431
    end
16432
 
16433
    @(posedge wb_clock) ;
16434
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
16435
    // here we just wait for two guest cycles for conf space bits to synchronize
16436
    repeat( 2 )
16437
        @(posedge pci_clock) ;
16438
 
16439
    `else // GUEST
16440
    byte_enables_l = ~byte_enable ;
16441
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
16442
 
16443
    fork
16444
    begin
16445
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16446
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16447
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
16448
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16449
              8'h0_0, `Test_One_Zero_Target_WS,
16450
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
16451
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16452
    do_pause( 1 ) ;
16453
    end
16454
    begin
16455
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
16456
        @(posedge pci_clock) ;
16457
    end
16458
    join
16459
 
16460
     repeat( 2 )
16461
         @(posedge wb_clock) ;
16462
 
16463
    `endif
16464
    in_use = 0 ;
16465
end
16466
endtask // config_write
16467
 
16468
task config_read ;
16469
    input [11:0] offset ;
16470
    input [3:0]  byte_enable ;
16471
    output [31:0] data ;
16472
 
16473
    reg `READ_STIM_TYPE    read_data ;
16474
    reg `WB_TRANSFER_FLAGS read_flags ;
16475
    reg `READ_RETURN_TYPE  read_status ;
16476
 
16477
    reg [31:0] pci_address ;
16478
    reg [3:0] byte_enables_l ;
16479
 
16480
    reg master_check_data_prev ;
16481
    reg in_use ;
16482
    reg [31:0] temp_var ;
16483
begin:main
16484
    if ( in_use === 1 )
16485
    begin
16486
        $display("config_read task re-entered! Time %t ", $time) ;
16487
        data = 32'hxxxx_xxxx ;
16488
        disable main ;
16489
    end
16490
 
16491
    in_use = 1 ;
16492
 
16493
`ifdef HOST
16494 26 mihad
    repeat(4)
16495
        @(posedge pci_clock) ;
16496
    repeat(4)
16497
        @(posedge wb_clock) ;
16498 15 mihad
    read_flags                    = 0 ;
16499
    read_flags`INIT_WAITS         = tb_init_waits ;
16500
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
16501
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
16502
 
16503
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
16504
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
16505
 
16506
    read_data`READ_ADDRESS  = temp_var + offset ;
16507
    read_data`READ_SEL      = byte_enable ;
16508
    read_data`READ_TAG_STIM = 0 ;
16509
 
16510
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
16511
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
16512
    begin
16513
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
16514
        #20 $stop ;
16515
    end
16516
    data = read_status`READ_DATA ;
16517
`else
16518
  `ifdef GUEST
16519 26 mihad
    repeat(4)
16520
        @(posedge wb_clock) ;
16521
    repeat(4)
16522
        @(posedge pci_clock) ;
16523 15 mihad
    master_check_data_prev = master2_check_received_data ;
16524
    master2_check_received_data = 0 ;
16525
 
16526
    byte_enables_l = ~byte_enable ;
16527
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
16528
 
16529
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16530
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16531
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
16532
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16533
             8'h4_0, `Test_One_Zero_Target_WS,
16534
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
16535
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16536
    do_pause( 1 ) ;
16537
 
16538
    @(master2_received_data_valid) ;
16539
    data = master2_received_data ;
16540
 
16541
    master2_check_received_data = master_check_data_prev ;
16542
  `endif
16543
`endif
16544
    in_use = 0 ;
16545
end
16546
endtask //config_read
16547
 
16548
task test_fail ;
16549
    input [7999:0] failure_reason ;
16550
    reg   [8007:0] display_failure ;
16551
    reg   [799:0] display_test ;
16552
begin
16553
    tests_failed = tests_failed + 1 ;
16554
 
16555
    display_failure = {failure_reason, "!"} ;
16556
    while ( display_failure[7999:7992] == 0 )
16557
        display_failure = display_failure << 8 ;
16558
 
16559
    display_test = test_name ;
16560
    while ( display_test[799:792] == 0 )
16561
       display_test = display_test << 8 ;
16562
 
16563
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16564
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
16565
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
16566
    $fdisplay( tb_log_file, " *FAILED* because") ;
16567
    $fdisplay( tb_log_file, " %s", display_failure ) ;
16568
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16569
    $fdisplay( tb_log_file, " " ) ;
16570
 
16571
    `ifdef STOP_ON_FAILURE
16572
    #20 $stop ;
16573
    `endif
16574
end
16575
endtask // test_fail
16576
 
16577
task test_ok ;
16578
    reg [799:0] display_test ;
16579
begin
16580
   tests_successfull = tests_successfull + 1 ;
16581
 
16582
   display_test = test_name ;
16583
   while ( display_test[799:792] == 0 )
16584
       display_test = display_test << 8 ;
16585
 
16586
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16587
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
16588
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
16589
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
16590
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
16591
   $fdisplay( tb_log_file, " " ) ;
16592
end
16593
endtask // test_ok
16594
 
16595
task test_summary;
16596
begin
16597
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
16598
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
16599
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
16600
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
16601
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
16602
    $fclose(tb_log_file) ;
16603
end
16604
endtask
16605
 
16606
endmodule

powered by: WebSVN 2.1.0

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