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

Subversion Repositories pci

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

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 45 mihad
 
38
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
39
 
40 15 mihad
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
 
77 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
78
 
79
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
80
 
81 15 mihad
wire        reset_wb ; // reset to Wb devices
82
 
83
`ifdef GUEST
84
    wire    RST = ~reset ;
85
    assign  reset_wb = RST_O ;
86
`else
87
    pullup(RST) ;
88
    assign  reset_wb = reset ;
89
`endif
90
 
91
`define PCI_BRIDGE_INSTANCE bridge32_top
92
 
93
TOP `PCI_BRIDGE_INSTANCE
94
(
95
    .CLK    ( pci_clock),
96
    .AD     ( AD ),
97
    .CBE    ( CBE ),
98
    .RST    ( RST ),
99
    .INTA   ( INTA ),
100
    .REQ    ( MAS0_REQ ),
101
    .GNT    ( MAS0_GNT ),
102
    .FRAME  ( FRAME ),
103
    .IRDY   ( IRDY ),
104
    .IDSEL  ( TAR0_IDSEL),
105
    .DEVSEL ( DEVSEL ),
106
    .TRDY   ( TRDY ),
107
    .STOP   ( STOP ),
108
    .PAR    ( PAR ),
109
    .PERR   ( PERR ),
110
    .SERR   ( SERR ),
111
 
112
    .CLK_I  ( wb_clock ),
113
    .RST_I  ( reset ),
114
    .RST_O  ( RST_O ),
115
    .INT_I  ( INT_I ),
116
    .INT_O  ( INT_O ),
117
 
118
    // WISHBONE slave interface
119
    .ADR_I  ( ADR_I ),
120
    .SDAT_I ( SDAT_I ),
121
    .SDAT_O ( SDAT_O ),
122
    .SEL_I  ( SEL_I ),
123
    .CYC_I  ( CYC_I ),
124
    .STB_I  ( STB_I ),
125
    .WE_I   ( WE_I ),
126
    .CAB_I  ( CAB_I),
127
    .ACK_O  ( ACK_O ),
128
    .RTY_O  ( RTY_O ),
129
    .ERR_O  ( ERR_O ),
130
 
131
    // WISHBONE master interface
132
    .ADR_O  ( ADR_O ),
133
    .MDAT_I ( MDAT_I ),
134
    .MDAT_O ( MDAT_O ),
135
    .SEL_O  ( SEL_O ),
136
    .CYC_O  ( CYC_O ),
137
    .STB_O  ( STB_O ),
138
    .WE_O   ( WE_O ),
139
    .CAB_O  ( CAB_O ),
140
    .ACK_I  ( ACK_I ),
141
    .RTY_I  ( RTY_I ),
142
    .ERR_I  ( ERR_I )
143
) ;
144
 
145
WB_MASTER_BEHAVIORAL wishbone_master
146
(
147
    .CLK_I(wb_clock),
148
    .RST_I(reset_wb),
149
    .TAG_I(4'b0000),
150
    .TAG_O(),
151
    .ACK_I(ACK_O),
152
    .ADR_O(ADR_I),
153
    .CYC_O(CYC_I),
154
    .DAT_I(SDAT_O),
155
    .DAT_O(SDAT_I),
156
    .ERR_I(ERR_O),
157
    .RTY_I(RTY_O),
158
    .SEL_O(SEL_I),
159
    .STB_O(STB_I),
160
    .WE_O (WE_I),
161
    .CAB_O(CAB_I)
162
);
163
 
164
WB_SLAVE_BEHAVIORAL wishbone_slave
165
(
166
    .CLK_I              (wb_clock),
167
    .RST_I              (reset_wb),
168
    .ACK_O              (ACK_I),
169
    .ADR_I              (ADR_O),
170
    .CYC_I              (CYC_O),
171
    .DAT_O              (MDAT_I),
172
    .DAT_I              (MDAT_O),
173
    .ERR_O              (ERR_I),
174
    .RTY_O              (RTY_I),
175
    .SEL_I              (SEL_O),
176
    .STB_I              (STB_O),
177
    .WE_I               (WE_O),
178
    .CAB_I              (CAB_O)
179
);
180
 
181
integer wbu_mon_log_file_desc ;
182
integer pciu_mon_log_file_desc ;
183
WB_BUS_MON wbu_wb_mon(
184
                    .CLK_I(wb_clock),
185
                    .RST_I(reset_wb),
186
                    .ACK_I(ACK_O),
187
                    .ADDR_O(ADR_I),
188
                    .CYC_O(CYC_I),
189
                    .DAT_I(SDAT_O),
190
                    .DAT_O(SDAT_I),
191
                    .ERR_I(ERR_O),
192
                    .RTY_I(RTY_O),
193
                    .SEL_O(SEL_I),
194
                    .STB_O(STB_I),
195
                    .WE_O (WE_I),
196
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
197
                    .TAG_O(),
198
                    .CAB_O(CAB_I),
199
                    .log_file_desc ( wbu_mon_log_file_desc )
200
                  ) ;
201
 
202
WB_BUS_MON pciu_wb_mon(
203
                    .CLK_I(wb_clock),
204
                    .RST_I(reset_wb),
205
                    .ACK_I(ACK_I),
206
                    .ADDR_O(ADR_O),
207
                    .CYC_O(CYC_O),
208
                    .DAT_I(MDAT_I),
209
                    .DAT_O(MDAT_O),
210
                    .ERR_I(ERR_I),
211
                    .RTY_I(RTY_I),
212
                    .SEL_O(SEL_O),
213
                    .STB_O(STB_O),
214
                    .WE_O (WE_O),
215
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
216
                    .TAG_O(),
217
                    .CAB_O(CAB_O),
218
                    .log_file_desc( pciu_mon_log_file_desc )
219
                  ) ;
220
 
221
// some aditional signals are needed here because of the arbiter
222
reg [3:0] pci_ext_req_prev ;
223
always@(posedge pci_clock)
224
begin
225
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
226
end
227
reg pci_frame_prev ;
228
always@(posedge pci_clock)
229
begin
230
    pci_frame_prev <= FRAME ;
231
end
232
reg pci_irdy_prev ;
233
always@(posedge pci_clock)
234
begin
235
    pci_irdy_prev <= IRDY ;
236
end
237
 
238
pci_blue_arbiter pci_arbiter
239
(
240
  .pci_int_req_direct(1'b0),
241
  .pci_ext_req_prev(pci_ext_req_prev),
242
  .pci_int_gnt_direct_out(arb_grant_out[4]),
243
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
244
  .pci_frame_prev(~pci_frame_prev),
245
  .pci_irdy_prev(~pci_irdy_prev),
246
  .pci_irdy_now(~IRDY),
247
  .arbitration_enable(1'b1),
248
  .pci_clk(pci_clock),
249
  .pci_reset_comb(~RST)
250
);
251
 
252
reg [31:0] target_message ;
253
 
254
// define output enable signals for monitor inputs
255
// real output enable signals
256
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
257
`ifdef ACTIVE_LOW_OE
258
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
259
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
260
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
261
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
262
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
263
                        !devsel_t_s_oe,
264
                        !ad_oe,
265
                        !cbe_oe,
266
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
267
                        ;
268
`else
269
`ifdef ACTIVE_HIGH_OE
270
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
271
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
272
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
273
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
274
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
275
                        devsel_t_s_oe,
276
                        ad_oe,
277
                        cbe_oe,
278
                        `PCI_BRIDGE_INSTANCE.PERR_en}
279
                        ;
280
`endif
281
`endif
282
/*wire [5:0] oe_sigs_0 = {1'b0,
283
                        1'b0,
284
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
285
                        pci_target32.ad_enable,
286
                        1'b0,
287
                        pci_target32.err_enable | pci_target32.r_err_enable
288
                       } ;
289
*/
290
 
291
wire [5:0] oe_sigs_2 ;
292
wire [5:0] oe_sigs_1 ;
293
 
294
// signals which are used by test modules to know what to do
295
triand  test_accepted_l_int, error_event_int;
296
pullup  (test_accepted_l_int), (error_event_int);
297
 
298
wire    pci_reset_comb  = ~RST;
299
wire    pci_ext_clk     = pci_clock;
300
 
301
integer pci_mon_log_file_desc ;
302
pci_bus_monitor monitor32
303
(
304
    .pci_ext_ad                 (AD),
305
    .pci_ext_cbe_l              (CBE),
306
    .pci_ext_par                (PAR),
307
    .pci_ext_frame_l            (FRAME),
308
    .pci_ext_irdy_l             (IRDY),
309
    .pci_ext_devsel_l           (DEVSEL),
310
    .pci_ext_trdy_l             (TRDY),
311
    .pci_ext_stop_l             (STOP),
312
    .pci_ext_perr_l             (PERR),
313
    .pci_ext_serr_l             (SERR),
314
    .pci_real_req_l             (MAS0_REQ),
315
    .pci_real_gnt_l             (MAS0_GNT),
316
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
317
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
318
    .test_error_event           (error_event_int),
319
    .test_observe_r_oe_sigs     (r_oe_sigs),
320
    .test_observe_0_oe_sigs     (6'h00),
321
    .test_observe_1_oe_sigs     (oe_sigs_1),
322
    .test_observe_2_oe_sigs     (oe_sigs_2),
323
    .test_observe_3_oe_sigs     (6'h00),
324
    .pci_ext_reset_l            (RST),
325
    .pci_ext_clk                (pci_clock),
326
    .log_file_desc              (pci_mon_log_file_desc)
327
) ;
328
 
329
reg [2:0]  test_master_number ;
330
reg [31:0] test_address ;
331
reg [3:0]  test_command ;
332
reg [31:0] test_data ;
333
reg [3:0]  test_byte_enables_l ;
334
reg [9:0]  test_size ;
335
reg        test_make_addr_par_error ;
336
reg        test_make_data_par_error ;
337
reg [3:0]  test_master_initial_wait_states ;
338
reg [3:0]  test_master_subsequent_wait_states ;
339
reg [3:0]  test_target_initial_wait_states ;
340
reg [3:0]  test_target_subsequent_wait_states ;
341
reg [1:0]  test_target_devsel_speed ;
342
reg        test_fast_back_to_back ;
343
reg [2:0]  test_target_termination ;
344
reg        test_expect_master_abort ;
345
reg        test_start ;
346
reg [25:0] test_target_response ;
347
 
348
wire [31:0] master2_received_data ;
349
wire        master2_received_data_valid ;
350
reg         master2_check_received_data ;
351
pci_behaviorial_device pci_behaviorial_device2
352
(
353
    .pci_ext_ad(AD),
354
    .pci_ext_cbe_l(CBE),
355
    .pci_ext_par(PAR),
356
    .pci_ext_frame_l(FRAME),
357
    .pci_ext_irdy_l(IRDY),
358
    .pci_ext_devsel_l(DEVSEL),
359
    .pci_ext_trdy_l(TRDY),
360
    .pci_ext_stop_l(STOP),
361
    .pci_ext_perr_l(PERR),
362
    .pci_ext_serr_l(SERR),
363
    .pci_ext_idsel(TAR2_IDSEL),
364
    .pci_ext_inta_l(INTA),
365
    .pci_ext_req_l(MAS2_REQ),
366
    .pci_ext_gnt_l(MAS2_GNT),
367
    .pci_ext_reset_l(RST),
368
    .pci_ext_clk(pci_clock),
369
 
370
// Signals used by the test bench instead of using "." notation
371
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
372
    .test_master_number                 (test_master_number[2:0]),
373
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
374
    .test_command                       (test_command[3:0]),
375
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
376
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
377
    .test_size                          (test_size),
378
    .test_make_addr_par_error           (test_make_addr_par_error),
379
    .test_make_data_par_error           (test_make_data_par_error),
380
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
381
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
382
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
383
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
384
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
385
    .test_fast_back_to_back             (test_fast_back_to_back),
386
    .test_target_termination            (test_target_termination[2:0]),
387
    .test_expect_master_abort           (test_expect_master_abort),
388
    .test_start                         (test_start),
389
    .test_accepted_l                    (test_accepted_l_int),
390
    .test_error_event                   (error_event_int),
391
    .test_device_id                     (`Test_Master_2),
392
    .test_target_response               (test_target_response),
393
 
394
    .master_received_data               (master2_received_data),
395
    .master_received_data_valid         (master2_received_data_valid),
396
    .master_check_received_data         (master2_check_received_data)
397
);
398
 
399
wire [31:0] master1_received_data ;
400
wire        master1_received_data_valid ;
401
reg         master1_check_received_data ;
402
pci_behaviorial_device pci_behaviorial_device1
403
(
404
    .pci_ext_ad(AD),
405
    .pci_ext_cbe_l(CBE),
406
    .pci_ext_par(PAR),
407
    .pci_ext_frame_l(FRAME),
408
    .pci_ext_irdy_l(IRDY),
409
    .pci_ext_devsel_l(DEVSEL),
410
    .pci_ext_trdy_l(TRDY),
411
    .pci_ext_stop_l(STOP),
412
    .pci_ext_perr_l(PERR),
413
    .pci_ext_serr_l(SERR),
414
    .pci_ext_idsel(TAR1_IDSEL),
415
    .pci_ext_inta_l(INTA),
416
    .pci_ext_req_l(MAS1_REQ),
417
    .pci_ext_gnt_l(MAS1_GNT),
418
    .pci_ext_reset_l(RST),
419
    .pci_ext_clk(pci_clock),
420
 
421
// Signals used by the test bench instead of using "." notation
422
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
423
    .test_master_number                 (test_master_number[2:0]),
424
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
425
    .test_command                       (test_command[3:0]),
426
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
427
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
428
    .test_size                          (test_size),
429
    .test_make_addr_par_error           (test_make_addr_par_error),
430
    .test_make_data_par_error           (test_make_data_par_error),
431
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
432
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
433
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
434
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
435
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
436
    .test_fast_back_to_back             (test_fast_back_to_back),
437
    .test_target_termination            (test_target_termination[2:0]),
438
    .test_expect_master_abort           (test_expect_master_abort),
439
    .test_start                         (test_start),
440
    .test_accepted_l                    (test_accepted_l_int),
441
    .test_error_event                   (error_event_int),
442
    .test_device_id                     (`Test_Master_1),
443
    .test_target_response               (test_target_response),
444
 
445
    .master_received_data               (master1_received_data),
446
    .master_received_data_valid         (master1_received_data_valid),
447
    .master_check_received_data         (master1_check_received_data)
448
);
449
 
450
pci_unsupported_commands_master ipci_unsupported_commands_master
451
(
452
    .CLK    ( pci_clock),
453
    .AD     ( AD ),
454
    .CBE    ( CBE ),
455
    .RST    ( RST ),
456
    .REQ    ( MAS3_REQ ),
457
    .GNT    ( MAS3_GNT ),
458
    .FRAME  ( FRAME ),
459
    .IRDY   ( IRDY ),
460
    .DEVSEL ( DEVSEL ),
461
    .TRDY   ( TRDY ),
462
    .STOP   ( STOP ),
463
    .PAR    ( PAR )
464
) ;
465
 
466 45 mihad
`ifdef HOST
467
 
468
reg     [1:0]   conf_cyc_type1_target_response ;
469
reg     [31:0]  conf_cyc_type1_target_data ;
470
reg     [7:0]   conf_cyc_type1_target_bus_num ;
471
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
472
 
473
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
474
(
475
    .CLK              ( pci_clock),
476
    .AD               ( AD ),
477
    .CBE              ( CBE ),
478
    .RST              ( RST ),
479
    .FRAME            ( FRAME ),
480
    .IRDY             ( IRDY ),
481
    .DEVSEL           ( DEVSEL ),
482
    .TRDY             ( TRDY ),
483
    .STOP             ( STOP ),
484
    .PAR              ( PAR ),
485
 
486
    .response         ( conf_cyc_type1_target_response ),
487
    .data_out         ( conf_cyc_type1_target_data ),
488
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
489
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
490
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
491
    .bus_number       ( conf_cyc_type1_target_bus_num )
492
);
493
`endif
494
 
495 15 mihad
// pci clock generator
496
always
497
`ifdef PCI33
498
    #15 pci_clock = ~pci_clock ;
499
`else
500
`ifdef PCI66
501
    #7.5 pci_clock = ~pci_clock ;
502
`endif
503
`endif
504
 
505
// WISHBONE clock generation
506
always
507
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
508
 
509
// Make test name visible when the Master starts working on it
510
reg     [79:0] present_test_name;
511
reg     [79:0] next_test_name;
512
wire    test_accepted = ~test_accepted_l_int;
513
always @(posedge test_accepted)
514
begin
515
    present_test_name <= next_test_name;
516
end
517
 
518
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
519
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
520
 
521
// basic configuration parameters for both behavioral devices
522
parameter [2:0] Master_ID_A                           = `Test_Master_1;
523
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
524
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
525
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
526
 
527
parameter [2:0] Master_ID_B                           = `Test_Master_2;
528
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
529
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
530
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
531
 
532
// basic configuration parameters for REAL device
533
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
534
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
535
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
536
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
537
 
538
// reg  [2:0]   ack_err_rty_termination ;
539
// reg          wait_cycles ;
540
// reg  [7:0]   num_of_retries ;
541
 
542
//reg [19:0] pci_config_base ;
543
reg [7:0] system_burst_size ;
544
reg [7:0] bridge_latency ;
545
integer   target_mem_image ;
546
integer   target_io_image ;
547
 
548
initial
549
begin
550
    next_test_name[79:0] <= "Nowhere___";
551
    reset = 1'b1 ;
552
    pci_clock = 1'b0 ;
553
    wb_clock  = 1'b1 ;
554
    target_message = 32'h0000_0000 ;
555
//  num_of_retries = 8'h01 ;
556
//  ack_err_rty_termination = 3'b100 ;
557
//  wait_cycles = 1'b0 ;
558
 
559
    // system paameters
560
    system_burst_size = 16 ;
561
    bridge_latency    = 8 ;
562
 
563
    // set initial values for controling the behavioral PCI master
564
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
565
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
566
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
567
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
568
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
569
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
570
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
571
 
572
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
573
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
574
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
575
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
576
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
577
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
578
 
579
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
580
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
581
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
582
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
583
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
584
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
585
 
586
    test_master_number = `Test_Master_2 ;
587
    test_address = 32'h0000_0000 ;
588
    test_command = `BC_RESERVED0 ;
589
    test_data = 32'h0000_0000 ;
590
    test_byte_enables_l   = 4'hF ;
591
    test_size = 0 ;
592
    test_make_addr_par_error = 0 ;
593
    test_make_data_par_error = 0;
594
    test_master_initial_wait_states = 0 ;
595
    test_master_subsequent_wait_states = 0 ;
596
    test_target_initial_wait_states = 0 ;
597
    test_target_subsequent_wait_states = 0;
598
    test_target_devsel_speed = `Test_Devsel_Fast ;
599
    test_fast_back_to_back = 0 ;
600
    test_target_termination = `Test_Target_Normal_Completion ;
601
    test_expect_master_abort = 0 ;
602
    test_start = 0 ;
603
    test_target_response = 0 ;
604
 
605
    master1_check_received_data = 0 ;
606
    master2_check_received_data = 0 ;
607
 
608 45 mihad
    `ifdef HOST
609
        conf_cyc_type1_target_response = 0 ;
610
        conf_cyc_type1_target_data = 0 ;
611
        conf_cyc_type1_target_bus_num = 255 ;
612
    `endif
613 15 mihad
 
614
    // fill memory and IO data with random values
615
    fill_memory ;
616
 
617
    INT_I = 0 ;
618
 
619
    // extract from constants which target image can be used as IO and which as memory
620
    `ifdef HOST
621
        target_mem_image = 1 ;
622
        target_io_image  = 1 ;
623
    `else
624
        target_mem_image = -1 ;
625
        target_io_image     = -1 ;
626
        if ( `PCI_BA1_MEM_IO === 0 )
627
            target_mem_image = 1 ;
628
        else
629
            target_io_image = 1 ;
630
 
631
        if ( target_mem_image === -1 )
632
        begin
633
            `ifdef PCI_IMAGE2
634
                if ( `PCI_BA2_MEM_IO === 0 )
635
                    target_mem_image = 2 ;
636
                else if ( target_io_image === -1 )
637
                    target_io_image = 2 ;
638
            `endif
639
        end
640
 
641
        if ( target_mem_image === -1 )
642
        begin
643
            `ifdef PCI_IMAGE3
644
                if ( `PCI_BA3_MEM_IO === 0 )
645
                    target_mem_image = 3 ;
646
                else if ( target_io_image === -1 )
647
                    target_io_image = 3 ;
648
            `endif
649
        end
650
 
651
        if ( target_mem_image === -1 )
652
        begin
653
            `ifdef PCI_IMAGE4
654
                if ( `PCI_BA4_MEM_IO === 0 )
655
                    target_mem_image = 4 ;
656
                else if ( target_io_image === -1 )
657
                    target_io_image = 4 ;
658
            `endif
659
        end
660
 
661
        if ( target_mem_image === -1 )
662
        begin
663
            `ifdef PCI_IMAGE5
664
                if ( `PCI_BA5_MEM_IO === 0 )
665
                    target_mem_image = 5 ;
666
                else if ( target_io_image === -1 )
667
                    target_io_image = 5 ;
668
            `endif
669
        end
670
    `endif
671
 
672
    tests_successfull = 0 ;
673
    tests_failed = 0 ;
674
 
675
    tb_log_file = $fopen("../log/pci_tb.log") ;
676
 
677
    if ( tb_log_file < 2 )
678
    begin
679
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
680
        $finish ;
681
    end
682
 
683
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
684
    $fdisplay( tb_log_file,"" ) ;
685
 
686
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
687
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
688
 
689
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
690
    begin
691
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
692
        $finish ;
693
    end
694
 
695
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
696
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
697
 
698
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
699
    if ( pci_mon_log_file_desc < 2 )
700
    begin
701
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
702
        $finish ;
703
    end
704
 
705
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
706
 
707
    run_tests ;
708
end
709
 
710
task fill_memory ;
711
    integer temp_index ;
712
begin
713
    // fill write memories with random data
714
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
715
    begin
716
        wmem_data[temp_index[9:0]] = $random ;
717 26 mihad
        # 1;
718 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
719 26 mihad
        # 1;
720 15 mihad
    end
721
    // fill WB slave behavioral MEMORY
722
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
723
    begin
724
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
725
        # 1;
726
    end
727
end
728
endtask // fill_memory
729
 
730
reg [2:0] tb_init_waits ;
731
reg [2:0] tb_subseq_waits ;
732
reg [2:0] tb_target_decode_speed ;
733
 
734
task run_tests ;
735
begin
736
    // first - reset logic
737
    do_reset ;
738 45 mihad
    test_initial_conf_values ;
739
 
740 15 mihad
    next_test_name[79:0] <= "Initing...";
741
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
742
 
743
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
744
    begin
745
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
746
        begin
747
 
748
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
749
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
750
 
751
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
752
            begin
753
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
754
 
755
                `ifdef HOST
756
                    configure_bridge_target ;
757
                    find_pci_devices ;
758 45 mihad
                    test_configuration_cycle_target_abort ;
759
                    test_configuration_cycle_type1_generation ;
760 15 mihad
                `endif
761
 
762
                @(posedge pci_clock) ;
763
                configure_target(1) ;
764
                @(posedge pci_clock) ;
765
                configure_target(2) ;
766
 
767
                `ifdef GUEST
768
                    configure_bridge_target ;
769
                `endif
770
 
771
               next_test_name[79:0] <= "WB_SLAVE..";
772
 
773
                $display("Testing WISHBONE slave images' features!") ;
774
                test_wb_image(1) ;
775
 
776
                `ifdef WB_IMAGE2
777
                    test_wb_image(2) ;
778
                `else
779
                    $display(" WB IMAGE 2 not implemented! ") ;
780
                `endif
781
 
782
                `ifdef WB_IMAGE3
783
                    test_wb_image(3) ;
784
                `else
785
                    $display(" WB IMAGE 3 not implemented! ") ;
786
                `endif
787
 
788
                `ifdef WB_IMAGE4
789
                    test_wb_image(4) ;
790
                `else
791
                    $display(" WB IMAGE 4 not implemented! ") ;
792
                `endif
793
 
794
                `ifdef WB_IMAGE5
795
                    test_wb_image(5) ;
796
                `else
797
                    $display(" WB IMAGE 5 not implemented! ") ;
798
                `endif
799
 
800
                wb_slave_errors ;
801
                wb_to_pci_error_handling ;
802
 
803
                parity_checking ;
804
 
805
                wb_to_pci_transactions ;
806
 
807
                `ifdef HOST
808
                iack_cycle ;
809
                `endif
810
 
811
            end
812
            $display(" ") ;
813
            $display("WB slave images' tests finished!") ;
814
 
815
            $display("########################################################################") ;
816
            $display("########################################################################") ;
817
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
818
            $display("########################################################################") ;
819
            $display("########################################################################") ;
820
 
821
            $display("Testing PCI target images' features!") ;
822
            configure_bridge_target_base_addresses ;
823
 
824
            `ifdef HOST
825
             `ifdef NO_CNF_IMAGE
826
              `ifdef PCI_IMAGE0
827
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
828
            test_pci_image(0) ;
829
              `else
830
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
831
              `endif
832
             `else
833
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
834
             `endif
835
            `endif
836
 
837
            $display("PCI image 1 is ALWAYS implemented!") ;
838
            test_pci_image(1) ;
839
 
840
            `ifdef PCI_IMAGE2
841
            $display("PCI image 2 is implemented!") ;
842
            test_pci_image(2) ;
843
            `else
844
            $display("PCI image 2 is NOT implemented!") ;
845
            `endif
846
 
847
            `ifdef PCI_IMAGE3
848
            $display("PCI image 3 is implemented!") ;
849
            test_pci_image(3) ;
850
            `else
851
            $display("PCI image 3 is NOT implemented!") ;
852
            `endif
853
 
854
            `ifdef PCI_IMAGE4
855
            $display("PCI image 4 is implemented!") ;
856
            test_pci_image(4) ;
857
            `else
858
            $display("PCI image 4 is NOT implemented!") ;
859
            `endif
860
 
861
            `ifdef PCI_IMAGE5
862
            $display("PCI image 5 is implemented!") ;
863
            test_pci_image(5) ;
864
            `else
865
            $display("PCI image 5 is NOT implemented!") ;
866
            `endif
867
 
868
            test_wb_error_rd ;
869
 
870
            target_fast_back_to_back ;
871
            target_disconnects ;
872
 
873
            if ( target_io_image !== -1 )
874
                test_target_abort( target_io_image ) ;
875
            $display(" ") ;
876
            $display("PCI target images' tests finished!") ;
877
 
878
            transaction_ordering ;
879 33 mihad
 
880
            target_completion_expiration ;
881 15 mihad
            $display(" ") ;
882
            $display("PCI transaction ordering tests finished!") ;
883
        end
884
    end
885
 
886
    test_summary ;
887
 
888
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
889
    $stop ;
890
end
891
endtask // run_tests
892
 
893
task do_reset;
894
begin
895
    next_test_name[79:0] <= "Reset.....";
896
 
897
    reset = 1'b1 ;
898
    #100 ;
899
    `ifdef HOST
900
        @(posedge wb_clock) ;
901
    `else
902
    `ifdef GUEST
903
        @(posedge pci_clock) ;
904
    `endif
905
    `endif
906
 
907
    reset <= 1'b0 ;
908
 
909 45 mihad
    `ifdef HOST
910
        @(posedge wb_clock) ;
911
    `else
912
    `ifdef GUEST
913
        @(posedge pci_clock) ;
914
    `endif
915
    `endif
916
 
917 15 mihad
end
918
endtask
919
 
920
/*############################################################################
921
WB SLAVE UNIT tasks
922
===================
923
############################################################################*/
924
 
925
task configure_target ;
926 45 mihad
    input [1:0]  beh_dev_num ;
927 15 mihad
    reg   [31:0] base_address1 ;
928
    reg   [31:0] base_address2 ;
929
    reg   [2:0]  Master_ID;
930
    reg   [31:0] Target_Config_Addr;
931 45 mihad
    reg   [4:0]  device_num ;
932 15 mihad
begin
933 45 mihad
    if (beh_dev_num === 1)
934 15 mihad
    begin
935
        base_address1       = `BEH_TAR1_MEM_START ;
936
        base_address2       = `BEH_TAR1_IO_START  ;
937
        Master_ID           = `Test_Master_2 ;
938
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
939 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
940 15 mihad
    end
941
    else
942 45 mihad
    if (beh_dev_num === 2)
943 15 mihad
    begin
944
        base_address1       = `BEH_TAR2_MEM_START ;
945
        base_address2       = `BEH_TAR2_IO_START  ;
946
        Master_ID           = `Test_Master_1 ;
947
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
948 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
949 15 mihad
    end
950
 
951
    // write target's base addresses
952
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
953
    // type 0 cycle, byte enables, base address
954
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
955
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
956
 
957
    // enable target's response and master
958
    // enable parity errors, disable system error
959
 
960
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
961
 
962
end
963
endtask //configure_target
964
 
965
task test_wb_image ;
966
    input [2:0]  image_num ;
967
    reg   [11:0] ctrl_offset ;
968
    reg   [11:0] ba_offset ;
969
    reg   [11:0] am_offset ;
970
    reg   [11:0] ta_offset ;
971
    reg   [11:0] err_cs_offset ;
972
    reg `WRITE_STIM_TYPE write_data ;
973
    reg `READ_STIM_TYPE  read_data ;
974
    reg `READ_RETURN_TYPE read_status ;
975
 
976
    reg `WRITE_RETURN_TYPE write_status ;
977
    reg `WB_TRANSFER_FLAGS write_flags ;
978
    reg [31:0] temp_val ;
979
    reg        ok   ;
980
    reg [11:0] pci_ctrl_offset ;
981
    reg [31:0] image_base ;
982
    reg [31:0] target_address ;
983
    reg [31:0] translation_address ;
984
    integer    i ;
985
    integer    j ;
986
begin:main
987
    pci_ctrl_offset = 12'h4 ;
988
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
989
    // image 0 can only be configuration image - start with 1
990
    if (image_num === 1)
991
    begin
992
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
993
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
994
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
995
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
996
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
997
    end
998
    else if (image_num === 2)
999
    begin
1000
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1001
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1002
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1003
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1004
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1005
    end
1006
    else if (image_num === 3)
1007
    begin
1008
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1009
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1010
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1011
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1012
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1013
    end
1014
    else if (image_num === 4)
1015
    begin
1016
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1017
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1018
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1019
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1020
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1021
    end
1022
    else if (image_num === 5)
1023
    begin
1024
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1025
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1026
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1027
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1028
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1029
    end
1030
    else
1031
    begin
1032
        test_name   = "WB IMAGES' FEATURES TEST" ;
1033
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1034
        disable main ;
1035
    end
1036
 
1037
    target_address  = `BEH_TAR1_MEM_START ;
1038
    image_base      = 0 ;
1039
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1040
 
1041
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1042
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1043
    write_flags                      = 0 ;
1044
    write_flags`INIT_WAITS           = tb_init_waits ;
1045
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1046
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1047
 
1048
    test_name = "WB IMAGE CONFIGURATION" ;
1049
    // enable master & target operation
1050
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1051
    if ( ok !== 1 )
1052
    begin
1053
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1054
        test_fail("write to PCI Device Control register didn't succeede");
1055
        disable main ;
1056
    end
1057
 
1058
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1059
    if ( ok !== 1 )
1060
    begin
1061
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1062
        test_fail("write to WB Error Control and Status register didn't succeede");
1063
        disable main ;
1064
    end
1065
 
1066
    // prepare image control register
1067
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1068
    if ( ok !== 1 )
1069
    begin
1070
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1071
        test_fail("write to WB Image Control register didn't succeede");
1072
        disable main ;
1073
    end
1074
 
1075
    // prepare base address register
1076
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1077
    if ( ok !== 1 )
1078
    begin
1079
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1080
        test_fail("write to WB Base Address register didn't succeede");
1081
        disable main ;
1082
    end
1083
 
1084
    // write address mask register
1085
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1086
    if ( ok !== 1 )
1087
    begin
1088
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1089
        test_fail("write to WB Address Mask register didn't succeede");
1090
        disable main ;
1091
    end
1092
 
1093
    fork
1094
    begin
1095
        write_data`WRITE_ADDRESS = target_address ;
1096
        write_data`WRITE_DATA    = wmem_data[0] ;
1097
        write_data`WRITE_SEL     = 4'hF ;
1098
 
1099
        // handle retries from now on
1100
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1101
 
1102
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1103
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1104
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1105
        begin
1106
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1107
            test_fail("WB Slave state machine failed to post single memory write");
1108
            disable main ;
1109
        end
1110
 
1111
        // read written data back
1112
        read_data`READ_ADDRESS  = target_address ;
1113
        read_data`READ_SEL      = 4'hF ;
1114
        read_data`READ_TAG_STIM = 0 ;
1115
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1116
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1117
        begin
1118
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1119
            test_fail("PCI bridge didn't process the read as expected");
1120
            disable main ;
1121
        end
1122
 
1123
        if (read_status`READ_DATA !== wmem_data[0])
1124
        begin
1125
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1126
            test_fail("PCI bridge returned unexpected Read Data");
1127
        end
1128
        else
1129
            test_ok ;
1130
    end
1131
    begin
1132
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1133
        if ( ok !== 1 )
1134
        begin
1135
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1136
        end
1137
        else
1138
            test_ok ;
1139
 
1140
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1141
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1142
        if ( ok !== 1 )
1143
        begin
1144
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1145
        end
1146
    end
1147
    join
1148
 
1149
    // if address translation is implemented - try it out
1150
    translation_address = image_base ;
1151
    `ifdef ADDR_TRAN_IMPL
1152
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1153
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1154
    if ( ok !== 1 )
1155
    begin
1156
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1157
        test_fail("write to WB Image Translation Address Register failed") ;
1158
        disable main ;
1159
    end
1160
 
1161
    target_address  = `BEH_TAR2_MEM_START ;
1162
    image_base      = 0 ;
1163
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1164
 
1165
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1166
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1167
 
1168
    write_flags                      = 0 ;
1169
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1170
 
1171
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1172
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1173
    if ( ok !== 1 )
1174
    begin
1175
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1176
        test_fail("write to WB Image Base Address Register failed") ;
1177
        disable main ;
1178
    end
1179
 
1180
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1181
    // enable address translation
1182
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1183
    if ( ok !== 1 )
1184
    begin
1185
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1186
        test_fail("write to WB Image Control Register failed") ;
1187
        disable main ;
1188
    end
1189
 
1190
    `endif
1191
 
1192
    fork
1193
    begin
1194
        write_data`WRITE_ADDRESS = target_address + 4 ;
1195
        write_data`WRITE_DATA    = wmem_data[1] ;
1196
        write_data`WRITE_SEL     = 4'hF ;
1197
 
1198
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1199
 
1200
        `ifdef ADDR_TRAN_IMPL
1201
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1202
        `else
1203
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1204
        `endif
1205
 
1206
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1207
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1208
        begin
1209
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1210
            test_fail("WB Slave state machine failed to post single memory write") ;
1211
            disable main ;
1212
        end
1213
 
1214
        // read written data back
1215
        read_data`READ_ADDRESS  = target_address + 4 ;
1216
        read_data`READ_SEL      = 4'hF ;
1217
        read_data`READ_TAG_STIM = 0 ;
1218
 
1219
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1220
 
1221
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1222
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1223
        begin
1224
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1225
            test_fail("PCI bridge failed to process single delayed memory read") ;
1226
            disable main ;
1227
        end
1228
 
1229
        if (read_status`READ_DATA !== wmem_data[1])
1230
        begin
1231
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1232
            test_fail("PCI bridge returned unexpected Read Data");
1233
        end
1234
        else
1235
            test_ok ;
1236
    end
1237
    begin
1238
        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 ) ;
1239
        if ( ok !== 1 )
1240
        begin
1241
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1242
        end
1243
        else
1244
            test_ok ;
1245
 
1246
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1247
        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 ) ;
1248
        if ( ok !== 1 )
1249
        begin
1250
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1251
        end
1252
    end
1253
    join
1254
 
1255
    // 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
1256
    // prepare write data
1257
    for ( i = 0 ; i < 6 ; i = i + 1 )
1258
    begin
1259
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1260
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1261
        write_data`WRITE_SEL     = 4'hF ;
1262
        wishbone_master.blk_write_data[i] = write_data ;
1263
    end
1264
 
1265
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1266
    write_flags`WB_TRANSFER_CAB    = 1 ;
1267
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1268
 
1269
    fork
1270
    begin
1271
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1272
        wishbone_master.wb_block_write(write_flags, write_status) ;
1273
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1274
        begin
1275
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1276
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1277
            disable main ;
1278
        end
1279
    end
1280
    begin
1281
        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 ) ;
1282
        if ( ok !== 1 )
1283
        begin
1284
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1285
        end
1286
        else
1287
            test_ok ;
1288
    end
1289
    join
1290
 
1291
    // set burst size and latency timer
1292
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1293
 
1294
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1295
    write_flags`WB_TRANSFER_CAB    = 1 ;
1296
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1297
 
1298
    // prepare read data
1299
    for ( i = 0 ; i < 4 ; i = i + 1 )
1300
    begin
1301
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1302
        read_data`READ_SEL     = 4'hF ;
1303
        wishbone_master.blk_read_data_in[i] = read_data ;
1304
    end
1305
 
1306
    fork
1307
    begin
1308
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1309
        wishbone_master.wb_block_read(write_flags, read_status) ;
1310
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1311
        begin
1312
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1313
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1314
            disable main ;
1315
        end
1316
 
1317
        // check data read from target
1318
        for ( i = 0 ; i < 4 ; i = i + 1 )
1319
        begin
1320
            read_status = wishbone_master.blk_read_data_out[i] ;
1321
            if (read_status`READ_DATA !== wmem_data[2 + i])
1322
            begin
1323
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1324
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1325
            end
1326
        end
1327
    end
1328
    begin
1329
        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 ) ;
1330
        if ( ok !== 1 )
1331
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1332
        else
1333
            test_ok ;
1334
 
1335
        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 ) ;
1336
        if ( ok !== 1 )
1337
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1338
        else
1339
            test_ok ;
1340
 
1341
        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 ) ;
1342
        if ( ok !== 1 )
1343
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1344
        else
1345
            test_ok ;
1346
 
1347
        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 ) ;
1348
        if ( ok !== 1 )
1349
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1350
        else
1351
            test_ok ;
1352
 
1353
    end
1354
    join
1355
 
1356
    // now repeat this same burst read with various image features enabled or disabled
1357
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1358
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1359
    if (ok !== 1)
1360
    begin
1361
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1362
        test_fail("write to WB Image control register failed") ;
1363
        disable main ;
1364
    end
1365
 
1366
    fork
1367
    begin
1368
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1369
        wishbone_master.wb_block_read(write_flags, read_status) ;
1370
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1371
        begin
1372
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1373
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1374
            disable main ;
1375
        end
1376
 
1377
        // check data read from target
1378
        for ( i = 0 ; i < 4 ; i = i + 1 )
1379
        begin
1380
            read_status = wishbone_master.blk_read_data_out[i] ;
1381
            if (read_status`READ_DATA !== wmem_data[2 + i])
1382
            begin
1383
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1384
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1385
            end
1386
            else
1387
                test_ok ;
1388
        end
1389
    end
1390
    begin
1391
        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 ) ;
1392
        if ( ok !== 1 )
1393
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1394
    end
1395
    join
1396
 
1397
    read_data`READ_ADDRESS  = target_address ;
1398
    read_data`READ_SEL      = 4'hF ;
1399
    read_data`READ_TAG_STIM = 0 ;
1400
 
1401
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1402
    fork
1403
    begin
1404
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1405
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1406
        begin
1407
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1408
            test_fail("delayed single memory read wasn't processed as expected") ;
1409
            disable main ;
1410
        end
1411
 
1412
        if (read_status`READ_DATA !== wmem_data[0])
1413
        begin
1414
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1415
            test_fail("delayed single memory read data value returned was not as expected") ;
1416
        end
1417
        else
1418
            test_ok ;
1419
    end
1420
    begin
1421
        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 ) ;
1422
        if ( ok !== 1 )
1423
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1424
    end
1425
    join
1426
 
1427
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1428
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1429
    if (ok !== 1)
1430
    begin
1431
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1432
        test_fail("write to WB Image control register failed") ;
1433
        disable main ;
1434
    end
1435
 
1436
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1437
    fork
1438
    begin
1439
        wishbone_master.wb_block_read(write_flags, read_status) ;
1440
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1441
        begin
1442
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1443
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1444
            disable main ;
1445
        end
1446
 
1447
        // check data read from target
1448
        for ( i = 0 ; i < 4 ; i = i + 1 )
1449
        begin
1450
            read_status = wishbone_master.blk_read_data_out[i] ;
1451
            if (read_status`READ_DATA !== wmem_data[2 + i])
1452
            begin
1453
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1454
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1455
            end
1456
            else
1457
                test_ok ;
1458
        end
1459
    end
1460
    begin
1461
        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 ) ;
1462
        if ( ok !== 1 )
1463
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1464
    end
1465
    join
1466
 
1467
    read_data`READ_ADDRESS  = target_address + 4 ;
1468
    read_data`READ_SEL      = 4'hF ;
1469
    read_data`READ_TAG_STIM = 0 ;
1470
 
1471
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1472
    fork
1473
    begin
1474
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1475
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1476
        begin
1477
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1478
            test_fail("delayed single memory read wasn't processed as expected") ;
1479
            disable main ;
1480
        end
1481
 
1482
        if (read_status`READ_DATA !== wmem_data[1])
1483
        begin
1484
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1485
            test_fail("delayed single memory read data value returned was not as expected") ;
1486
        end
1487
        else
1488
            test_ok ;
1489
    end
1490
    begin
1491
        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 ) ;
1492
        if ( ok !== 1 )
1493
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1494
    end
1495
    join
1496
 
1497
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1498
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1499
    if (ok !== 1)
1500
    begin
1501
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1502
        test_fail("write to WB Image control register failed") ;
1503
        disable main ;
1504
    end
1505
 
1506
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1507
    fork
1508
    begin
1509
        wishbone_master.wb_block_read(write_flags, read_status) ;
1510
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1511
        begin
1512
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1513
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1514
            disable main ;
1515
        end
1516
 
1517
        // check data read from target
1518
        for ( i = 0 ; i < 4 ; i = i + 1 )
1519
        begin
1520
            read_status = wishbone_master.blk_read_data_out[i] ;
1521
            if (read_status`READ_DATA !== wmem_data[2 + i])
1522
            begin
1523
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1524
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1525
            end
1526
            else
1527
                test_ok ;
1528
        end
1529
    end
1530
    begin
1531
        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 ) ;
1532
        if ( ok !== 1 )
1533
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1534
    end
1535
    join
1536
 
1537
    read_data`READ_ADDRESS  = target_address + 8 ;
1538
    read_data`READ_SEL      = 4'hF ;
1539
    read_data`READ_TAG_STIM = 0 ;
1540
 
1541
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1542
    fork
1543
    begin
1544
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1545
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1546
        begin
1547
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1548
            test_fail("delayed single memory read wasn't processed as expected") ;
1549
            disable main ;
1550
        end
1551
 
1552
        if (read_status`READ_DATA !== wmem_data[2])
1553
        begin
1554
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1555
            test_fail("delayed single memory read data value returned was not as expected") ;
1556
        end
1557
        else
1558
            test_ok ;
1559
    end
1560
    begin
1561
        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 ) ;
1562
        if ( ok !== 1 )
1563
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1564
    end
1565
    join
1566
 
1567
    // map image to IO space
1568
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1569
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1570
    if ( ok !== 1 )
1571
    begin
1572
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1573
        test_fail("write to WB Image Base Address register failed") ;
1574
        disable main ;
1575
    end
1576
 
1577
    write_data`WRITE_ADDRESS = target_address ;
1578
    write_data`WRITE_DATA    = wmem_data[11] ;
1579
    write_data`WRITE_SEL     = 4'hF ;
1580
 
1581
    // handle retries from now on
1582
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1583
 
1584
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1585
    fork
1586
    begin
1587
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1588
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1589
        begin
1590
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1591
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1592
            disable main ;
1593
        end
1594
    end
1595
    begin
1596
        // currently IO commands not supported in behavioral models - master abort
1597
        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 ) ;
1598
        if ( ok !== 1 )
1599
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1600
        else
1601
            test_ok ;
1602
    end
1603
    join
1604
 
1605
    read_data`READ_ADDRESS  = target_address ;
1606
    read_data`READ_SEL      = 4'hF ;
1607
    read_data`READ_TAG_STIM = 0 ;
1608
 
1609
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1610
 
1611
    // currently io commands are not supported by behavioral target - transfer should not be completed
1612
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1613
    fork
1614
    begin
1615
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1616
        if (read_status`CYC_ERR !== 1)
1617
        begin
1618
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1619
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1620
            disable main ;
1621
        end
1622
        else
1623
            test_ok ;
1624
    end
1625
    begin
1626
        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 ) ;
1627
        if ( ok !== 1 )
1628
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1629
    end
1630
    join
1631
 
1632
    // test byte addressing
1633
    read_data`READ_ADDRESS = target_address + 2 ;
1634
    read_data`READ_SEL     = 4'b1100 ;
1635
 
1636
    fork
1637
    begin
1638
        // currently io commands are not supported by behavioral target - transfer should not be completed
1639
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1640
        if (read_status`CYC_ERR !== 1)
1641
        begin
1642
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1643
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1644
            disable main ;
1645
        end
1646
        else test_ok ;
1647
    end
1648
    begin
1649
        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 ) ;
1650
        if ( ok !== 1 )
1651
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1652
    end
1653
    join
1654
 
1655
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1656
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1657
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1658
    if ( ok !== 1 )
1659
    begin
1660
        test_fail("WB Base address register could not be written") ;
1661
        disable main ;
1662
    end
1663
 
1664
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1665
    if ( ok !== 1 )
1666
    begin
1667
        test_fail("WB Address Mask register could not be written") ;
1668
        disable main ;
1669
    end
1670
 
1671
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1672
    if ( ok !== 1 )
1673
    begin
1674
        test_fail("WB Image Control register could not be written") ;
1675
        disable main ;
1676
    end
1677
 
1678
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1679
    write_data`WRITE_DATA    = wmem_data[11] ;
1680
    write_data`WRITE_SEL     = 4'b1000 ;
1681
 
1682
    // handle retries from now on
1683
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1684
 
1685
    fork
1686
    begin
1687
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1688
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1689
        begin
1690
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1691
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1692
            disable main ;
1693
        end
1694
    end
1695
    begin
1696
        // currently IO commands not supported in behavioral models - master abort
1697
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1698
        if ( ok !== 1 )
1699
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1700
        else
1701
            test_ok ;
1702
    end
1703
    join
1704
 
1705
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1706
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1707
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1708
 
1709
    fork
1710
    begin
1711
        // currently io commands are not supported by behavioral target - transfer should not be completed
1712
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1713
        if (read_status`CYC_ERR !== 1)
1714
        begin
1715
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1716
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1717
            disable main ;
1718
        end
1719
        else test_ok ;
1720
    end
1721
    begin
1722
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1723
        if ( ok !== 1 )
1724
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1725
    end
1726
    join
1727
 
1728
    test_name = "DISABLING WB IMAGE" ;
1729
 
1730
    // disable current image
1731
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1732
    if ( ok !== 1 )
1733
    begin
1734
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1735
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1736
        disable main ;
1737
    end
1738
 
1739
    // clear master abort status bit
1740
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1741
    if ( ok !== 1 )
1742
    begin
1743
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1744
        test_fail("write to PCI Device Status register not accepted as expected") ;
1745
        disable main ;
1746
    end
1747
 
1748
end //main
1749
endtask //test_wb_image
1750
 
1751
task wb_slave_errors ;
1752
    reg   [11:0] ctrl_offset ;
1753
    reg   [11:0] ba_offset ;
1754
    reg   [11:0] am_offset ;
1755
    reg   [11:0] ta_offset ;
1756
    reg `WRITE_STIM_TYPE write_data ;
1757
    reg `READ_STIM_TYPE  read_data ;
1758
    reg `READ_RETURN_TYPE read_status ;
1759
 
1760
    reg `WRITE_RETURN_TYPE write_status ;
1761
    reg `WB_TRANSFER_FLAGS write_flags ;
1762
    reg [31:0] temp_val1 ;
1763
    reg [31:0] temp_val2 ;
1764
    reg        ok   ;
1765
    reg [11:0] pci_ctrl_offset ;
1766
    reg [31:0] image_base ;
1767
    reg [31:0] target_address ;
1768
    integer    i ;
1769
    reg skip ;
1770
fork
1771
begin:main
1772
 
1773
    `ifdef GUEST
1774
        skip = 1 ;
1775
    `else
1776
        skip = 0 ;
1777
    `endif
1778
 
1779
    pci_ctrl_offset = 12'h4 ;
1780
 
1781
    // image 1 is used for error testing, since it is always implemented
1782
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1783
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1784
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1785
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1786
 
1787
    target_address  = `BEH_TAR1_MEM_START ;
1788
    image_base      = 0 ;
1789
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1790
 
1791
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1792
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1793
    write_flags                    = 0 ;
1794
    write_flags`INIT_WAITS         = tb_init_waits ;
1795
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1796
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1797
 
1798
    // enable master & target operation
1799
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1800
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1801
    if ( ok !== 1 )
1802
    begin
1803
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1804
        test_fail("PCI Device Control register couldn't be written") ;
1805
        disable no_transaction ;
1806
        disable main ;
1807
    end
1808
 
1809
    // prepare image control register
1810
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1811
    if ( ok !== 1 )
1812
    begin
1813
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1814
        test_fail("WB Image Control register couldn't be written") ;
1815
        disable no_transaction ;
1816
        disable main ;
1817
    end
1818
 
1819
    // prepare base address register
1820
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1821
    if ( ok !== 1 )
1822
    begin
1823
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1824
        test_fail("WB Base Address register couldn't be written") ;
1825
        disable no_transaction ;
1826
        disable main ;
1827
    end
1828
 
1829
    // write address mask register
1830
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1831
    if ( ok !== 1 )
1832
    begin
1833
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1834
        test_fail("WB Address Mask register couldn't be written") ;
1835
        disable no_transaction ;
1836
        disable main ;
1837
    end
1838
 
1839
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1840
 
1841
    skip = 0 ;
1842
 
1843
    // memory mapped image - access is erroneous when address is not alligned
1844
    write_data`WRITE_ADDRESS = target_address + 1 ;
1845
    write_data`WRITE_DATA    = wmem_data[0] ;
1846
    write_data`WRITE_SEL     = 4'hF ;
1847
 
1848
    // handle retries from now on
1849
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1850
 
1851
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1852
 
1853
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1854
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1855
    begin
1856
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1857
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1858
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1859
        disable no_transaction ;
1860
        disable main ;
1861
    end
1862
 
1863
    write_data`WRITE_ADDRESS = target_address + 2 ;
1864
 
1865
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1866
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1867
    begin
1868
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1869
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1870
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1871
        disable no_transaction ;
1872
        disable main ;
1873
 
1874
    end
1875
 
1876
    write_data`WRITE_ADDRESS = target_address + 3 ;
1877
 
1878
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1879
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1880
    begin
1881
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1882
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1883
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1884
        disable no_transaction ;
1885
        disable main ;
1886
    end
1887
 
1888
    test_ok ;
1889
 
1890
    // perform same tests for read accesses
1891
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1892
 
1893
    read_data`READ_ADDRESS  = target_address + 2 ;
1894
    read_data`READ_SEL      = 4'hF ;
1895
    read_data`READ_TAG_STIM = 0 ;
1896
 
1897
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1898
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_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 memory read as expected") ;
1903
        disable no_transaction ;
1904
        disable main ;
1905
    end
1906
 
1907
    test_ok ;
1908
 
1909
    // prepare write data
1910
    for ( i = 0 ; i < 6 ; i = i + 1 )
1911
    begin
1912
        write_data`WRITE_DATA    = wmem_data[i] ;
1913
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1914
        write_data`WRITE_SEL     = 4'hF ;
1915
        wishbone_master.blk_write_data[i] = write_data ;
1916
    end
1917
 
1918
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1919
    write_flags`WB_TRANSFER_CAB    = 1 ;
1920
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1921
 
1922
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1923
    wishbone_master.wb_block_write(write_flags, write_status) ;
1924
 
1925
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1926
    begin
1927
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1928
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1929
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1930
        disable no_transaction ;
1931
        disable main ;
1932
    end
1933
 
1934
    // prepare read data
1935
    for ( i = 0 ; i < 6 ; i = i + 1 )
1936
    begin
1937
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1938
        read_data`READ_SEL     = 4'hF ;
1939
        wishbone_master.blk_read_data_in[i] = read_data ;
1940
    end
1941
 
1942
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1943
    wishbone_master.wb_block_read(write_flags, read_status) ;
1944
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1945
    begin
1946
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1947
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1948
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
1949
        disable no_transaction ;
1950
        disable main ;
1951
    end
1952
 
1953
    test_ok ;
1954
 
1955
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1956
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
1957
 
1958
    // map image to IO space
1959
    `ifdef GUEST
1960
        skip = 1 ;
1961
    `endif
1962
 
1963
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
1964
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1965
    if ( ok !== 1 )
1966
    begin
1967
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1968
        test_fail("WB Image Base Address register couldn't be written") ;
1969
        disable no_transaction ;
1970
        disable main ;
1971
    end
1972
 
1973
    skip = 0 ;
1974
 
1975
    write_data`WRITE_ADDRESS = target_address ;
1976
    write_data`WRITE_DATA    = wmem_data[0] ;
1977
    write_data`WRITE_SEL     = 4'b1010 ;
1978
 
1979
    // don't handle retries
1980
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1981
 
1982
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
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 + 1 ;
1996
    write_data`WRITE_SEL     = 4'b0011 ;
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'b1100 ;
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 + 2 ;
2023
    write_data`WRITE_SEL     = 4'b0101 ;
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'b1000 ;
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
    write_data`WRITE_ADDRESS = target_address + 3 ;
2050
    write_data`WRITE_SEL     = 4'b1010 ;
2051
 
2052
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2053
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2054
    begin
2055
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2056
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2057
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2058
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2059
        disable no_transaction ;
2060
        disable main ;
2061
    end
2062
 
2063
    write_data`WRITE_SEL     = 4'b0110 ;
2064
 
2065
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2066
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2067
    begin
2068
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2069
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2070
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2071
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2072
        disable no_transaction ;
2073
        disable main ;
2074
    end
2075
 
2076
    test_ok ;
2077
 
2078
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2079
 
2080
    read_data`READ_ADDRESS  = target_address + 3 ;
2081
    read_data`READ_SEL      = 4'hF ;
2082
    read_data`READ_TAG_STIM = 0 ;
2083
 
2084
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2085
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2086
    begin
2087
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2088
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
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 erroneous I/O read as expected") ;
2091
        disable no_transaction ;
2092
        disable main ;
2093
    end
2094
 
2095
    test_ok ;
2096
 
2097
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2098
    // prepare write data
2099
    for ( i = 0 ; i < 6 ; i = i + 1 )
2100
    begin
2101
        write_data`WRITE_DATA    = wmem_data[i] ;
2102
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2103
        write_data`WRITE_SEL     = 4'hF ;
2104
        wishbone_master.blk_write_data[i] = write_data ;
2105
    end
2106
 
2107
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2108
    write_flags`WB_TRANSFER_CAB    = 1 ;
2109
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2110
 
2111
    wishbone_master.wb_block_write(write_flags, write_status) ;
2112
 
2113
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2114
    begin
2115
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2116
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2117
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2118
        disable no_transaction ;
2119
        disable main ;
2120
    end
2121
 
2122
    test_ok ;
2123
 
2124
    test_name = "CAB I/O READ TO WB SLAVE" ;
2125
    // prepare read data
2126
    for ( i = 0 ; i < 6 ; i = i + 1 )
2127
    begin
2128
        read_data`READ_ADDRESS = target_address + 4*i ;
2129
        read_data`READ_SEL     = 4'hF ;
2130
        wishbone_master.blk_read_data_in[i] = read_data ;
2131
    end
2132
 
2133
    wishbone_master.wb_block_read(write_flags, read_status) ;
2134
 
2135
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2136
    begin
2137
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2138
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2139
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2140
        disable no_transaction ;
2141
        disable main ;
2142
    end
2143
 
2144
    test_ok ;
2145
 
2146
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2147
 
2148
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2149
 
2150
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2151
    write_data`WRITE_ADDRESS = target_address + 1 ;
2152
    write_data`WRITE_DATA    = wmem_data[0] ;
2153
    write_data`WRITE_SEL     = 4'hF ;
2154
 
2155
    // don't handle retries
2156
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2157
 
2158
    `ifdef HOST
2159
        `define DO_W_CONF_TEST
2160
        `define DO_R_CONF_TEST
2161
    `else
2162
        `ifdef WB_CNF_IMAGE
2163
             `define DO_R_CONF_TEST
2164
        `endif
2165
    `endif
2166
 
2167
    `ifdef DO_W_CONF_TEST
2168
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2169
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2170
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2171
    begin
2172
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2173
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2174
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2175
        disable no_transaction ;
2176
        disable main ;
2177
    end
2178
 
2179
    write_data`WRITE_ADDRESS = target_address + 2 ;
2180
 
2181
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2182
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2183
    begin
2184
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2185
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2186
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2187
        disable no_transaction ;
2188
        disable main ;
2189
    end
2190
 
2191
    write_data`WRITE_ADDRESS = target_address + 3 ;
2192
 
2193
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2194
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2195
    begin
2196
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2197
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2198
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2199
        disable no_transaction ;
2200
        disable main ;
2201
    end
2202
 
2203
    test_ok ;
2204
    `endif
2205
 
2206
    `ifdef DO_R_CONF_TEST
2207
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2208
    read_data`READ_ADDRESS  = target_address + 3 ;
2209
    read_data`READ_SEL      = 4'hF ;
2210
    read_data`READ_TAG_STIM = 0 ;
2211
 
2212
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2213
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2214
    begin
2215
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2216
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2217
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2218
        disable no_transaction ;
2219
        disable main ;
2220
    end
2221
 
2222
    test_ok ;
2223
    `endif
2224
 
2225
    `ifdef DO_W_CONF_TEST
2226
    // prepare write data
2227
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2228
    for ( i = 0 ; i < 6 ; i = i + 1 )
2229
    begin
2230
        write_data`WRITE_DATA    = wmem_data[i] ;
2231
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2232
        write_data`WRITE_SEL     = 4'hF ;
2233
        wishbone_master.blk_write_data[i] = write_data ;
2234
    end
2235
 
2236
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2237
    write_flags`WB_TRANSFER_CAB    = 1 ;
2238
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2239
 
2240
    wishbone_master.wb_block_write(write_flags, write_status) ;
2241
 
2242
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2243
    begin
2244
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2245
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2246
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2247
        disable no_transaction ;
2248
        disable main ;
2249
    end
2250
    test_ok ;
2251
    `endif
2252
 
2253
    `ifdef DO_R_CONF_TEST
2254
    // prepare read data
2255
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2256
    for ( i = 0 ; i < 6 ; i = i + 1 )
2257
    begin
2258
        read_data`READ_ADDRESS = target_address + 4*i ;
2259
        read_data`READ_SEL     = 4'hF ;
2260
        wishbone_master.blk_read_data_in[i] = read_data ;
2261
    end
2262
 
2263
    wishbone_master.wb_block_read(write_flags, read_status) ;
2264
 
2265
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2266
    begin
2267
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2268
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2269
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2270
        disable no_transaction ;
2271
        disable main ;
2272
    end
2273
    test_ok ;
2274
    `endif
2275
 
2276
    `ifdef GUEST
2277
        skip = 1 ;
2278
    `endif
2279
 
2280
    // disable image
2281
    test_name = "DISABLE IMAGE" ;
2282
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2283
    if ( ok !== 1 )
2284
    begin
2285
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2286
        test_fail("WB Address Mask register couldn't be written") ;
2287
        disable no_transaction ;
2288
        disable main ;
2289
    end
2290
 
2291
    skip = 0 ;
2292
 
2293
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2294
 
2295
    disable no_transaction ;
2296
end
2297
begin:no_transaction
2298
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2299
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2300
    forever
2301
    begin
2302
        @(posedge pci_clock) ;
2303
        if ( skip !== 1 )
2304
        begin
2305
            if ( FRAME !== 1 )
2306
            begin
2307
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2308
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2309
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2310
            end
2311
        end
2312
    end
2313
end
2314
join
2315
endtask //wb_slave_errors
2316
 
2317
task wb_to_pci_error_handling ;
2318
    reg   [11:0] ctrl_offset ;
2319
    reg   [11:0] ba_offset ;
2320
    reg   [11:0] am_offset ;
2321
    reg   [11:0] ta_offset ;
2322
    reg   [11:0] err_cs_offset ;
2323
    reg `WRITE_STIM_TYPE write_data ;
2324
    reg `READ_STIM_TYPE  read_data ;
2325
    reg `READ_RETURN_TYPE read_status ;
2326
 
2327
    reg `WRITE_RETURN_TYPE write_status ;
2328
    reg `WB_TRANSFER_FLAGS write_flags ;
2329
    reg [31:0] temp_val1 ;
2330
    reg [31:0] temp_val2 ;
2331
    reg        ok   ;
2332
    reg [11:0] pci_ctrl_offset ;
2333
    reg [31:0] image_base ;
2334
    reg [31:0] target_address ;
2335
    integer    num_of_trans ;
2336
    integer    current ;
2337
    integer    i ;
2338
begin:main
2339
 
2340
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2341
 
2342
    pci_ctrl_offset = 12'h4 ;
2343
 
2344
    // disable error interrupts and disable error reporting
2345
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2346
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2347
    if ( ok !== 1 )
2348
    begin
2349
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2350
        test_fail("PCI Device Control register couldn't be written") ;
2351
        disable main ;
2352
    end
2353
 
2354
    // image 1 is used for error testing, since it is always implemented
2355
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2356
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2357
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2358
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2359
 
2360
    // set master abort testing address to address that goes out of target's range
2361
    target_address  = `BEH_TAR1_MEM_START ;
2362
    image_base      = 0 ;
2363
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2364
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2365
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2366
 
2367
    write_flags                    = 0 ;
2368
    write_flags`INIT_WAITS         = tb_init_waits ;
2369
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2370
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2371
 
2372
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2373
 
2374
    // enable master & target operation
2375
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2376
    if ( ok !== 1 )
2377
    begin
2378
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2379
        test_fail("PCI Device Control register couldn't be written") ;
2380
        disable main ;
2381
    end
2382
 
2383
    // prepare image control register
2384
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2385
    if ( ok !== 1 )
2386
    begin
2387
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2388
        test_fail("WB Image Control register couldn't be written") ;
2389
        disable main ;
2390
    end
2391
 
2392
    // prepare base address register
2393
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2394
    if ( ok !== 1 )
2395
    begin
2396
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2397
        test_fail("WB Image Base Address register couldn't be written") ;
2398
        disable main ;
2399
    end
2400
 
2401
    // write address mask register
2402
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2403
    if ( ok !== 1 )
2404
    begin
2405
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2406
        test_fail("WB Image Address Mask register couldn't be written") ;
2407
        disable main ;
2408
    end
2409
 
2410
    // disable error reporting
2411
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2412
    if ( ~ok )
2413
    begin
2414
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2415
        test_fail("WB Error Control and Status register couldn't be written") ;
2416
        disable main ;
2417
    end
2418
 
2419
    // perform two writes - one to error address and one to OK address
2420
    // prepare write buffer
2421
 
2422
    write_data`WRITE_ADDRESS = target_address ;
2423
    write_data`WRITE_DATA    = wmem_data[100] ;
2424
    write_data`WRITE_SEL     = 4'hF ;
2425
 
2426
    wishbone_master.blk_write_data[0] = write_data ;
2427
 
2428
    write_flags`WB_TRANSFER_SIZE = 2 ;
2429
 
2430
    // don't handle retries
2431
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2432
    write_flags`WB_TRANSFER_CAB    = 0 ;
2433
 
2434
    $display("Introducing master abort error on single WB to PCI write!") ;
2435
 
2436
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2437
    // first disable target 1
2438
 
2439 45 mihad
    configuration_cycle_write(0,                        // bus number
2440
                              `TAR1_IDSEL_INDEX - 11,   // device number
2441
                              0,                        // function number
2442
                              1,                        // register number
2443
                              0,                        // type of configuration cycle
2444
                              4'b0001,                  // byte enables
2445
                              32'h0000_0000             // data
2446 15 mihad
                             ) ;
2447
 
2448
    fork
2449
    begin
2450
        // start no response monitor in parallel with writes
2451
        musnt_respond(ok) ;
2452
        if ( ok !== 1 )
2453
        begin
2454
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2455
            $display("Testbench is configured wrong!") ;
2456
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2457
        end
2458
        else
2459
            test_ok ;
2460
    end
2461
    begin
2462
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2463
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2464
       begin
2465
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2466
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2467
           test_fail("WB Slave state machine failed to post single memory write");
2468
           disable main ;
2469
       end
2470
    end
2471
    join
2472
 
2473
    /*// read data from second write
2474
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2475
    read_data`READ_ADDRESS = target_address ;
2476
    read_data`READ_SEL     = 4'hF ;
2477
    read_data`READ_TAG_STIM = 0 ;
2478
 
2479
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2480
 
2481
    if ( read_status`READ_DATA !== wmem_data[101] )
2482
    begin
2483
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2484
    end
2485
    */
2486
 
2487
    // read error status register - no errors should be reported since reporting was disabled
2488
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2489
 
2490
    @(posedge pci_clock) ;
2491
    // wait for two WB clocks for synchronization to be finished
2492
    repeat (2)
2493
        @(posedge wb_clock) ;
2494
 
2495
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2496
    if ( temp_val1[8] !== 0 )
2497
    begin
2498
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2499
        $display("Error reporting was disabled, but error was reported anyway!") ;
2500
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2501
        disable main ;
2502
    end
2503
    test_ok ;
2504
 
2505
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2506
    // check for interrupts - there should be no interrupt requests active
2507
    `ifdef HOST
2508
        repeat(4)
2509
            @(posedge wb_clock) ;
2510
 
2511
        if ( INT_O !== 0 )
2512
        begin
2513
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2514
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2515
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2516
        end
2517
        else
2518
            test_ok ;
2519
    `else
2520
    `ifdef GUEST
2521
        repeat( 4 )
2522
            @(posedge pci_clock) ;
2523
 
2524
        if ( INTA !== 1 )
2525
        begin
2526
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2527
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2528
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2529
        end
2530
        else
2531
            test_ok ;
2532
    `endif
2533
    `endif
2534
 
2535
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2536
    // check PCI status register
2537
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2538
    if ( temp_val1[29] !== 1 )
2539
    begin
2540
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2541
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2542
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2543
    end
2544
    else
2545
        test_ok ;
2546
 
2547
    // clear
2548
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2549
 
2550
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2551
 
2552
    $display("Introducing master abort error to CAB write!") ;
2553
    // now enable error reporting mechanism
2554
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2555
    // enable error interrupts
2556
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2557
 
2558
    // configure flags for CAB transfer
2559
    write_flags`WB_TRANSFER_CAB = 1 ;
2560
    write_flags`WB_TRANSFER_SIZE = 3 ;
2561
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2562
 
2563
    // prepare data for erroneous write
2564
    for ( i = 0 ; i < 3 ; i = i + 1 )
2565
    begin
2566
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2567
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2568
        write_data`WRITE_SEL     = 4'hF ;
2569
        wishbone_master.blk_write_data[i] = write_data ;
2570
    end
2571
 
2572
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2573
    fork
2574
    begin
2575
        wishbone_master.wb_block_write(write_flags, write_status) ;
2576
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2577
        begin
2578
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2579
            $display("Complete burst write through WB slave didn't succeed!") ;
2580
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2581
            disable main ;
2582
        end
2583
    end
2584
    begin
2585
        musnt_respond(ok) ;
2586
        if ( ok !== 1 )
2587
        begin
2588
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2589
            $display("Testbench is configured wrong!") ;
2590
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2591
        end
2592
        else
2593
            test_ok ;
2594
    end
2595
    join
2596
 
2597
    // check error status address, data, byte enables and bus command
2598
    // error status bit is signalled on PCI clock and synchronized to WB clock
2599
    // wait one PCI clock cycle
2600
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2601
    ok = 1 ;
2602
    @(posedge pci_clock) ;
2603
 
2604
    // wait for two WB clocks for synchronization to be finished
2605
    repeat (2)
2606
        @(posedge wb_clock) ;
2607
 
2608
    // read registers
2609
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2610
    if ( temp_val1[8] !== 1 )
2611
    begin
2612
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2613
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2614
        ok = 0 ;
2615
    end
2616
 
2617
    if ( temp_val1[9] !== 1 )
2618
    begin
2619
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2620
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2621
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2622
        ok = 0 ;
2623
    end
2624
 
2625
    if ( temp_val1[31:28] !== 0 )
2626
    begin
2627
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2628
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2629
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2630
        ok = 0 ;
2631
    end
2632
 
2633
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2634
    begin
2635
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2636
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2637
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2638
        ok = 0 ;
2639
    end
2640
 
2641
    // read error address register
2642
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2643
    if ( temp_val1 !== target_address )
2644
    begin
2645
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2646
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2647
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2648
        ok = 0 ;
2649
    end
2650
 
2651
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2652
    if ( temp_val1 !== wmem_data[110] )
2653
    begin
2654
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2655
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2656
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2657
        ok = 0 ;
2658
    end
2659
 
2660
    // check PCI status register
2661
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2662
    if ( temp_val1[29] !== 1 )
2663
    begin
2664
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2665
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2666
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2667
        ok = 0 ;
2668
    end
2669
 
2670
    if ( temp_val1[28] !== 0 )
2671
    begin
2672
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2673
        $display("Received Target Abort bit was set for no reason!") ;
2674
        test_fail("Received Target Abort bit was set for no reason") ;
2675
        ok = 0 ;
2676
    end
2677
 
2678
    if ( ok )
2679
        test_ok ;
2680
 
2681
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2682
 
2683
    // clear error status bit
2684
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2685
 
2686
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2687
 
2688
    ok = 1 ;
2689
 
2690
    `ifdef HOST
2691
        repeat(4)
2692
        @(posedge wb_clock) ;
2693
        if ( INT_O !== 1 )
2694
        begin
2695
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2696
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2697
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2698
            ok = 0 ;
2699
        end
2700
    `else
2701
    `ifdef GUEST
2702
        repeat(4)
2703
        @(posedge pci_clock) ;
2704
        if ( INTA !== 0 )
2705
        begin
2706
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2707
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2708
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2709
            ok = 0 ;
2710
        end
2711
    `endif
2712
    `endif
2713
 
2714
    // read interrupt status register
2715
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2716
    if ( temp_val1 !== 32'h0000_0002 )
2717
    begin
2718
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2719
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2720
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2721
        test_fail("Interrupt Status register returned wrong value") ;
2722
        ok = 0 ;
2723
    end
2724
 
2725
    if ( ok )
2726
        test_ok ;
2727
    // clear interrupt status bits
2728
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2729
 
2730
    ok = 1 ;
2731
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2732
    // wait for two clock cycles before checking interrupt request deassertion
2733
    `ifdef HOST
2734
        repeat (4)
2735
            @(posedge wb_clock) ;
2736
 
2737
        if ( INT_O !== 0 )
2738
        begin
2739
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2740
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2741
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2742
            ok = 0 ;
2743
        end
2744
    `else
2745
    `ifdef GUEST
2746
        repeat (4)
2747
            @(posedge pci_clock) ;
2748
 
2749
        if ( INTA !== 1 )
2750
        begin
2751
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2752
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2753
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2754
            ok = 0 ;
2755
        end
2756
    `endif
2757
    `endif
2758
 
2759
    if ( ok )
2760
        test_ok ;
2761
 
2762
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2763
    ok = 1 ;
2764
    // enable target
2765 45 mihad
    configuration_cycle_write(0,                        // bus number
2766
                              `TAR1_IDSEL_INDEX - 11,   // device number
2767
                              0,                        // function number
2768
                              1,                        // register number
2769
                              0,                        // type of configuration cycle
2770
                              4'b0001,                  // byte enables
2771
                              32'h0000_0007             // data
2772 15 mihad
                             ) ;
2773
    // prepare data for ok write
2774
    for ( i = 0 ; i < 3 ; i = i + 1 )
2775
    begin
2776
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2777
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2778
        write_data`WRITE_SEL     = 4'hF ;
2779
        wishbone_master.blk_write_data[i] = write_data ;
2780
    end
2781
 
2782
    wishbone_master.wb_block_write(write_flags, write_status) ;
2783
 
2784
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2785
    begin
2786
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2787
        $display("Complete burst write through WB slave didn't succeed!") ;
2788
        test_fail("WB Slave state machine failed to post CAB write") ;
2789
        disable main ;
2790
    end
2791
 
2792
    // do a read
2793
    for ( i = 0 ; i < 3 ; i = i + 1 )
2794
    begin
2795
        read_data`READ_ADDRESS = target_address + 4*i ;
2796
        read_data`READ_SEL     = 4'hF ;
2797
        wishbone_master.blk_read_data_in[i] = read_data ;
2798
    end
2799
 
2800
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2801
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2802
    write_flags`WB_TRANSFER_CAB    = 1 ;
2803
 
2804
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2805
 
2806
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2807
    begin
2808
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2809
        $display("Complete burst read through WB slave didn't succeed!") ;
2810
        test_fail("Delayed CAB write was not processed as expected") ;
2811
        disable main ;
2812
    end
2813
 
2814
    for ( i = 0 ; i < 3 ; i = i + 1 )
2815
    begin
2816
        read_status = wishbone_master.blk_read_data_out[i] ;
2817
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2818
        begin
2819
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2820
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2821
        end
2822
    end
2823
 
2824
    $display("Introducing master abort error to single read!") ;
2825
    // disable target
2826 45 mihad
    configuration_cycle_write(0,                        // bus number
2827
                              `TAR1_IDSEL_INDEX - 11,   // device number
2828
                              0,                        // function number
2829
                              1,                        // register number
2830
                              0,                        // type of configuration cycle
2831
                              4'b0001,                  // byte enables
2832
                              32'h0000_0000             // data
2833 15 mihad
                             ) ;
2834
    // set read data
2835
    read_data`READ_ADDRESS = target_address ;
2836
    read_data`READ_SEL     = 4'hF ;
2837
 
2838
    // enable automatic retry handling
2839
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2840
    write_flags`WB_TRANSFER_CAB    = 0 ;
2841
 
2842
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2843
    fork
2844
    begin
2845
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2846
    end
2847
    begin
2848
        musnt_respond(ok) ;
2849
        if ( ok !== 1 )
2850
        begin
2851
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2852
            $display("Testbench is configured wrong!") ;
2853
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2854
        end
2855
    end
2856
    join
2857
 
2858
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2859
    begin
2860
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2861
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2862
        $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) ;
2863
        test_fail("read didn't finish on WB bus as expected") ;
2864
        disable main ;
2865
    end
2866
 
2867
    test_ok ;
2868
 
2869
 
2870
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2871
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2872
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2873
    if ( temp_val1[8] !== 0 )
2874
    begin
2875
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2876
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2877
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2878
    end
2879
    else
2880
        test_ok ;
2881
 
2882
    // now check normal read operation
2883 45 mihad
    configuration_cycle_write(0,                        // bus number
2884
                              `TAR1_IDSEL_INDEX - 11,   // device number
2885
                              0,                        // function number
2886
                              1,                        // register number
2887
                              0,                        // type of configuration cycle
2888
                              4'b0001,                  // byte enables
2889
                              32'h0000_0007             // data
2890 15 mihad
                             ) ;
2891
 
2892 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
2893 15 mihad
    read_data`READ_ADDRESS = target_address ;
2894
    read_data`READ_SEL     = 4'hF ;
2895
 
2896
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2897
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2898
    begin
2899
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2900
        $display("WB slave failed to process single read!") ;
2901
        $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) ;
2902
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2903
        disable main ;
2904
    end
2905
 
2906
    if ( read_status`READ_DATA !== wmem_data[113] )
2907
    begin
2908
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2909
        test_fail("when read finished on WB bus, wrong data was provided") ;
2910
    end
2911
    else
2912
        test_ok ;
2913
 
2914
    // check PCI status register
2915 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
2916 15 mihad
    ok = 1 ;
2917
 
2918
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2919
    if ( temp_val1[29] !== 1 )
2920
    begin
2921
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2922
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2923
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2924
        ok = 0 ;
2925
    end
2926
 
2927
    if ( temp_val1[28] !== 0 )
2928
    begin
2929
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2930
        $display("Received Target Abort bit was set for no reason!") ;
2931
        test_fail("Received Target Abort bit was set for no reason") ;
2932
        ok = 0 ;
2933
    end
2934
    if ( ok )
2935
        test_ok ;
2936
 
2937
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2938
 
2939
    $display("Introducing master abort error to CAB read!") ;
2940
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2941
 
2942 45 mihad
    configuration_cycle_write(0,                        // bus number
2943
                              `TAR1_IDSEL_INDEX - 11,   // device number
2944
                              0,                        // function number
2945
                              1,                        // register number
2946
                              0,                        // type of configuration cycle
2947
                              4'b0001,                  // byte enables
2948
                              32'h0000_0000             // data
2949 15 mihad
                             ) ;
2950
 
2951
    for ( i = 0 ; i < 3 ; i = i + 1 )
2952
    begin
2953
        read_data`READ_ADDRESS = target_address + 4*i ;
2954
        read_data`READ_SEL     = 4'hF ;
2955
        wishbone_master.blk_read_data_in[i] = read_data ;
2956
    end
2957
 
2958
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2959
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2960
    write_flags`WB_TRANSFER_CAB    = 1 ;
2961
 
2962
    fork
2963
    begin
2964
        wishbone_master.wb_block_read( write_flags, read_status ) ;
2965
    end
2966
    begin
2967
        musnt_respond(ok) ;
2968
        if ( ok !== 1 )
2969
        begin
2970
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2971
            $display("Testbench is configured wrong!") ;
2972
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2973
        end
2974
    end
2975
    join
2976
 
2977
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2978
    begin
2979
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2980
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2981
        $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) ;
2982
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
2983
        disable main ;
2984
    end
2985
    else
2986
        test_ok ;
2987
 
2988
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
2989
    ok = 1 ;
2990
    // check PCI status register
2991
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2992
    if ( temp_val1[29] !== 1 )
2993
    begin
2994
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2995
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2996
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2997
        ok = 0 ;
2998
    end
2999
 
3000
    if ( temp_val1[28] !== 0 )
3001
    begin
3002
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3003
        $display("Received Target Abort bit was set for no reason!") ;
3004
        test_fail("Received Target Abort bit was set for no reason") ;
3005
        ok = 0 ;
3006
    end
3007
 
3008
    if ( ok )
3009
        test_ok ;
3010
 
3011
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3012
 
3013
    $display("Introducing target abort termination to single write!") ;
3014
 
3015
    // disable error reporting and interrupts
3016
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3017
 
3018 45 mihad
    configuration_cycle_write(0,                        // bus number
3019
                              `TAR1_IDSEL_INDEX - 11,   // device number
3020
                              0,                        // function number
3021
                              1,                        // register number
3022
                              0,                        // type of configuration cycle
3023
                              4'b0001,                  // byte enables
3024
                              32'h0000_0007             // data
3025 15 mihad
                             ) ;
3026
 
3027
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3028
    if ( ok !== 1 )
3029
    begin
3030
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3031
        test_fail("WB Error Control and Status register couldn't be written to") ;
3032
        disable main ;
3033
    end
3034
 
3035
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3036
    if ( ok !== 1 )
3037
    begin
3038
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3039
        test_fail("Interrupt Control register couldn't be written to") ;
3040
        disable main ;
3041
    end
3042
 
3043
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3044
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3045
 
3046
    write_data`WRITE_ADDRESS = target_address ;
3047
    write_data`WRITE_DATA    = wmem_data[0] ;
3048
    write_data`WRITE_SEL     = 4'hF ;
3049
 
3050
    wishbone_master.blk_write_data[0] = write_data ;
3051
 
3052
    write_data`WRITE_ADDRESS = target_address + 4;
3053
    write_data`WRITE_DATA    = wmem_data[1] ;
3054
    write_data`WRITE_SEL     = 4'hF ;
3055
 
3056
    wishbone_master.blk_write_data[1] = write_data ;
3057
 
3058
    write_flags`WB_TRANSFER_SIZE = 2 ;
3059
 
3060
    // don't handle retries
3061
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3062
    write_flags`WB_TRANSFER_CAB    = 0 ;
3063
 
3064
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3065
    fork
3066
    begin
3067
        wishbone_master.wb_block_write(write_flags, write_status) ;
3068
 
3069
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3070
        begin
3071
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3072
            $display("Image writes were not accepted as expected!") ;
3073
            $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) ;
3074
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3075
            disable main ;
3076
        end
3077
 
3078
        // read data back to see, if it was written OK
3079
        read_data`READ_ADDRESS         = target_address + 4;
3080
        read_data`READ_SEL             = 4'hF ;
3081
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3082
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3083
    end
3084
    begin
3085
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3086
        if ( ok !== 1 )
3087
        begin
3088
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3089
        end
3090
        else
3091
            test_ok ;
3092
 
3093
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3094
 
3095
        // when first transaction finishes - enable normal target response!
3096
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3097
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3098
 
3099
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3100
        if ( ok !== 1 )
3101
        begin
3102
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3103
        end
3104
        else
3105
            test_ok ;
3106
 
3107
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3108
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3109
        if ( ok !== 1 )
3110
        begin
3111
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3112
        end
3113
    end
3114
    join
3115
 
3116
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3117
    begin
3118
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3119
        $display("Bridge failed to process single read after target abort terminated write!") ;
3120
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3121
        disable main ;
3122
    end
3123
 
3124
    if ( read_status`READ_DATA !== wmem_data[1] )
3125
    begin
3126
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3127
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3128
    end
3129
    else
3130
        test_ok ;
3131
 
3132
    // check interrupt and error statuses!
3133
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3134
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3135
    if ( temp_val1[8] !== 0 )
3136
    begin
3137
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3138
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3139
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3140
    end
3141
    else
3142
        test_ok ;
3143
 
3144
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3145
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3146
    if ( temp_val1[1] !== 0 )
3147
    begin
3148
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3149
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3150
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3151
    end
3152
    else
3153
        test_ok ;
3154
 
3155
    // check PCI status register
3156
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3157
    ok = 1 ;
3158
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3159
    if ( temp_val1[29] !== 0 )
3160
    begin
3161
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3162
        $display("Received Master Abort bit was set with no reason!") ;
3163
        test_fail("Received Master Abort bit was set with no reason") ;
3164
        ok = 0 ;
3165
    end
3166
 
3167
    if ( temp_val1[28] !== 1 )
3168
    begin
3169
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3170
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3171
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3172
        ok = 0 ;
3173
    end
3174
 
3175
    if ( ok )
3176
        test_ok ;
3177
 
3178
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3179
 
3180
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3181
 
3182
    $display("Introducing target abort termination to CAB write!") ;
3183
    // enable error reporting mechanism
3184
 
3185
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3186
    if ( ok !== 1 )
3187
    begin
3188
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3189
        test_fail("WB Error Control and Status register could not be written to") ;
3190
        disable main ;
3191
    end
3192
 
3193
    for ( i = 0 ; i < 3 ; i = i + 1 )
3194
    begin
3195
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3196
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3197
        write_data`WRITE_SEL     = 4'b1010 ;
3198
        wishbone_master.blk_write_data[i] = write_data ;
3199
    end
3200
 
3201
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3202
    write_flags`WB_TRANSFER_CAB    = 1 ;
3203
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3204
 
3205
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3206
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3207
 
3208
    fork
3209
    begin
3210
        wishbone_master.wb_block_write(write_flags, write_status) ;
3211
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3212
        begin
3213
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3214
            $display("Bridge failed to process complete CAB write!") ;
3215
            test_fail("bridge failed to post CAB Memory Write") ;
3216
            disable main ;
3217
        end
3218
    end
3219
    begin
3220
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3221
        if ( ok !== 1 )
3222
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3223
        else
3224
            test_ok ;
3225
    end
3226
    join
3227
 
3228
    // check statuses and data from error
3229
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3230
    ok = 1 ;
3231
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3232
    if ( temp_val1[8] !== 1 )
3233
    begin
3234
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3235
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3236
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3237
        ok = 0 ;
3238
    end
3239
 
3240
    if ( temp_val1[9] !== 0 )
3241
    begin
3242
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3243
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3244
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3245
        ok = 0 ;
3246
    end
3247
 
3248
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3249
    begin
3250
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3251
        $display("Value in W_ERR_CS register was wrong!") ;
3252
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3253
        test_fail("BE Field didn't provided expected value") ;
3254
        ok = 0 ;
3255
    end
3256
 
3257
    if ( ok )
3258
        test_ok ;
3259
 
3260
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3261
    ok = 1 ;
3262
    // check erroneous address and data
3263
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3264
    if ( temp_val1 !== (target_address + 8) )
3265
    begin
3266
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3267
        $display("Value in W_ERR_ADDR register was wrong!") ;
3268
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3269
        test_fail("Value in WB Erroneous Address register was wrong") ;
3270
        ok = 0 ;
3271
    end
3272
 
3273
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3274
    if ( temp_val1 !== wmem_data[120] )
3275
    begin
3276
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3277
        $display("Value in W_ERR_DATA register was wrong!") ;
3278
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3279
        test_fail("Value in WB Erroneous Data register was wrong") ;
3280
        ok = 0 ;
3281
    end
3282
 
3283
    if ( ok )
3284
        test_ok ;
3285
 
3286
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3287
    ok = 1 ;
3288
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3289
    if ( temp_val1[29] !== 0 )
3290
    begin
3291
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3292
        $display("Received Master Abort bit was set with no reason!") ;
3293
        test_fail("Received Master Abort bit was set for no reason") ;
3294
        ok = 0 ;
3295
    end
3296
 
3297
    if ( temp_val1[28] !== 1 )
3298
    begin
3299
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3300
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3301
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3302
        ok = 0 ;
3303
    end
3304
 
3305
    if ( ok )
3306
        test_ok ;
3307
 
3308
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3309
 
3310
    // clear error status bit and enable error interrupts
3311
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3312
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3313
 
3314
    // check if error bit was cleared
3315
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3316
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3317
    if ( temp_val1[8] !== 0 )
3318
    begin
3319
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3320
        $display("Error bit was not cleared even though one was written to its location!") ;
3321
        test_fail("Error bit was not cleared even though one was written to its location") ;
3322
    end
3323
 
3324
    // repeat same write with different target configuration
3325
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3326
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3327
 
3328
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3329
    fork
3330
    begin
3331
        write_flags`WB_TRANSFER_SIZE = 2 ;
3332
        wishbone_master.wb_block_write(write_flags, write_status) ;
3333
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3334
        begin
3335
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3336
            $display("Bridge failed to process complete CAB write!") ;
3337
            test_fail("bridge failed to post CAB Memory Write") ;
3338
            disable main ;
3339
        end
3340
 
3341
        write_flags`WB_TRANSFER_SIZE = 3 ;
3342
        wishbone_master.wb_block_write(write_flags, write_status) ;
3343
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3344
        begin
3345
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3346
            $display("Bridge failed to process complete CAB write!") ;
3347
            test_fail("bridge failed to post CAB Memory Write") ;
3348
            disable main ;
3349
        end
3350
    end
3351
    begin
3352
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3353
        if ( ok !== 1 )
3354
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3355
        else
3356
        begin
3357
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3358
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3359
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3360
            if ( ok !== 1 )
3361
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3362
            else
3363
                test_ok ;
3364
        end
3365
    end
3366
    join
3367
 
3368
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3369
    ok = 1 ;
3370
    // check statuses and data from error
3371
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3372
    if ( temp_val1[8] !== 1 )
3373
    begin
3374
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3375
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3376
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3377
        ok = 0 ;
3378
    end
3379
 
3380
    if ( temp_val1[9] !== 0 )
3381
    begin
3382
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3383
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3384
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3385
        ok = 0 ;
3386
    end
3387
 
3388
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3389
    begin
3390
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3391
        $display("Value in W_ERR_CS register was wrong!") ;
3392
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3393
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3394
        ok = 0 ;
3395
    end
3396
 
3397
    if ( ok )
3398
        test_ok ;
3399
 
3400
    // check erroneous address and data
3401
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3402
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3403
    ok = 1 ;
3404
    if ( temp_val1 !== (target_address + 8 + 4) )
3405
    begin
3406
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3407
        $display("Value in W_ERR_ADDR register was wrong!") ;
3408
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3409
        test_fail("Value in WB Erroneous Address register was wrong") ;
3410
        ok = 0 ;
3411
 
3412
    end
3413
 
3414
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3415
    if ( temp_val1 !== wmem_data[121] )
3416
    begin
3417
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3418
        $display("Value in W_ERR_DATA register was wrong!") ;
3419
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3420
        test_fail("Value in WB Erroneous Data register was wrong") ;
3421
        ok = 0 ;
3422
    end
3423
 
3424
    if ( ok )
3425
        test_ok ;
3426
 
3427
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3428
    `ifdef HOST
3429
        repeat(4)
3430
            @(posedge wb_clock) ;
3431
        if ( INT_O !== 1 )
3432
        begin
3433
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3434
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3435
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3436
        end
3437
        else
3438
            test_ok ;
3439
    `else
3440
    `ifdef GUEST
3441
        repeat(4)
3442
            @(posedge pci_clock) ;
3443
        if ( INTA !== 0 )
3444
        begin
3445
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3446
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3447
            test_fail("interrupt request was not presented on PCI bus") ;
3448
        end
3449
        else
3450
            test_ok ;
3451
    `endif
3452
    `endif
3453
 
3454
    // read interrupt status register
3455
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3456
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3457
    if ( temp_val1[1] !== 1 )
3458
    begin
3459
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3460
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3461
        test_fail("Expected Interrupt status bit wasn't set") ;
3462
    end
3463
 
3464
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3465
 
3466
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3467
    ok = 1 ;
3468
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3469
    if ( temp_val1[29] !== 0 )
3470
    begin
3471
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3472
        $display("Received Master Abort bit was set with no reason!") ;
3473
        test_fail("Received Master Abort bit was set with no reason") ;
3474
        ok = 0 ;
3475
    end
3476
 
3477
    if ( temp_val1[28] !== 1 )
3478
    begin
3479
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3480
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3481
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3482
        ok = 0 ;
3483
    end
3484
 
3485
    if ( ok )
3486
        test_ok ;
3487
 
3488
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3489
 
3490
    // clear interrupts and errors
3491
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3492
    repeat( 3 )
3493
        @(posedge pci_clock) ;
3494
 
3495
    repeat( 2 )
3496
        @(posedge wb_clock) ;
3497
 
3498
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3499
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3500
    if ( temp_val1[1] !== 0 )
3501
    begin
3502
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3503
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3504
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3505
    end
3506
    else
3507
        test_ok ;
3508
 
3509
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3510
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3511
    if ( temp_val1[8] !== 0 )
3512
    begin
3513
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3514
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3515
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3516
    end
3517
 
3518
 
3519
    $display("Introducing Target Abort error to single read!") ;
3520
    // set read data
3521
    read_data`READ_ADDRESS = target_address + 8 ;
3522
    read_data`READ_SEL     = 4'hF ;
3523
 
3524
    // enable automatic retry handling
3525
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3526
    write_flags`WB_TRANSFER_CAB    = 0 ;
3527
 
3528
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3529
 
3530
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3531
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3532
 
3533
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3534
 
3535
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3536
    begin
3537
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3538
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3539
        $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) ;
3540
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3541
        disable main ;
3542
    end
3543
    else
3544
        test_ok ;
3545
 
3546
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3547
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3548
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3549
    if ( temp_val1[8] !== 0 )
3550
    begin
3551
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3552
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3553
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3554
    end
3555
    else
3556
        test_ok ;
3557
 
3558
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3559
    ok = 1 ;
3560
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3561
    if ( temp_val1[29] !== 0 )
3562
    begin
3563
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3564
        $display("Received Master Abort bit was set with no reason!") ;
3565
        test_fail("Received Master Abort bit was set with no reason") ;
3566
        ok = 0 ;
3567
    end
3568
 
3569
    if ( temp_val1[28] !== 1 )
3570
    begin
3571
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3572
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3573
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3574
        ok = 0 ;
3575
    end
3576
 
3577
    if ( ok )
3578
        test_ok ;
3579
 
3580
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3581
 
3582
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3583
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3584
    if ( temp_val1[1] !== 0 )
3585
    begin
3586
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3587
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3588
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3589
    end
3590
    else
3591
        test_ok ;
3592
 
3593
    $display("Introducing Target Abort error to CAB read!") ;
3594
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3595
 
3596
    for ( i = 0 ; i < 4 ; i = i + 1 )
3597
    begin
3598
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3599
        read_data`READ_SEL     = 4'b1010 ;
3600
        wishbone_master.blk_read_data_in[i] = read_data ;
3601
    end
3602
 
3603
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3604
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3605
    write_flags`WB_TRANSFER_CAB    = 1 ;
3606
 
3607
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3608
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3609
 
3610
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3611
 
3612
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3613
    begin
3614
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3615
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3616
        $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) ;
3617
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3618
        disable main ;
3619
    end
3620
 
3621
    read_status = wishbone_master.blk_read_data_out[0] ;
3622
    temp_val1 = read_status`READ_DATA ;
3623
    temp_val2 = wmem_data[120] ;
3624
 
3625
    // last write to this address was with only two byte enables - check only those
3626
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3627
    begin
3628
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3629
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3630
    end
3631
    else
3632
        test_ok ;
3633
 
3634
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3635
    ok = 1 ;
3636
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3637
    if ( temp_val1[29] !== 0 )
3638
    begin
3639
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3640
        $display("Received Master Abort bit was set with no reason!") ;
3641
        test_fail("Received Master Abort bit was set with no reason") ;
3642
        ok = 0 ;
3643
    end
3644
 
3645
    if ( temp_val1[28] !== 1 )
3646
    begin
3647
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3648
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3649
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3650
        ok = 0 ;
3651
    end
3652
 
3653
    if ( ok )
3654
       test_ok ;
3655
 
3656
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3657
 
3658
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3659
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3660
 
3661
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3662
    for ( i = 0 ; i < 3 ; i = i + 1 )
3663
    begin
3664
        read_data`READ_ADDRESS = target_address + 4*i ;
3665
        read_data`READ_SEL     = 4'b1111 ;
3666
        wishbone_master.blk_read_data_in[i] = read_data ;
3667
    end
3668
 
3669
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3670
 
3671
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3672
 
3673
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3674
    begin
3675
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3676
        $display("Complete burst read through WB slave didn't succeed!") ;
3677
        test_fail("bridge didn't process Burst Read in an expected way") ;
3678
        disable main ;
3679
    end
3680
    else
3681
        test_ok ;
3682
 
3683
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3684
 
3685
    for ( i = 0 ; i < 3 ; i = i + 1 )
3686
    begin
3687
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3688
        read_data`READ_SEL     = 4'b1111 ;
3689
        wishbone_master.blk_read_data_in[i] = read_data ;
3690
    end
3691
 
3692
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3693
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3694
    write_flags`WB_TRANSFER_CAB    = 1 ;
3695
 
3696
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3697
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3698
 
3699
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3700
 
3701
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3702
    begin
3703
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3704
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3705
        $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) ;
3706
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3707
        disable main ;
3708
    end
3709
 
3710
    for ( i = 0 ; i < 3 ; i = i + 1 )
3711
    begin
3712
        ok = 1 ;
3713
        read_status = wishbone_master.blk_read_data_out[i] ;
3714
        temp_val1 = read_status`READ_DATA ;
3715
        temp_val2 = wmem_data[120 + i] ;
3716
 
3717
        // last write to this address was with only two byte enables - check only those
3718
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3719
        begin
3720
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3721
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3722
            ok = 0 ;
3723
        end
3724
    end
3725
 
3726
    if ( ok )
3727
        test_ok ;
3728
 
3729
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3730
    ok = 1 ;
3731
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3732
    if ( temp_val1[29] !== 0 )
3733
    begin
3734
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3735
        $display("Received Master Abort bit was set with no reason!") ;
3736
        test_fail("Received Master Abort bit was set with no reason") ;
3737
        ok = 0 ;
3738
    end
3739
 
3740
    if ( temp_val1[28] !== 1 )
3741
    begin
3742
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3743
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3744
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3745
        ok = 0 ;
3746
    end
3747
 
3748
    if ( ok )
3749
       test_ok ;
3750
 
3751
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3752
 
3753
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3754
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3755
 
3756
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3757
    for ( i = 0 ; i < 3 ; i = i + 1 )
3758
    begin
3759
        read_data`READ_ADDRESS = target_address + 4*i ;
3760
        read_data`READ_SEL     = 4'b1111 ;
3761
        wishbone_master.blk_read_data_in[i] = read_data ;
3762
    end
3763
 
3764
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3765
 
3766
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3767
 
3768
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3769
    begin
3770
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3771
        $display("Complete burst read through WB slave didn't succeed!") ;
3772
        test_fail("bridge didn't process Burst Read in an expected way") ;
3773
        disable main ;
3774
    end
3775
    else
3776
        test_ok ;
3777
 
3778
    // test error on IO write
3779
    // change base address
3780
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3781
    write_data`WRITE_SEL     = 4'b0101 ;
3782
    write_data`WRITE_ADDRESS = target_address ;
3783
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3784
 
3785
    write_flags`WB_TRANSFER_CAB    = 0 ;
3786
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3787
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3788
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3789
    fork
3790
    begin
3791
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3792
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3793
        begin
3794
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3795
            $display("WB slave failed to accept IO write!") ;
3796
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3797
            disable main ;
3798
        end
3799
    end
3800
    begin
3801
        musnt_respond(ok) ;
3802
        if ( ok !== 1 )
3803
        begin
3804
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3805
            $display("Testbench is configured wrong!") ;
3806
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3807
        end
3808
        else
3809
            test_ok ;
3810
    end
3811
    join
3812
 
3813
    // check statuses and everything else
3814
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3815
    ok = 1 ;
3816
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3817
    if ( temp_val1[8] !== 1 )
3818
    begin
3819
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3820
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3821
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3822
        ok = 0 ;
3823
    end
3824
 
3825
    if ( temp_val1[9] !== 1 )
3826
    begin
3827
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3828
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3829
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3830
        ok = 0 ;
3831
    end
3832
 
3833
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3834
    begin
3835
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3836
        $display("Value in W_ERR_CS register was wrong!") ;
3837
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3838
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3839
        ok = 0 ;
3840
    end
3841
 
3842
    if ( ok )
3843
        test_ok ;
3844
 
3845
    // check erroneous address and data
3846
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3847
    ok = 1 ;
3848
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3849
    if ( temp_val1 !== target_address )
3850
    begin
3851
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3852
        $display("Value in W_ERR_ADDR register was wrong!") ;
3853
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3854
        test_fail("WB Erroneous Address register didn't provide right value") ;
3855
        ok = 0 ;
3856
    end
3857
 
3858
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3859
    if ( temp_val1 !== 32'hAAAA_AAAA )
3860
    begin
3861
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3862
        $display("Value in W_ERR_DATA register was wrong!") ;
3863
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3864
        test_fail("WB Erroneous Data register didn't provide right value") ;
3865
        ok = 0 ;
3866
    end
3867
 
3868
    if ( ok )
3869
        test_ok ;
3870
 
3871
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3872
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3873
    if ( temp_val1[1] !== 1 )
3874
    begin
3875
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3876
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3877
        test_fail("expected interrupt status bit was not set") ;
3878
    end
3879
    else
3880
        test_ok ;
3881
 
3882
    // clear interrupts and errors
3883
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3884
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3885
 
3886
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3887
    ok = 1 ;
3888
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3889
    if ( temp_val1[29] !== 1 )
3890
    begin
3891
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3892
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3893
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3894
        ok = 0 ;
3895
    end
3896
 
3897
    if ( temp_val1[28] !== 0 )
3898
    begin
3899
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3900
        $display("Received Target Abort bit was set for no reason!") ;
3901
        test_fail("Received Target Abort bit was set for no reason") ;
3902
        ok = 0 ;
3903
    end
3904
 
3905
    if ( ok )
3906
        test_ok ;
3907
 
3908
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3909
 
3910
    // disable image
3911
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3912
    if ( ok !== 1 )
3913
    begin
3914
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3915
        test_fail("WB Image Address Mask register couldn't be written") ;
3916
        disable main ;
3917
    end
3918
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3919
 
3920
end
3921
endtask
3922
 
3923
task parity_checking ;
3924
    reg   [11:0] ctrl_offset ;
3925
    reg   [11:0] ba_offset ;
3926
    reg   [11:0] am_offset ;
3927
    reg   [11:0] ta_offset ;
3928
    reg `WRITE_STIM_TYPE write_data ;
3929
    reg `READ_STIM_TYPE  read_data ;
3930
    reg `READ_RETURN_TYPE read_status ;
3931
 
3932
    reg `WRITE_RETURN_TYPE write_status ;
3933
    reg `WB_TRANSFER_FLAGS write_flags ;
3934
    reg [31:0] temp_val1 ;
3935
    reg [31:0] temp_val2 ;
3936
    reg        ok   ;
3937
    reg [11:0] pci_ctrl_offset ;
3938
    reg [31:0] image_base ;
3939
    reg [31:0] target_address ;
3940
    reg [11:0] icr_offset ;
3941
    reg [11:0] isr_offset ;
3942
    reg [11:0] p_ba_offset ;
3943
    reg [11:0] p_am_offset ;
3944
    reg [11:0] p_ctrl_offset ;
3945
    integer    i ;
3946
    reg        perr_asserted ;
3947
begin:main
3948
    $display("******************************* Testing Parity Checker functions ********************************") ;
3949
    $display("Testing Parity Errors during Master Transactions!") ;
3950
    $display("Introducing Parity Erros to Master Writes!") ;
3951
    $fdisplay(pci_mon_log_file_desc,
3952
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
3953
 
3954
    // image 1 is used for error testing, since it is always implemented
3955
    pci_ctrl_offset = 12'h004 ;
3956
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
3957
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
3958
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
3959
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
3960
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
3961
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
3962
 
3963
    // image 1 for PCI target
3964
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
3965
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
3966
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
3967
 
3968
    target_address  = `BEH_TAR1_MEM_START ;
3969
    image_base      = 0 ;
3970
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
3971
 
3972
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
3973
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
3974
    write_flags                    = 0 ;
3975
    write_flags`INIT_WAITS         = tb_init_waits ;
3976
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
3977
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3978
 
3979
    // enable master & target operation and disable parity functions
3980
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
3981
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
3982
    if ( ok !== 1 )
3983
    begin
3984
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
3985
        test_fail("PCI Device Control register could not be written to") ;
3986
        disable main ;
3987
    end
3988
 
3989
    // prepare image control register
3990
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
3991
    if ( ok !== 1 )
3992
    begin
3993
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
3994
        test_fail("WB Image Control register could not be written to") ;
3995
        disable main ;
3996
    end
3997
 
3998
    // prepare base address register
3999
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4000
    if ( ok !== 1 )
4001
    begin
4002
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4003
        test_fail("WB Image Base Address register could not be written to") ;
4004
        disable main ;
4005
    end
4006
 
4007
    // write address mask register
4008
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4009
    if ( ok !== 1 )
4010
    begin
4011
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4012
        test_fail("WB Image Address Mask register could not be written to") ;
4013
        disable main ;
4014
    end
4015
 
4016
    // disable parity interrupts
4017
    config_write( icr_offset, 0, 4'hF, ok ) ;
4018
    if ( ok !== 1 )
4019
    begin
4020
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4021
        test_fail("Interrupt Control register could not be written to") ;
4022
        disable main ;
4023
    end
4024
 
4025
    write_data`WRITE_ADDRESS = target_address ;
4026
    write_data`WRITE_DATA    = wmem_data[0] ;
4027
    write_data`WRITE_SEL     = 4'b1111 ;
4028
 
4029
    // enable target's 1 response to parity errors
4030 45 mihad
    configuration_cycle_write(0,                        // bus number
4031
                              `TAR1_IDSEL_INDEX - 11,   // device number
4032
                              0,                        // function number
4033
                              1,                        // register number
4034
                              0,                        // type of configuration cycle
4035
                              4'b0001,                  // byte enables
4036
                              32'h0000_0047             // data
4037 15 mihad
                             ) ;
4038
 
4039
    // disable target's 2 response to parity errors
4040 45 mihad
    configuration_cycle_write(0,                        // bus number
4041
                              `TAR2_IDSEL_INDEX - 11,   // device number
4042
                              0,                        // function number
4043
                              1,                        // register number
4044
                              0,                        // type of configuration cycle
4045
                              4'b0001,                  // byte enables
4046
                              32'h0000_0007             // data
4047 15 mihad
                             ) ;
4048
 
4049
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4050
 
4051
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4052
    fork
4053
    begin
4054
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4055
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4056
        begin
4057
            $display("Parity checker testing failed! Time %t ", $time) ;
4058
            $display("Bridge failed to process single memory write!") ;
4059
            test_fail("bridge failed to post single WB memory write") ;
4060
            disable main ;
4061
        end
4062
    end
4063
    begin:wait_perr1
4064
        perr_asserted = 0 ;
4065
        @(posedge pci_clock) ;
4066
 
4067 35 mihad
        while ( PERR !== 0 )
4068 15 mihad
            @(posedge pci_clock) ;
4069
 
4070 35 mihad
        perr_asserted = 1 ;
4071 15 mihad
 
4072
    end
4073
    begin
4074
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4075
 
4076
        if ( ok !== 1 )
4077
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4078
 
4079 35 mihad
        repeat(2)
4080 15 mihad
            @(posedge pci_clock) ;
4081
 
4082 35 mihad
        #1 ;
4083
        if ( !perr_asserted )
4084
            disable wait_perr1 ;
4085 15 mihad
    end
4086
    join
4087
 
4088
    if ( perr_asserted && ok )
4089
    begin
4090
        test_ok ;
4091
    end
4092
    else
4093
    if ( ~perr_asserted )
4094
    begin
4095
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4096
        disable main ;
4097
    end
4098
 
4099
    // check all the statuses - if HOST is defined, wait for them to be synced
4100
    `ifdef HOST
4101
    repeat(4)
4102
        @(posedge wb_clock) ;
4103
    `endif
4104
 
4105
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4106
    ok = 1 ;
4107
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4108 45 mihad
    if ( temp_val1[31] !== 0 )
4109 15 mihad
    begin
4110
        $display("Parity checker testing failed! Time %t ", $time) ;
4111 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4112
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4113 15 mihad
        ok = 0 ;
4114
    end
4115
 
4116
    if ( temp_val1[30] !== 0 )
4117
    begin
4118
        $display("Parity checker testing failed! Time %t ", $time) ;
4119
        $display("Signalled System Error bit was set for no reason!") ;
4120
        test_fail("Signalled System Error bit was set for no reason") ;
4121
        ok = 0 ;
4122
    end
4123
 
4124
    if ( temp_val1[24] !== 0 )
4125
    begin
4126
        $display("Parity checker testing failed! Time %t ", $time) ;
4127
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4128
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4129
        ok = 0 ;
4130
    end
4131
 
4132
    if ( ok )
4133
        test_ok ;
4134
 
4135
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4136
    // clear parity bits and enable parity response
4137
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4138
    if ( ok !== 1 )
4139
    begin
4140
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4141
        test_fail("write to PCI Status Register failed") ;
4142
        disable main ;
4143
    end
4144
 
4145
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4146
    fork
4147
    begin
4148
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4149
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4150
        begin
4151
            $display("Parity checker testing failed! Time %t ", $time) ;
4152
            $display("Bridge failed to process single memory write!") ;
4153
            test_fail("bridge failed to post single memory write") ;
4154
            disable main ;
4155
        end
4156
    end
4157
    begin:wait_perr2
4158
        perr_asserted = 0 ;
4159
        @(posedge pci_clock) ;
4160
 
4161 35 mihad
        while ( PERR !== 0 )
4162 15 mihad
            @(posedge pci_clock) ;
4163
 
4164 35 mihad
        perr_asserted = 1 ;
4165 15 mihad
 
4166
    end
4167
    begin
4168
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4169
 
4170
        if ( ok !== 1 )
4171
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4172
 
4173 35 mihad
        repeat(2)
4174 15 mihad
            @(posedge pci_clock) ;
4175
 
4176 35 mihad
        #1 ;
4177
        if (!perr_asserted)
4178
            disable wait_perr2 ;
4179 15 mihad
    end
4180
    join
4181
 
4182
    if ( perr_asserted && ok )
4183
    begin
4184
        test_ok ;
4185
    end
4186
    else
4187
    if ( ~perr_asserted )
4188
    begin
4189
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4190
        disable main ;
4191
    end
4192
 
4193
    // check all the statuses - if HOST is defined, wait for them to be synced
4194
    `ifdef HOST
4195
    repeat(4)
4196
        @(posedge wb_clock) ;
4197
    `endif
4198
 
4199
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4200
    ok = 1 ;
4201
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4202 45 mihad
    if ( temp_val1[31] !== 0 )
4203 15 mihad
    begin
4204
        $display("Parity checker testing failed! Time %t ", $time) ;
4205 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4206
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4207 15 mihad
        ok = 0 ;
4208
    end
4209
 
4210
    if ( temp_val1[30] !== 0 )
4211
    begin
4212
        $display("Parity checker testing failed! Time %t ", $time) ;
4213
        $display("Signalled System Error bit was set for no reason!") ;
4214
        test_fail("Signalled System Error bit was set for no reason") ;
4215
        ok = 0 ;
4216
    end
4217
 
4218
    if ( temp_val1[24] !== 1 )
4219
    begin
4220
        $display("Parity checker testing failed! Time %t ", $time) ;
4221 45 mihad
        $display("Master Data Parity Error bit wasn't set even though Parity Error Response bit was set and data parity error occured during Master write!") ;
4222
        test_fail("Master Data Parity Error bit wasn't set after Data Parity Error during Write on PCI bus, even though Parity Error Response bit was set") ;
4223 15 mihad
        ok = 0 ;
4224
    end
4225
 
4226
    if ( ok )
4227
        test_ok ;
4228
 
4229
    // clear status bits and disable parity error response
4230
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4231
 
4232
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4233
 
4234
    // disable perr generation and perform a write - no bits should be set
4235
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4236
    fork
4237
    begin
4238
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4239
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4240
        begin
4241
            $display("Parity checker testing failed! Time %t ", $time) ;
4242
            $display("Bridge failed to process single memory write!") ;
4243
            test_fail("bridge failed to post single memory write") ;
4244
            disable main ;
4245
        end
4246
    end
4247
    begin
4248
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4249
 
4250
        if ( ok !== 1 )
4251
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4252
        else
4253
            test_ok ;
4254
 
4255
        repeat(3)
4256
            @(posedge pci_clock) ;
4257
    end
4258
    join
4259
 
4260
    `ifdef HOST
4261
    repeat(4)
4262
        @(posedge wb_clock) ;
4263
    `endif
4264
 
4265
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4266
    ok = 1 ;
4267
 
4268
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4269
    if ( temp_val1[31] !== 0 )
4270
    begin
4271
        $display("Parity checker testing failed! Time %t ", $time) ;
4272
        $display("Detected Parity Error bit was set for no reason!") ;
4273
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4274
        ok = 0 ;
4275
    end
4276
 
4277
    if ( temp_val1[30] !== 0 )
4278
    begin
4279
        $display("Parity checker testing failed! Time %t ", $time) ;
4280
        $display("Signalled System Error bit was set for no reason!") ;
4281
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4282
        ok = 0 ;
4283
    end
4284
 
4285
    if ( temp_val1[24] !== 0 )
4286
    begin
4287
        $display("Parity checker testing failed! Time %t ", $time) ;
4288
        $display("Master Data Parity Error bit was set for no reason!") ;
4289
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4290
        ok = 0 ;
4291
    end
4292
 
4293
    if ( ok )
4294
        test_ok ;
4295
 
4296
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4297
 
4298
    read_data = 0 ;
4299
    read_data`READ_ADDRESS  = target_address ;
4300
    read_data`READ_SEL      = 4'hF ;
4301
    read_data`READ_TAG_STIM = 0 ;
4302
 
4303
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4304
 
4305
    // enable parity and system error interrupts
4306
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4307
 
4308
    // enable parity error response
4309
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4310
 
4311
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4312
 
4313
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4314
    fork
4315
    begin
4316
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4317
    end
4318
    begin:wait_perr4
4319
        perr_asserted = 0 ;
4320
        @(posedge pci_clock) ;
4321 35 mihad
        while ( PERR !== 0 )
4322 15 mihad
            @(posedge pci_clock) ;
4323
 
4324 35 mihad
        perr_asserted = 1 ;
4325 15 mihad
 
4326
    end
4327
    begin
4328
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4329
 
4330
        if ( ok !== 1 )
4331
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4332
 
4333
        repeat(2)
4334
            @(posedge pci_clock) ;
4335
 
4336 35 mihad
        #1 ;
4337
        if ( !perr_asserted )
4338
            disable wait_perr4 ;
4339 15 mihad
    end
4340
    join
4341
 
4342
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4343
    begin
4344
        $display("Parity checker testing failed! Time %t ", $time) ;
4345
        $display("Bridge failed to process single memory read!") ;
4346
        test_fail("bridge didn't process single memory read correctly") ;
4347
        ok = 0 ;
4348
    end
4349
 
4350
    if ( perr_asserted && ok )
4351
    begin
4352
        test_ok ;
4353
    end
4354
    else
4355
    if ( ~perr_asserted )
4356
    begin
4357
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4358
        disable main ;
4359
    end
4360
 
4361
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4362
    // interrupt should also be present
4363
    `ifdef HOST
4364
        repeat(4)
4365 26 mihad
            @(posedge pci_clock) ;
4366
        repeat(4)
4367 15 mihad
            @(posedge wb_clock) ;
4368
 
4369
        if ( INT_O !== 1 )
4370
        begin
4371
            $display("Parity checker testing failed! Time %t ", $time) ;
4372
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4373
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4374
        end
4375
        else
4376
            test_ok ;
4377
    `else
4378
    `ifdef GUEST
4379 26 mihad
        repeat(4)
4380
            @(posedge wb_clock) ;
4381
        repeat(4)
4382 15 mihad
            @(posedge pci_clock) ;
4383
 
4384
        if ( INTA !== 1 )
4385
        begin
4386
            $display("Parity checker testing failed! Time %t ", $time) ;
4387
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4388
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4389
        end
4390
        else
4391
            test_ok ;
4392
    `endif
4393
    `endif
4394
 
4395
    // check statuses!
4396
 
4397
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4398
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4399
    ok = 1 ;
4400
 
4401
    if ( temp_val1[31] !== 1 )
4402
    begin
4403
        $display("Parity checker testing failed! Time %t ", $time) ;
4404 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4405
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4406 15 mihad
        ok = 0 ;
4407
    end
4408
 
4409
    if ( temp_val1[30] !== 0 )
4410
    begin
4411
        $display("Parity checker testing failed! Time %t ", $time) ;
4412
        $display("Signalled System Error bit was set for no reason!") ;
4413
        test_fail("Signalled System Error bit was set for no reason") ;
4414
        ok = 0 ;
4415
    end
4416
 
4417
    if ( temp_val1[24] !== 1 )
4418
    begin
4419
        $display("Parity checker testing failed! Time %t ", $time) ;
4420 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4421
        test_fail("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction and Parity Error Response was enabled") ;
4422 15 mihad
        ok = 0 ;
4423
    end
4424
 
4425
    if ( ok )
4426
        test_ok ;
4427
 
4428
    // clear statuses and disable parity error response
4429
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4430
 
4431
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4432
    ok = 1 ;
4433
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4434
 
4435
    if ( temp_val1[4] !== 0 )
4436
    begin
4437
        $display("Parity checker testing failed! Time %t ", $time) ;
4438
        $display("System error interrupt status bit set for no reason!") ;
4439
        test_fail("System error interrupt status bit set for no reason") ;
4440
        ok = 0 ;
4441
    end
4442
 
4443
    `ifdef HOST
4444
    if ( temp_val1[3] !== 1 )
4445
    begin
4446
        $display("Parity checker testing failed! Time %t ", $time) ;
4447
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4448
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4449
        ok = 0 ;
4450
    end
4451
    `else
4452
    if ( temp_val1[3] !== 0 )
4453
    begin
4454
        $display("Parity checker testing failed! Time %t ", $time) ;
4455
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4456
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4457
        ok = 0 ;
4458
    end
4459
    `endif
4460
 
4461
    if ( ok )
4462
        test_ok ;
4463
 
4464
    // clear int statuses
4465
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4466
 
4467
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4468
 
4469
    `ifdef HOST
4470
        repeat(4)
4471 26 mihad
            @(posedge pci_clock) ;
4472
        repeat(4)
4473 15 mihad
            @(posedge wb_clock) ;
4474
 
4475
        if ( INT_O !== 0 )
4476
        begin
4477
            $display("Parity checker testing failed! Time %t ", $time) ;
4478
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4479
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4480
        end
4481
        else
4482
            test_ok ;
4483
    `else
4484
    `ifdef GUEST
4485 26 mihad
        repeat(4)
4486
            @(posedge wb_clock) ;
4487
        repeat(4)
4488 15 mihad
            @(posedge pci_clock) ;
4489
 
4490
        if ( INTA !== 1 )
4491
        begin
4492
            $display("Parity checker testing failed! Time %t ", $time) ;
4493
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4494
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4495
        end
4496
        else
4497
            test_ok ;
4498
    `endif
4499
    `endif
4500
 
4501
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4502
 
4503
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4504
    fork
4505
    begin
4506
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4507
    end
4508
    begin:wait_perr5
4509
        perr_asserted = 0 ;
4510
        @(posedge pci_clock) ;
4511
        while ( PERR === 1 )
4512
            @(posedge pci_clock) ;
4513
 
4514
        perr_asserted = 1 ;
4515
        $display("Parity checker testing failed! Time %t ", $time) ;
4516 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4517
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4518 15 mihad
    end
4519
    begin
4520
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4521
        if ( ok !== 1 )
4522
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4523
 
4524
        // perr can be asserted on idle or next PCI address phase
4525
        repeat(2)
4526
            @(posedge pci_clock) ;
4527
 
4528 35 mihad
        #1 ;
4529
        if ( !perr_asserted )
4530
            disable wait_perr5 ;
4531 15 mihad
    end
4532
    join
4533
 
4534
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4535
    begin
4536
        $display("Parity checker testing failed! Time %t ", $time) ;
4537
        $display("Bridge failed to process single memory read!") ;
4538
        test_fail("bridge failed to process single memory read correctly") ;
4539
        ok = 0 ;
4540
    end
4541
 
4542
    if ( ok && !perr_asserted)
4543
        test_ok ;
4544
 
4545
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4546
 
4547
    // interrupts should not be present
4548
    `ifdef HOST
4549
        repeat( 4 )
4550 26 mihad
            @(posedge pci_clock) ;
4551
        repeat( 4 )
4552 15 mihad
            @(posedge wb_clock) ;
4553
        if ( INT_O !== 0 )
4554
        begin
4555
            $display("Parity checker testing failed! Time %t ", $time) ;
4556
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4557
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4558
        end
4559
        else
4560
            test_ok ;
4561
    `else
4562
    `ifdef GUEST
4563
        repeat( 4 )
4564 26 mihad
            @(posedge wb_clock) ;
4565
        repeat( 4 )
4566 15 mihad
            @(posedge pci_clock) ;
4567
        if ( INTA !== 1 )
4568
        begin
4569
            $display("Parity checker testing failed! Time %t ", $time) ;
4570
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4571
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4572
        end
4573
        else
4574
            test_ok ;
4575
    `endif
4576
    `endif
4577
 
4578
    // check statuses!
4579
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4580
    ok = 1 ;
4581
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4582
    if ( temp_val1[31] !== 1 )
4583
    begin
4584
        $display("Parity checker testing failed! Time %t ", $time) ;
4585 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4586 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4587
        ok = 0 ;
4588
    end
4589
 
4590
    if ( temp_val1[30] !== 0 )
4591
    begin
4592
        $display("Parity checker testing failed! Time %t ", $time) ;
4593
        $display("Signalled System Error bit was set for no reason!") ;
4594
        test_fail("Signalled System Error bit was set for no reason") ;
4595
        ok = 0 ;
4596
    end
4597
 
4598
    if ( temp_val1[24] !== 0 )
4599
    begin
4600
        $display("Parity checker testing failed! Time %t ", $time) ;
4601 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4602 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4603
        ok = 0 ;
4604
    end
4605
 
4606
    if ( ok )
4607
        test_ok ;
4608
 
4609
    // clear statuses
4610
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4611
 
4612
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4613
    ok = 1 ;
4614
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4615
 
4616
    if ( temp_val1[4] !== 0 )
4617
    begin
4618
        $display("Parity checker testing failed! Time %t ", $time) ;
4619
        $display("System error interrupt status bit set for no reason!") ;
4620
        test_fail("System error interrupt status bit set for no reason") ;
4621
        ok = 0 ;
4622
    end
4623
 
4624
    if ( temp_val1[3] !== 0 )
4625
    begin
4626
        $display("Parity checker testing failed! Time %t ", $time) ;
4627
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4628
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4629
        ok = 0 ;
4630
    end
4631
 
4632
    if ( ok )
4633
        test_ok ;
4634
 
4635
    // enable all responses to parity errors!
4636
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4637
 
4638
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4639
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4640
 
4641
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4642
 
4643
    // repeat a read
4644
    fork
4645
    begin
4646
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4647
    end
4648
    begin:wait_perr6
4649
        perr_asserted = 0 ;
4650
        @(posedge pci_clock) ;
4651
        while ( PERR === 1 )
4652
            @(posedge pci_clock) ;
4653
 
4654
        perr_asserted = 1 ;
4655
        $display("Parity checker testing failed! Time %t ", $time) ;
4656
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4657
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4658
    end
4659
    begin
4660
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4661
        if ( ok !== 1 )
4662
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4663
 
4664
        repeat(2)
4665
            @(posedge pci_clock) ;
4666
 
4667 35 mihad
        #1 ;
4668
        if ( !perr_asserted )
4669
            disable wait_perr6 ;
4670 15 mihad
    end
4671
    join
4672
 
4673
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4674
    begin
4675
        $display("Parity checker testing failed! Time %t ", $time) ;
4676
        $display("Bridge failed to process single memory read!") ;
4677
        test_fail("bridge didn't process single memory read as expected") ;
4678
        ok = 0 ;
4679
    end
4680
 
4681
    if ( ok && !perr_asserted)
4682
        test_ok ;
4683
 
4684
    // check statuses!
4685
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4686
    ok = 1 ;
4687
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4688
    if ( temp_val1[31] !== 0 )
4689
    begin
4690
        $display("Parity checker testing failed! Time %t ", $time) ;
4691
        $display("Detected Parity Error bit was set for no reason!") ;
4692
        test_fail("Detected Parity Error bit was set for no reason") ;
4693
        ok = 0 ;
4694
    end
4695
 
4696
    if ( temp_val1[30] !== 0 )
4697
    begin
4698
        $display("Parity checker testing failed! Time %t ", $time) ;
4699
        $display("Signalled System Error bit was set for no reason!") ;
4700
        test_fail("Signalled System Error bit was set for no reason") ;
4701
        ok = 0 ;
4702
    end
4703
 
4704
    if ( temp_val1[24] !== 0 )
4705
    begin
4706
        $display("Parity checker testing failed! Time %t ", $time) ;
4707
        $display("Master Data Parity Error bit was set for no reason!") ;
4708
        test_fail("Master Data Parity Error bit was set for no reason") ;
4709
        ok = 0 ;
4710
    end
4711
 
4712
    if ( ok )
4713
        test_ok ;
4714
 
4715
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4716
    ok = 1 ;
4717
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4718
 
4719
    if ( temp_val1[4] !== 0 )
4720
    begin
4721
        $display("Parity checker testing failed! Time %t ", $time) ;
4722
        $display("System error interrupt status bit set for no reason!") ;
4723
        test_fail("System error interrupt status bit set for no reason") ;
4724
        ok = 0 ;
4725
    end
4726
 
4727
    if ( temp_val1[3] !== 0 )
4728
    begin
4729
        $display("Parity checker testing failed! Time %t ", $time) ;
4730
        $display("Parity error interrupt status bit set for no reason!") ;
4731
        test_fail("Parity error interrupt status bit set for no reason") ;
4732
        ok = 0 ;
4733
    end
4734
 
4735
    if ( ok )
4736
        test_ok ;
4737
 
4738
    $display("Presenting address parity error on PCI bus!") ;
4739
    // enable parity errors - this should not affect system errors
4740
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4741
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4742
 
4743
    // perform PCI write
4744
    // check transaction progress
4745
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4746
    fork
4747
    begin
4748
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4749
               target_address, 32'h1234_5678,
4750
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4751
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4752
        do_pause( 1 ) ;
4753
    end
4754
    begin:wait_serr7
4755
        perr_asserted = 0 ;
4756
        @(posedge pci_clock) ;
4757
        while( SERR === 1 )
4758
            @(posedge pci_clock) ;
4759
 
4760
        perr_asserted = 1 ;
4761
        $display("Parity checker testing failed! Time %t ", $time) ;
4762
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4763
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4764
    end
4765
    begin
4766
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4767
        if ( ok !== 1 )
4768
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4769
 
4770 35 mihad
        if ( !perr_asserted )
4771
            disable wait_serr7 ;
4772 15 mihad
    end
4773
    join
4774
 
4775
    if ( ok && !perr_asserted)
4776
        test_ok ;
4777
 
4778
    // check statuses!
4779
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4780
    ok = 1 ;
4781
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4782
    if ( temp_val1[31] !== 1 )
4783
    begin
4784
        $display("Parity checker testing failed! Time %t ", $time) ;
4785
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4786
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4787
        ok = 0 ;
4788
    end
4789
 
4790
    if ( temp_val1[30] !== 0 )
4791
    begin
4792
        $display("Parity checker testing failed! Time %t ", $time) ;
4793
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4794
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4795
        ok = 0 ;
4796
    end
4797
 
4798
    if ( temp_val1[24] !== 0 )
4799
    begin
4800
        $display("Parity checker testing failed! Time %t ", $time) ;
4801
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4802
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4803
        ok = 0 ;
4804
    end
4805
 
4806
    if ( ok )
4807
        test_ok ;
4808
 
4809
    // clear statuses
4810
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4811
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4812
    fork
4813
    begin
4814
        ipci_unsupported_commands_master.master_reference
4815
        (
4816
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4817
            32'h5555_5555,      // second part of address in dual address cycle
4818
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4819
            `BC_MEM_WRITE,      // normal command
4820
            4'h0,               // byte enables
4821
            32'h1234_5678,      // data
4822
            1'b1,               // make address parity error on first phase of dual address
4823
            1'b0,               // make address parity error on second phase of dual address
4824
            ok                  // result of operation
4825
        ) ;
4826 35 mihad
        if ( !perr_asserted )
4827
            disable wait_serr8 ;
4828 15 mihad
    end
4829
    begin:wait_serr8
4830
        perr_asserted = 0 ;
4831
        @(posedge pci_clock) ;
4832
        while( SERR === 1 )
4833
            @(posedge pci_clock) ;
4834
 
4835
        perr_asserted = 1 ;
4836
        $display("Parity checker testing failed! Time %t ", $time) ;
4837
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4838
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4839
    end
4840
    join
4841
 
4842
    if ( ok && !perr_asserted)
4843
        test_ok ;
4844
 
4845
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4846
    fork
4847
    begin
4848
        ipci_unsupported_commands_master.master_reference
4849
        (
4850
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4851
            32'h5555_5555,      // second part of address in dual address cycle
4852
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4853
            `BC_MEM_WRITE,      // normal command
4854
            4'h0,               // byte enables
4855
            32'h1234_5678,      // data
4856
            1'b0,               // make address parity error on first phase of dual address
4857
            1'b1,               // make address parity error on second phase of dual address
4858
            ok                  // result of operation
4859
        ) ;
4860 35 mihad
        if ( !perr_asserted )
4861
            disable wait_serr9 ;
4862 15 mihad
    end
4863
    begin:wait_serr9
4864
        perr_asserted = 0 ;
4865
        @(posedge pci_clock) ;
4866
        while( SERR === 1 )
4867
            @(posedge pci_clock) ;
4868
 
4869
        perr_asserted = 1 ;
4870
        $display("Parity checker testing failed! Time %t ", $time) ;
4871
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4872
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4873
    end
4874
    join
4875
 
4876
    if ( ok && !perr_asserted)
4877
        test_ok ;
4878
 
4879
    // check statuses!
4880
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4881
    ok = 1 ;
4882
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4883
    if ( temp_val1[31] !== 1 )
4884
    begin
4885
        $display("Parity checker testing failed! Time %t ", $time) ;
4886
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4887
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4888
        ok = 0 ;
4889
    end
4890
 
4891
    if ( temp_val1[30] !== 0 )
4892
    begin
4893
        $display("Parity checker testing failed! Time %t ", $time) ;
4894
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4895
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4896
        ok = 0 ;
4897
    end
4898
 
4899
    if ( temp_val1[24] !== 0 )
4900
    begin
4901
        $display("Parity checker testing failed! Time %t ", $time) ;
4902
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4903
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4904
        ok = 0 ;
4905
    end
4906
 
4907
    if ( ok )
4908
        test_ok ;
4909
 
4910
    // clear statuses
4911
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4912
 
4913
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4914
    fork
4915
    begin
4916
        ipci_unsupported_commands_master.master_reference
4917
        (
4918
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4919
            32'h5555_5555,      // second part of address in dual address cycle
4920
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4921
            `BC_MEM_WRITE,      // normal command
4922
            4'h0,               // byte enables
4923
            32'h1234_5678,      // data
4924
            1'b1,               // make address parity error on first phase of dual address
4925
            1'b1,               // make address parity error on second phase of dual address
4926
            ok                  // result of operation
4927
        ) ;
4928 35 mihad
        if ( !perr_asserted )
4929
            disable wait_serr10 ;
4930 15 mihad
    end
4931
    begin:wait_serr10
4932
        perr_asserted = 0 ;
4933
        @(posedge pci_clock) ;
4934
        while( SERR === 1 )
4935
            @(posedge pci_clock) ;
4936
 
4937
        perr_asserted = 1 ;
4938
        $display("Parity checker testing failed! Time %t ", $time) ;
4939
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4940
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4941
    end
4942
    join
4943
 
4944
    if ( ok && !perr_asserted)
4945
        test_ok ;
4946
 
4947
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
4948
 
4949
    `ifdef HOST
4950
        repeat(4)
4951 26 mihad
            @(posedge pci_clock) ;
4952
        repeat(4)
4953 15 mihad
            @(posedge wb_clock) ;
4954
        if ( INT_O !== 0 )
4955
        begin
4956
            $display("Parity checker testing failed! Time %t ", $time) ;
4957
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
4958
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
4959
        end
4960
        else
4961
            test_ok ;
4962
    `else
4963
    `ifdef GUEST
4964 26 mihad
        repeat(4)
4965
            @(posedge wb_clock) ;
4966
        repeat(4)
4967 15 mihad
            @(posedge pci_clock) ;
4968
 
4969
        if ( INTA !== 1 )
4970
        begin
4971
            $display("Parity checker testing failed! Time %t ", $time) ;
4972
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
4973
            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") ;
4974
        end
4975
        else
4976
            test_ok ;
4977
    `endif
4978
    `endif
4979
 
4980
    // check statuses!
4981
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4982
    ok = 1 ;
4983
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4984
    if ( temp_val1[31] !== 1 )
4985
    begin
4986
        $display("Parity checker testing failed! Time %t ", $time) ;
4987
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4988
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4989
        ok = 0 ;
4990
    end
4991
 
4992
    if ( temp_val1[30] !== 0 )
4993
    begin
4994
        $display("Parity checker testing failed! Time %t ", $time) ;
4995
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4996
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4997
        ok = 0 ;
4998
    end
4999
 
5000
    if ( temp_val1[24] !== 0 )
5001
    begin
5002
        $display("Parity checker testing failed! Time %t ", $time) ;
5003
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5004
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5005
        ok = 0 ;
5006
    end
5007
 
5008
    if ( ok )
5009
        test_ok ;
5010
 
5011
    // clear statuses
5012
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5013
 
5014
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5015
    ok = 1 ;
5016
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5017
 
5018
    if ( temp_val1[4] !== 0 )
5019
    begin
5020
        $display("Parity checker testing failed! Time %t ", $time) ;
5021
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5022
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5023
        ok = 0 ;
5024
    end
5025
 
5026
    if ( temp_val1[3] !== 0 )
5027
    begin
5028
        $display("Parity checker testing failed! Time %t ", $time) ;
5029
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5030
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5031
        ok = 0 ;
5032
    end
5033
 
5034
    if ( ok )
5035
        test_ok ;
5036
 
5037
    // now enable system error signaling and test response
5038
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5039
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5040
 
5041
    fork
5042
    begin
5043
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5044
               target_address, 32'h1234_5678,
5045
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5046
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5047
        do_pause( 1 ) ;
5048
    end
5049
    begin:wait_serr11
5050
        perr_asserted = 0 ;
5051
        @(posedge pci_clock) ;
5052 35 mihad
        while( SERR !== 0 )
5053 15 mihad
            @(posedge pci_clock) ;
5054
 
5055 35 mihad
        perr_asserted = 1 ;
5056 15 mihad
    end
5057
    begin
5058
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5059
        if ( ok !== 1 )
5060
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5061
 
5062
        @(posedge pci_clock) ;
5063 35 mihad
        #1 ;
5064
        if ( !perr_asserted )
5065
            disable wait_serr11 ;
5066 15 mihad
    end
5067
    join
5068
 
5069
    if ( ok && perr_asserted)
5070
        test_ok ;
5071
    else
5072
    if ( !perr_asserted )
5073
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5074
 
5075
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5076
 
5077
    `ifdef HOST
5078
        repeat(4)
5079 26 mihad
            @(posedge pci_clock) ;
5080
        repeat(4)
5081 15 mihad
            @(posedge wb_clock) ;
5082
        if ( INT_O !== 1 )
5083
        begin
5084
            $display("Parity checker testing failed! Time %t ", $time) ;
5085
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5086
            test_fail("Interrupt Request was not triggered as expected") ;
5087
        end
5088
        else
5089
            test_ok ;
5090
    `else
5091
    `ifdef GUEST
5092 26 mihad
        repeat(4)
5093
            @(posedge wb_clock) ;
5094
        repeat(4)
5095 15 mihad
            @(posedge pci_clock) ;
5096
 
5097
        if ( INTA !== 1 )
5098
        begin
5099
            $display("Parity checker testing failed! Time %t ", $time) ;
5100
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5101
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5102
        end
5103
        else
5104
            test_ok ;
5105
    `endif
5106
    `endif
5107
 
5108
    // check statuses!
5109
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5110
    ok = 1 ;
5111
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5112
    if ( temp_val1[31] !== 1 )
5113
    begin
5114
        $display("Parity checker testing failed! Time %t ", $time) ;
5115
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5116
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5117
        ok = 0 ;
5118
    end
5119
 
5120
    if ( temp_val1[30] !== 1 )
5121
    begin
5122
        $display("Parity checker testing failed! Time %t ", $time) ;
5123
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5124
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5125
        ok = 0 ;
5126
    end
5127
 
5128
    if ( temp_val1[24] !== 0 )
5129
    begin
5130
        $display("Parity checker testing failed! Time %t ", $time) ;
5131
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5132
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5133
        ok = 0 ;
5134
    end
5135
 
5136
    if ( ok )
5137
        test_ok ;
5138
 
5139
    // clear statuses
5140
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5141
 
5142
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5143
 
5144
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5145
    ok = 1 ;
5146
 
5147
    `ifdef HOST
5148
    if ( temp_val1[4] !== 1 )
5149
    begin
5150
        $display("Parity checker testing failed! Time %t ", $time) ;
5151
        $display("System error interrupt status bit not set when expected!") ;
5152
        test_fail("System error interrupt status bit not set when expected") ;
5153
        ok = 0 ;
5154
    end
5155
    `else
5156
    if ( temp_val1[4] !== 0 )
5157
    begin
5158
        $display("Parity checker testing failed! Time %t ", $time) ;
5159
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5160
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5161
        ok = 0 ;
5162
    end
5163
    `endif
5164
 
5165
    if ( temp_val1[3] !== 0 )
5166
    begin
5167
        $display("Parity checker testing failed! Time %t ", $time) ;
5168
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5169
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5170
        ok = 0 ;
5171
    end
5172
 
5173
    if ( ok )
5174
        test_ok ;
5175
 
5176
    // clear statuses
5177
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5178
 
5179
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5180
    fork
5181
    begin
5182
        ipci_unsupported_commands_master.master_reference
5183
        (
5184
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5185
            32'h5555_5555,      // second part of address in dual address cycle
5186
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5187
            `BC_MEM_WRITE,      // normal command
5188
            4'h0,               // byte enables
5189
            32'h1234_5678,      // data
5190
            1'b1,               // make address parity error on first phase of dual address
5191
            1'b0,               // make address parity error on second phase of dual address
5192
            ok                  // result of operation
5193
        ) ;
5194 35 mihad
        if ( !perr_asserted )
5195
            disable wait_serr14 ;
5196 15 mihad
    end
5197
    begin:wait_serr14
5198
        perr_asserted = 0 ;
5199
        @(posedge pci_clock) ;
5200 35 mihad
        while( SERR !== 0 )
5201 15 mihad
            @(posedge pci_clock) ;
5202
 
5203 35 mihad
        perr_asserted = 1 ;
5204 15 mihad
    end
5205
    join
5206
 
5207
    if ( ok && perr_asserted)
5208
        test_ok ;
5209
    else
5210
    if ( !perr_asserted )
5211
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5212
 
5213
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5214
 
5215
    `ifdef HOST
5216
        repeat(4)
5217 26 mihad
            @(posedge pci_clock) ;
5218
        repeat(4)
5219 15 mihad
            @(posedge wb_clock) ;
5220
        if ( INT_O !== 1 )
5221
        begin
5222
            $display("Parity checker testing failed! Time %t ", $time) ;
5223
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5224
            test_fail("Interrupt Request was not triggered as expected") ;
5225
        end
5226
        else
5227
            test_ok ;
5228
    `else
5229
    `ifdef GUEST
5230 26 mihad
        repeat(4)
5231
            @(posedge wb_clock) ;
5232
        repeat(4)
5233 15 mihad
            @(posedge pci_clock) ;
5234
 
5235
        if ( INTA !== 1 )
5236
        begin
5237
            $display("Parity checker testing failed! Time %t ", $time) ;
5238
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5239
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5240
        end
5241
        else
5242
            test_ok ;
5243
    `endif
5244
    `endif
5245
 
5246
    // check statuses!
5247
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5248
    ok = 1 ;
5249
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5250
    if ( temp_val1[31] !== 1 )
5251
    begin
5252
        $display("Parity checker testing failed! Time %t ", $time) ;
5253
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5254
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5255
        ok = 0 ;
5256
    end
5257
 
5258
    if ( temp_val1[30] !== 1 )
5259
    begin
5260
        $display("Parity checker testing failed! Time %t ", $time) ;
5261
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5262
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5263
        ok = 0 ;
5264
    end
5265
 
5266
    if ( temp_val1[24] !== 0 )
5267
    begin
5268
        $display("Parity checker testing failed! Time %t ", $time) ;
5269
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5270
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5271
        ok = 0 ;
5272
    end
5273
 
5274
    if ( ok )
5275
        test_ok ;
5276
 
5277
    // clear statuses
5278
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5279
 
5280
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5281
 
5282
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5283
    ok = 1 ;
5284
 
5285
    `ifdef HOST
5286
    if ( temp_val1[4] !== 1 )
5287
    begin
5288
        $display("Parity checker testing failed! Time %t ", $time) ;
5289
        $display("System error interrupt status bit not set when expected!") ;
5290
        test_fail("System error interrupt status bit not set when expected") ;
5291
        ok = 0 ;
5292
    end
5293
    `else
5294
    if ( temp_val1[4] !== 0 )
5295
    begin
5296
        $display("Parity checker testing failed! Time %t ", $time) ;
5297
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5298
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5299
        ok = 0 ;
5300
    end
5301
    `endif
5302
 
5303
    if ( temp_val1[3] !== 0 )
5304
    begin
5305
        $display("Parity checker testing failed! Time %t ", $time) ;
5306
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5307
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5308
        ok = 0 ;
5309
    end
5310
 
5311
    if ( ok )
5312
        test_ok ;
5313
 
5314
    // clear statuses
5315
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5316
 
5317
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5318
    fork
5319
    begin
5320
        ipci_unsupported_commands_master.master_reference
5321
        (
5322
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5323
            32'h5555_5555,      // second part of address in dual address cycle
5324
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5325
            `BC_MEM_WRITE,      // normal command
5326
            4'h0,               // byte enables
5327
            32'h1234_5678,      // data
5328
            1'b0,               // make address parity error on first phase of dual address
5329
            1'b1,               // make address parity error on second phase of dual address
5330
            ok                  // result of operation
5331
        ) ;
5332 35 mihad
        if ( !perr_asserted )
5333
            disable wait_serr15 ;
5334 15 mihad
    end
5335
    begin:wait_serr15
5336
        perr_asserted = 0 ;
5337
        @(posedge pci_clock) ;
5338 35 mihad
        while( SERR !== 0 )
5339 15 mihad
            @(posedge pci_clock) ;
5340
 
5341 35 mihad
        perr_asserted = 1 ;
5342 15 mihad
    end
5343
    join
5344
 
5345
    if ( ok && perr_asserted)
5346
        test_ok ;
5347
    else
5348
    if ( !perr_asserted )
5349
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5350
 
5351
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5352
 
5353
    `ifdef HOST
5354
        repeat(4)
5355 26 mihad
            @(posedge pci_clock) ;
5356
        repeat(4)
5357 15 mihad
            @(posedge wb_clock) ;
5358
        if ( INT_O !== 1 )
5359
        begin
5360
            $display("Parity checker testing failed! Time %t ", $time) ;
5361
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5362
            test_fail("Interrupt Request was not triggered as expected") ;
5363
        end
5364
        else
5365
            test_ok ;
5366
    `else
5367
    `ifdef GUEST
5368 26 mihad
        repeat(4)
5369
            @(posedge wb_clock) ;
5370
        repeat(4)
5371 15 mihad
            @(posedge pci_clock) ;
5372
 
5373
        if ( INTA !== 1 )
5374
        begin
5375
            $display("Parity checker testing failed! Time %t ", $time) ;
5376
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5377
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5378
        end
5379
        else
5380
            test_ok ;
5381
    `endif
5382
    `endif
5383
 
5384
    // check statuses!
5385
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5386
    ok = 1 ;
5387
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5388
    if ( temp_val1[31] !== 1 )
5389
    begin
5390
        $display("Parity checker testing failed! Time %t ", $time) ;
5391
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5392
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5393
        ok = 0 ;
5394
    end
5395
 
5396
    if ( temp_val1[30] !== 1 )
5397
    begin
5398
        $display("Parity checker testing failed! Time %t ", $time) ;
5399
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5400
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5401
        ok = 0 ;
5402
    end
5403
 
5404
    if ( temp_val1[24] !== 0 )
5405
    begin
5406
        $display("Parity checker testing failed! Time %t ", $time) ;
5407
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5408
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5409
        ok = 0 ;
5410
    end
5411
 
5412
    if ( ok )
5413
        test_ok ;
5414
 
5415
    // clear statuses
5416
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5417
 
5418
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5419
 
5420
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5421
    ok = 1 ;
5422
 
5423
    `ifdef HOST
5424
    if ( temp_val1[4] !== 1 )
5425
    begin
5426
        $display("Parity checker testing failed! Time %t ", $time) ;
5427
        $display("System error interrupt status bit not set when expected!") ;
5428
        test_fail("System error interrupt status bit not set when expected") ;
5429
        ok = 0 ;
5430
    end
5431
    `else
5432
    if ( temp_val1[4] !== 0 )
5433
    begin
5434
        $display("Parity checker testing failed! Time %t ", $time) ;
5435
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5436
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5437
        ok = 0 ;
5438
    end
5439
    `endif
5440
 
5441
    if ( temp_val1[3] !== 0 )
5442
    begin
5443
        $display("Parity checker testing failed! Time %t ", $time) ;
5444
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5445
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5446
        ok = 0 ;
5447
    end
5448
 
5449
    if ( ok )
5450
        test_ok ;
5451
 
5452
    // clear statuses
5453
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5454
 
5455
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5456
    fork
5457
    begin
5458
        ipci_unsupported_commands_master.master_reference
5459
        (
5460
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5461
            32'h5555_5555,      // second part of address in dual address cycle
5462
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5463
            `BC_MEM_WRITE,      // normal command
5464
            4'h0,               // byte enables
5465
            32'h1234_5678,      // data
5466
            1'b1,               // make address parity error on first phase of dual address
5467
            1'b1,               // make address parity error on second phase of dual address
5468
            ok                  // result of operation
5469
        ) ;
5470 35 mihad
        if ( !perr_asserted )
5471
            disable wait_serr16 ;
5472 15 mihad
    end
5473
    begin:wait_serr16
5474
        perr_asserted = 0 ;
5475
        @(posedge pci_clock) ;
5476 35 mihad
        while( SERR !== 0 )
5477 15 mihad
            @(posedge pci_clock) ;
5478
 
5479 35 mihad
        perr_asserted = 1 ;
5480 15 mihad
    end
5481
    join
5482
 
5483
    if ( ok && perr_asserted)
5484
        test_ok ;
5485
    else
5486
    if ( !perr_asserted )
5487
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5488
 
5489
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5490
 
5491
    `ifdef HOST
5492
        repeat(4)
5493 26 mihad
            @(posedge pci_clock) ;
5494
        repeat(4)
5495 15 mihad
            @(posedge wb_clock) ;
5496
        if ( INT_O !== 1 )
5497
        begin
5498
            $display("Parity checker testing failed! Time %t ", $time) ;
5499
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5500
            test_fail("Interrupt Request was not triggered as expected") ;
5501
        end
5502
        else
5503
            test_ok ;
5504
    `else
5505
    `ifdef GUEST
5506 26 mihad
        repeat(4)
5507
            @(posedge wb_clock) ;
5508
        repeat(4)
5509 15 mihad
            @(posedge pci_clock) ;
5510
 
5511
        if ( INTA !== 1 )
5512
        begin
5513
            $display("Parity checker testing failed! Time %t ", $time) ;
5514
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5515
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5516
        end
5517
        else
5518
            test_ok ;
5519
    `endif
5520
    `endif
5521
 
5522
    // check statuses!
5523
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5524
    ok = 1 ;
5525
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5526
    if ( temp_val1[31] !== 1 )
5527
    begin
5528
        $display("Parity checker testing failed! Time %t ", $time) ;
5529
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5530
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5531
        ok = 0 ;
5532
    end
5533
 
5534
    if ( temp_val1[30] !== 1 )
5535
    begin
5536
        $display("Parity checker testing failed! Time %t ", $time) ;
5537
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5538
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5539
        ok = 0 ;
5540
    end
5541
 
5542
    if ( temp_val1[24] !== 0 )
5543
    begin
5544
        $display("Parity checker testing failed! Time %t ", $time) ;
5545
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5546
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5547
        ok = 0 ;
5548
    end
5549
 
5550
    if ( ok )
5551
        test_ok ;
5552
 
5553
    // clear statuses
5554
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5555
 
5556
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5557
 
5558
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5559
    ok = 1 ;
5560
 
5561
    `ifdef HOST
5562
    if ( temp_val1[4] !== 1 )
5563
    begin
5564
        $display("Parity checker testing failed! Time %t ", $time) ;
5565
        $display("System error interrupt status bit not set when expected!") ;
5566
        test_fail("System error interrupt status bit not set when expected") ;
5567
        ok = 0 ;
5568
    end
5569
    `else
5570
    if ( temp_val1[4] !== 0 )
5571
    begin
5572
        $display("Parity checker testing failed! Time %t ", $time) ;
5573
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5574
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5575
        ok = 0 ;
5576
    end
5577
    `endif
5578
 
5579
    if ( temp_val1[3] !== 0 )
5580
    begin
5581
        $display("Parity checker testing failed! Time %t ", $time) ;
5582
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5583
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5584
        ok = 0 ;
5585
    end
5586
 
5587
    if ( ok )
5588
        test_ok ;
5589
 
5590
    // clear statuses
5591
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5592
 
5593
    // now just disable Parity Error response - on Address par errors nothing should happen
5594
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5595
 
5596
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5597
    fork
5598
    begin
5599
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5600
               target_address, 32'h1234_5678,
5601
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5602
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5603
        do_pause( 1 ) ;
5604
    end
5605
    begin:wait_serr12
5606
        perr_asserted = 0 ;
5607
        @(posedge pci_clock) ;
5608
        while( SERR === 1 )
5609
            @(posedge pci_clock) ;
5610
 
5611
        perr_asserted = 1 ;
5612
        $display("Parity checker testing failed! Time %t ", $time) ;
5613
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5614
        test_fail("SERR asserted when parity error response was disabled") ;
5615
    end
5616
    begin
5617
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5618
        if ( ok !== 1 )
5619
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5620
 
5621 35 mihad
        @(posedge pci_clock) ;
5622
        #1 ;
5623
        if ( !perr_asserted )
5624
            disable wait_serr12 ;
5625 15 mihad
    end
5626
    join
5627
 
5628
    if ( ok && !perr_asserted )
5629
        test_ok ;
5630
 
5631
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5632
    `ifdef HOST
5633 26 mihad
        repeat (4)
5634
            @(posedge pci_clock) ;
5635 15 mihad
        repeat(4)
5636
            @(posedge wb_clock) ;
5637
        if ( INT_O !== 0 )
5638
        begin
5639
            $display("Parity checker testing failed! Time %t ", $time) ;
5640
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5641
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5642
        end
5643
        else
5644
            test_ok ;
5645
    `else
5646
    `ifdef GUEST
5647 26 mihad
        repeat(4)
5648
            @(posedge wb_clock) ;
5649
        repeat (4)
5650 15 mihad
            @(posedge pci_clock) ;
5651
 
5652
        if ( INTA !== 1 )
5653
        begin
5654
            $display("Parity checker testing failed! Time %t ", $time) ;
5655
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5656
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5657
        end
5658
        else
5659
            test_ok ;
5660
    `endif
5661
    `endif
5662
 
5663
    // check statuses!
5664
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5665
    ok = 1 ;
5666
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5667
    if ( temp_val1[31] !== 1 )
5668
    begin
5669
        $display("Parity checker testing failed! Time %t ", $time) ;
5670
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5671
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5672
        ok = 0 ;
5673
    end
5674
 
5675
    if ( temp_val1[30] !== 0 )
5676
    begin
5677
        $display("Parity checker testing failed! Time %t ", $time) ;
5678
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5679
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5680
        ok = 0 ;
5681
    end
5682
 
5683
    if ( temp_val1[24] !== 0 )
5684
    begin
5685
        $display("Parity checker testing failed! Time %t ", $time) ;
5686
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5687
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5688
        ok = 0 ;
5689
    end
5690
 
5691
    if ( ok )
5692
        test_ok ;
5693
 
5694
    // clear statuses
5695
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5696
 
5697
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5698
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5699
    ok = 1 ;
5700
    if ( temp_val1[4] !== 0 )
5701
    begin
5702
        $display("Parity checker testing failed! Time %t ", $time) ;
5703
        $display("System error interrupt status bit set when not expected!") ;
5704
        test_fail("System error interrupt status bit set when not expected") ;
5705
        ok = 0 ;
5706
    end
5707
 
5708
    if ( temp_val1[3] !== 0 )
5709
    begin
5710
        $display("Parity checker testing failed! Time %t ", $time) ;
5711
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5712
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5713
        ok = 0 ;
5714
    end
5715
 
5716
    if ( ok )
5717
        test_ok ;
5718
 
5719
    // clear statuses
5720
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5721
 
5722
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5723
    fork
5724
    begin
5725
        ipci_unsupported_commands_master.master_reference
5726
        (
5727
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5728
            32'h5555_5555,      // second part of address in dual address cycle
5729
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5730
            `BC_MEM_WRITE,      // normal command
5731
            4'h0,               // byte enables
5732
            32'h1234_5678,      // data
5733
            1'b1,               // make address parity error on first phase of dual address
5734
            1'b0,               // make address parity error on second phase of dual address
5735
            ok                  // result of operation
5736
        ) ;
5737 35 mihad
        if ( !perr_asserted )
5738
            disable wait_serr17 ;
5739 15 mihad
    end
5740
    begin:wait_serr17
5741
        perr_asserted = 0 ;
5742
        @(posedge pci_clock) ;
5743
        while( SERR === 1 )
5744
            @(posedge pci_clock) ;
5745
 
5746
        perr_asserted = 1 ;
5747
        $display("Parity checker testing failed! Time %t ", $time) ;
5748
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5749
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5750
    end
5751
    join
5752
 
5753
    if ( ok && !perr_asserted)
5754
        test_ok ;
5755
 
5756
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5757
    fork
5758
    begin
5759
        ipci_unsupported_commands_master.master_reference
5760
        (
5761
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5762
            32'h5555_5555,      // second part of address in dual address cycle
5763
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5764
            `BC_MEM_WRITE,      // normal command
5765
            4'h0,               // byte enables
5766
            32'h1234_5678,      // data
5767
            1'b0,               // make address parity error on first phase of dual address
5768
            1'b1,               // make address parity error on second phase of dual address
5769
            ok                  // result of operation
5770
        ) ;
5771 35 mihad
        if ( !perr_asserted )
5772
            disable wait_serr18 ;
5773 15 mihad
    end
5774
    begin:wait_serr18
5775
        perr_asserted = 0 ;
5776
        @(posedge pci_clock) ;
5777
        while( SERR === 1 )
5778
            @(posedge pci_clock) ;
5779
 
5780
        perr_asserted = 1 ;
5781
        $display("Parity checker testing failed! Time %t ", $time) ;
5782
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5783
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5784
    end
5785
    join
5786
 
5787
    if ( ok && !perr_asserted)
5788
        test_ok ;
5789
 
5790
    // check statuses!
5791
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5792
    ok = 1 ;
5793
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5794
    if ( temp_val1[31] !== 1 )
5795
    begin
5796
        $display("Parity checker testing failed! Time %t ", $time) ;
5797
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5798
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5799
        ok = 0 ;
5800
    end
5801
 
5802
    if ( temp_val1[30] !== 0 )
5803
    begin
5804
        $display("Parity checker testing failed! Time %t ", $time) ;
5805
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5806
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5807
        ok = 0 ;
5808
    end
5809
 
5810
    if ( temp_val1[24] !== 0 )
5811
    begin
5812
        $display("Parity checker testing failed! Time %t ", $time) ;
5813
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5814
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5815
        ok = 0 ;
5816
    end
5817
 
5818
    if ( ok )
5819
        test_ok ;
5820
 
5821
    // clear statuses
5822
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5823
 
5824
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5825
    fork
5826
    begin
5827
        ipci_unsupported_commands_master.master_reference
5828
        (
5829
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5830
            32'h5555_5555,      // second part of address in dual address cycle
5831
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5832
            `BC_MEM_WRITE,      // normal command
5833
            4'h0,               // byte enables
5834
            32'h1234_5678,      // data
5835
            1'b1,               // make address parity error on first phase of dual address
5836
            1'b1,               // make address parity error on second phase of dual address
5837
            ok                  // result of operation
5838
        ) ;
5839 35 mihad
        if ( !perr_asserted )
5840
            disable wait_serr19 ;
5841 15 mihad
    end
5842
    begin:wait_serr19
5843
        perr_asserted = 0 ;
5844
        @(posedge pci_clock) ;
5845
        while( SERR === 1 )
5846
            @(posedge pci_clock) ;
5847
 
5848
        perr_asserted = 1 ;
5849
        $display("Parity checker testing failed! Time %t ", $time) ;
5850
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5851
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5852
    end
5853
    join
5854
 
5855
    if ( ok && !perr_asserted)
5856
        test_ok ;
5857
 
5858
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5859
 
5860
    `ifdef HOST
5861
        repeat(4)
5862 26 mihad
            @(posedge pci_clock) ;
5863
        repeat(4)
5864 15 mihad
            @(posedge wb_clock) ;
5865
        if ( INT_O !== 0 )
5866
        begin
5867
            $display("Parity checker testing failed! Time %t ", $time) ;
5868
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5869
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5870
        end
5871
        else
5872
            test_ok ;
5873
    `else
5874
    `ifdef GUEST
5875 26 mihad
        repeat(4)
5876
            @(posedge wb_clock) ;
5877
        repeat(4)
5878 15 mihad
            @(posedge pci_clock) ;
5879
 
5880
        if ( INTA !== 1 )
5881
        begin
5882
            $display("Parity checker testing failed! Time %t ", $time) ;
5883
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5884
            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") ;
5885
        end
5886
        else
5887
            test_ok ;
5888
    `endif
5889
    `endif
5890
 
5891
    // check statuses!
5892
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5893
    ok = 1 ;
5894
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5895
    if ( temp_val1[31] !== 1 )
5896
    begin
5897
        $display("Parity checker testing failed! Time %t ", $time) ;
5898
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5899
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5900
        ok = 0 ;
5901
    end
5902
 
5903
    if ( temp_val1[30] !== 0 )
5904
    begin
5905
        $display("Parity checker testing failed! Time %t ", $time) ;
5906
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5907
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5908
        ok = 0 ;
5909
    end
5910
 
5911
    if ( temp_val1[24] !== 0 )
5912
    begin
5913
        $display("Parity checker testing failed! Time %t ", $time) ;
5914
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5915
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5916
        ok = 0 ;
5917
    end
5918
 
5919
    if ( ok )
5920
        test_ok ;
5921
 
5922
    // clear statuses
5923
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5924
 
5925
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5926
 
5927
    // do normal write
5928
    fork
5929
    begin
5930
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5931
               target_address, 32'h1234_5678, `Test_All_Bytes,
5932
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5933
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5934
        do_pause( 1 ) ;
5935
    end
5936
    begin:wait_serr13
5937
        perr_asserted = 0 ;
5938
        @(posedge pci_clock) ;
5939
        while( SERR === 1 )
5940
            @(posedge pci_clock) ;
5941
 
5942
        perr_asserted = 1 ;
5943
        $display("Parity checker testing failed! Time %t ", $time) ;
5944
        $display("SERR asserted for no reason!") ;
5945
        test_fail("SERR was asserted for no reason") ;
5946
    end
5947
    begin
5948
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5949
        if ( ok !== 1 )
5950
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5951
 
5952 35 mihad
        @(posedge pci_clock) ;
5953
        #1 ;
5954
        if ( !perr_asserted )
5955
            disable wait_serr13 ;
5956 15 mihad
    end
5957
    join
5958
 
5959
    if ( ok && !perr_asserted )
5960
        test_ok ;
5961
 
5962
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
5963
    `ifdef HOST
5964 26 mihad
        repeat( 4 )
5965
            @(posedge pci_clock) ;
5966 15 mihad
        repeat(4)
5967
            @(posedge wb_clock) ;
5968
        if ( INT_O !== 0 )
5969
        begin
5970
            $display("Parity checker testing failed! Time %t ", $time) ;
5971
            $display("Interrupt request asserted for no reason!") ;
5972
            test_fail("Interrupt request was asserted for no reason") ;
5973
        end
5974
        else
5975
            test_ok ;
5976
    `else
5977
    `ifdef GUEST
5978 26 mihad
        repeat(4)
5979
            @(posedge wb_clock) ;
5980
        repeat(4)
5981 15 mihad
            @(posedge pci_clock) ;
5982
 
5983
        if ( INTA !== 1 )
5984
        begin
5985
            $display("Parity checker testing failed! Time %t ", $time) ;
5986
            $display("Interrupt request asserted for no reason!") ;
5987
            test_fail("Interrupt request was asserted for no reason") ;
5988
        end
5989
        else
5990
            test_ok ;
5991
    `endif
5992
    `endif
5993
 
5994
    // check statuses!
5995
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
5996
    ok = 1 ;
5997
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5998
    if ( temp_val1[31] !== 0 )
5999
    begin
6000
        $display("Parity checker testing failed! Time %t ", $time) ;
6001
        $display("Detected Parity Error bit was set for no reason!") ;
6002
        test_fail("Detected Parity Error bit was set for no reason") ;
6003
        ok = 0 ;
6004
    end
6005
 
6006
    if ( temp_val1[30] !== 0 )
6007
    begin
6008
        $display("Parity checker testing failed! Time %t ", $time) ;
6009
        $display("Signalled System Error bit was set for no reason!") ;
6010
        test_fail("Signalled System Error bit was set for no reason") ;
6011
        ok = 0 ;
6012
    end
6013
 
6014
    if ( temp_val1[24] !== 0 )
6015
    begin
6016
        $display("Parity checker testing failed! Time %t ", $time) ;
6017
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6018
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6019
        ok = 0 ;
6020
    end
6021
 
6022
    if ( ok )
6023
        test_ok ;
6024
 
6025
    // clear statuses
6026
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6027
 
6028
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6029
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6030
    ok = 1 ;
6031
 
6032
    if ( temp_val1[4] !== 0 )
6033
    begin
6034
        $display("Parity checker testing failed! Time %t ", $time) ;
6035
        $display("System error interrupt status bit set when not expected!") ;
6036
        test_fail("System error interrupt status bit set when not expected") ;
6037
        ok = 0 ;
6038
    end
6039
 
6040
    if ( temp_val1[3] !== 0 )
6041
    begin
6042
        $display("Parity checker testing failed! Time %t ", $time) ;
6043
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6044
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6045
        ok = 0 ;
6046
    end
6047
 
6048
    if ( ok )
6049
        test_ok ;
6050
 
6051
    // clear statuses
6052
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6053
 
6054
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6055
 
6056
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6057
 
6058
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6059
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6060
 
6061
    // setup target's image!
6062
    target_address  = Target_Base_Addr_R[1] ;
6063
 
6064
    // base address
6065
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6066
 
6067
    // address mask
6068
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6069
 
6070
    // image control
6071
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6072
 
6073
    // enable everything possible for parity checking
6074
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6075
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6076
 
6077
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6078
 
6079
    fork
6080
    begin
6081
        if ( target_mem_image === 1 )
6082
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6083
                   target_address, 32'h1234_5678,
6084
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6085
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6086
        else
6087
            PCIU_IO_WRITE_MAKE_PERR (
6088
                                    `Test_Master_1,
6089
                                    target_address,
6090
                                    32'h1234_5678,
6091
                                    4'h0,
6092
                                    1,
6093
                                    `Test_Target_Normal_Completion
6094
                                    );
6095
 
6096
        do_pause( 1 ) ;
6097
    end
6098
    begin:wait_perr11
6099
        perr_asserted = 0 ;
6100
        @(posedge pci_clock) ;
6101 35 mihad
        while ( PERR !== 0 )
6102 15 mihad
            @(posedge pci_clock) ;
6103
 
6104 35 mihad
        perr_asserted = 1 ;
6105 15 mihad
 
6106
    end
6107
    begin
6108
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6109
 
6110
        if ( ok !== 1 )
6111
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6112
 
6113
        repeat(2)
6114
            @(posedge pci_clock) ;
6115
 
6116 35 mihad
        #1 ;
6117
        if ( !perr_asserted )
6118
            disable wait_perr11 ;
6119 15 mihad
    end
6120
    join
6121
 
6122
    if ( ok && perr_asserted )
6123
        test_ok ;
6124
    else
6125
    if ( !perr_asserted )
6126
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6127
 
6128
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6129
    `ifdef HOST
6130 26 mihad
        repeat (4)
6131
            @(posedge pci_clock) ;
6132 15 mihad
        repeat(4)
6133
            @(posedge wb_clock) ;
6134
        if ( INT_O !== 0 )
6135
        begin
6136
            $display("Parity checker testing failed! Time %t ", $time) ;
6137
            $display("Interrupt request asserted for no reason!") ;
6138
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6139
        end
6140
        else
6141
            test_ok ;
6142
    `else
6143
    `ifdef GUEST
6144 26 mihad
        repeat(4)
6145
            @(posedge wb_clock) ;
6146
        repeat (4)
6147 15 mihad
            @(posedge pci_clock) ;
6148
 
6149
        if ( INTA !== 1 )
6150
        begin
6151
            $display("Parity checker testing failed! Time %t ", $time) ;
6152
            $display("Interrupt request asserted for no reason!") ;
6153
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6154
        end
6155
        else
6156
            test_ok ;
6157
 
6158
    `endif
6159
    `endif
6160
 
6161
    // check statuses!
6162
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6163
    ok = 1 ;
6164
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6165
    if ( temp_val1[31] !== 1 )
6166
    begin
6167
        $display("Parity checker testing failed! Time %t ", $time) ;
6168 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6169
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6170 15 mihad
        ok = 0 ;
6171
    end
6172
 
6173
    if ( temp_val1[30] !== 0 )
6174
    begin
6175
        $display("Parity checker testing failed! Time %t ", $time) ;
6176
        $display("Signalled System Error bit was set for no reason!") ;
6177
        test_fail("Signalled System Error bit was set for no reason") ;
6178
        ok = 0 ;
6179
    end
6180
 
6181
    if ( temp_val1[24] !== 0 )
6182
    begin
6183
        $display("Parity checker testing failed! Time %t ", $time) ;
6184
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6185
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6186
        ok = 0 ;
6187
    end
6188
 
6189
    if ( ok )
6190
        test_ok ;
6191
 
6192
    // clear statuses
6193
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6194
 
6195
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6196
 
6197
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6198
    ok = 1 ;
6199
    if ( temp_val1[4] !== 0 )
6200
    begin
6201
        $display("Parity checker testing failed! Time %t ", $time) ;
6202
        $display("System error interrupt status bit set when not expected!") ;
6203
        test_fail("System error interrupt status bit set when not expected") ;
6204
        ok = 0 ;
6205
    end
6206
 
6207
    if ( temp_val1[3] !== 0 )
6208
    begin
6209
        $display("Parity checker testing failed! Time %t ", $time) ;
6210
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6211
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6212
        ok = 0 ;
6213
    end
6214
 
6215
    if ( ok )
6216
        test_ok ;
6217
 
6218
    // clear statuses
6219
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6220
 
6221
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6222
 
6223
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6224
    fork
6225
    begin
6226
        if ( target_mem_image === 1 )
6227
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6228
                          target_address, 32'h1234_5678,
6229
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6230
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6231
        else
6232
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6233
 
6234
        do_pause( 1 ) ;
6235
    end
6236
    begin:wait_perr12
6237
        perr_asserted = 0 ;
6238
        @(posedge pci_clock) ;
6239 35 mihad
        while ( PERR !== 0 )
6240 15 mihad
            @(posedge pci_clock) ;
6241
 
6242 35 mihad
        perr_asserted = 1 ;
6243 15 mihad
    end
6244
    begin
6245
 
6246
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6247
        if ( ok !== 1 )
6248
        begin
6249
            test_fail("Bridge failed to process Target Memory read correctly") ;
6250
            disable main ;
6251
        end
6252
 
6253
        repeat(3)
6254
            @(posedge pci_clock) ;
6255
 
6256
        if ( target_mem_image === 1 )
6257
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6258
                    target_address, 32'h1234_5678,
6259
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6260
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6261
        else
6262
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6263
 
6264
        do_pause( 1 ) ;
6265
 
6266
    end
6267
    begin
6268
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6269
        if ( ok !== 1 )
6270
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6271
        else
6272
        begin
6273
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6274
            if ( ok !== 1 )
6275
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6276
        end
6277
 
6278 35 mihad
        repeat(2)
6279 15 mihad
            @(posedge pci_clock) ;
6280
 
6281 35 mihad
        #1 ;
6282
        if ( !perr_asserted )
6283
            disable wait_perr12 ;
6284 15 mihad
    end
6285
    join
6286
 
6287
    if ( ok && perr_asserted )
6288
        test_ok ;
6289
    else
6290
    if ( !perr_asserted )
6291
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6292
 
6293
 
6294
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6295
    `ifdef HOST
6296
        repeat(4)
6297 26 mihad
            @(posedge pci_clock) ;
6298
        repeat(4)
6299 15 mihad
            @(posedge wb_clock) ;
6300
        if ( INT_O !== 0 )
6301
        begin
6302
            $display("Parity checker testing failed! Time %t ", $time) ;
6303
            $display("Interrupt request asserted for no reason!") ;
6304
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6305
        end
6306
        else
6307
            test_ok ;
6308
    `else
6309
    `ifdef GUEST
6310 26 mihad
        repeat(4)
6311
            @(posedge wb_clock) ;
6312
        repeat(4)
6313 15 mihad
            @(posedge pci_clock) ;
6314
 
6315
        if ( INTA !== 1 )
6316
        begin
6317
            $display("Parity checker testing failed! Time %t ", $time) ;
6318
            $display("Interrupt request asserted for no reason!") ;
6319
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6320
        end
6321
        else
6322
            test_ok ;
6323
    `endif
6324
    `endif
6325
 
6326
    // check statuses!
6327
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6328
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6329
    ok = 1 ;
6330 45 mihad
    if ( temp_val1[31] !== 0 )
6331 15 mihad
    begin
6332
        $display("Parity checker testing failed! Time %t ", $time) ;
6333 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6334
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6335 15 mihad
        ok = 0 ;
6336
    end
6337
 
6338
    if ( temp_val1[30] !== 0 )
6339
    begin
6340
        $display("Parity checker testing failed! Time %t ", $time) ;
6341
        $display("Signalled System Error bit was set for no reason!") ;
6342
        test_fail("Signalled System Error bit was set for no reason") ;
6343
        ok = 0 ;
6344
    end
6345
 
6346
    if ( temp_val1[24] !== 0 )
6347
    begin
6348
        $display("Parity checker testing failed! Time %t ", $time) ;
6349
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6350
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6351
        ok = 0 ;
6352
    end
6353
 
6354
    if ( ok )
6355
        test_ok ;
6356
 
6357
    // clear statuses
6358
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6359
 
6360
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6361
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6362
    ok = 1 ;
6363
    if ( temp_val1[4] !== 0 )
6364
    begin
6365
        $display("Parity checker testing failed! Time %t ", $time) ;
6366
        $display("System error interrupt status bit set when not expected!") ;
6367
        test_fail("System error interrupt status bit set when not expected") ;
6368
        ok = 0 ;
6369
    end
6370
 
6371
    if ( temp_val1[3] !== 0 )
6372
    begin
6373
        $display("Parity checker testing failed! Time %t ", $time) ;
6374
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6375
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6376
        ok = 0 ;
6377
    end
6378
 
6379
    if ( ok )
6380
        test_ok ;
6381
    // clear statuses
6382
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6383
 
6384
    $fdisplay(pci_mon_log_file_desc,
6385
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6386
    test_name = "DISABLE USED IMAGES" ;
6387
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6388
    if ( ok !== 1 )
6389
    begin
6390
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6391
        test_fail("WB Image Address Mask register could not be written to") ;
6392
        disable main ;
6393
    end
6394
 
6395 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6396 15 mihad
    if ( ok !== 1 )
6397
    begin
6398
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6399
        test_fail("PCI Image Address Mask register could not be written to") ;
6400
        disable main ;
6401
    end
6402
 
6403
    // disable target's 1 response to parity errors
6404 45 mihad
    configuration_cycle_write(0,                        // bus number
6405
                              `TAR1_IDSEL_INDEX - 11,   // device number
6406
                              0,                        // function number
6407
                              1,                        // register number
6408
                              0,                        // type of configuration cycle
6409
                              4'b0001,                  // byte enables
6410
                              32'h0000_0007             // data
6411 15 mihad
                             ) ;
6412
 
6413
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6414
end
6415
endtask // parity_checking
6416
 
6417
task wb_to_pci_transactions ;
6418
    reg   [11:0] ctrl_offset ;
6419
    reg   [11:0] ba_offset ;
6420
    reg   [11:0] am_offset ;
6421
    reg   [11:0] pci_ctrl_offset ;
6422
    reg   [11:0] err_cs_offset ;
6423
    reg   [11:0] icr_offset ;
6424
    reg   [11:0] isr_offset ;
6425
    reg   [11:0] lat_tim_cls_offset ;
6426
 
6427
    reg `WRITE_STIM_TYPE  write_data ;
6428
    reg `READ_STIM_TYPE   read_data ;
6429
    reg `READ_RETURN_TYPE read_status ;
6430
 
6431
    reg `WRITE_RETURN_TYPE write_status ;
6432
    reg `WB_TRANSFER_FLAGS write_flags ;
6433
    reg [31:0] temp_val1 ;
6434
    reg [31:0] temp_val2 ;
6435
    reg        ok   ;
6436
 
6437
    reg [31:0] image_base ;
6438
    reg [31:0] target_address ;
6439
    integer i ;
6440
    integer required_reads ;
6441
    integer writes_left ;
6442
 
6443
begin:main
6444
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6445
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6446
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6447
    pci_ctrl_offset    = 12'h4 ;
6448
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6449
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6450
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6451
    lat_tim_cls_offset = 12'hC ;
6452
 
6453
    $display("Checking WB to PCI transaction lengths!") ;
6454
    target_address  = `BEH_TAR1_MEM_START ;
6455
    image_base      = 0 ;
6456
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6457
 
6458
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6459
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6460
    write_flags                    = 0 ;
6461
    write_flags`INIT_WAITS         = tb_init_waits ;
6462
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6463
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6464
 
6465
    // enable master & target operation
6466
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6467
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6468
    if ( ok !== 1 )
6469
    begin
6470
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6471
        test_fail("write to PCI Device Control register failed") ;
6472
        disable main ;
6473
    end
6474
 
6475
    // prepare image control register
6476
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6477
    if ( ok !== 1 )
6478
    begin
6479
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6480
        test_fail("write to WB Image Control register failed") ;
6481
        disable main ;
6482
    end
6483
 
6484
    // prepare base address register
6485
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6486
    if ( ok !== 1 )
6487
    begin
6488
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6489
        test_fail("write to WB Base Address register failed") ;
6490
        disable main ;
6491
    end
6492
 
6493
    // write address mask register
6494
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6495
    if ( ok !== 1 )
6496
    begin
6497
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6498
        test_fail("write to WB Address Mask register failed") ;
6499
        disable main ;
6500
    end
6501
 
6502
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6503
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6504
    if ( ok !== 1 )
6505
    begin
6506
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6507
        test_fail("write to WB Error Control and Status register failed") ;
6508
        disable main ;
6509
    end
6510
 
6511
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6512
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6513
    if ( ok !== 1 )
6514
    begin
6515
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6516
        test_fail("write to Interrupt Control register failed") ;
6517
        disable main ;
6518
    end
6519
 
6520
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6521
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6522
    if ( ok !== 1 )
6523
    begin
6524
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6525
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6526
        disable main ;
6527
    end
6528
 
6529
    $display("Testing single write transaction progress from WB to PCI!") ;
6530
    write_data`WRITE_ADDRESS = target_address ;
6531
    write_data`WRITE_DATA    = wmem_data[0] ;
6532
    write_data`WRITE_SEL     = 4'hF ;
6533
 
6534
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6535
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6536
 
6537
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6538
    fork
6539
    begin
6540
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6541
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6542
        begin
6543
            $display("Transaction progress testing failed! Time %t ", $time) ;
6544
            $display("Bridge failed to process single memory write!") ;
6545
            test_fail("bridge failed to post single memory write") ;
6546
            disable main ;
6547
        end
6548
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6549
    end
6550
    begin
6551
        // wait two retries, then enable target response
6552
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6553
        if ( ok !== 1 )
6554
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6555
        else
6556
            test_ok ;
6557
 
6558
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6559
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6560
        if ( ok !== 1 )
6561
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6562
        else
6563
            test_ok ;
6564
 
6565
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6566
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6567
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6568
 
6569
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6570
        if ( ok !== 1 )
6571
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6572
        else
6573
            test_ok ;
6574
    end
6575
    join
6576
 
6577
    $display("Testing burst write transaction progress from WB to PCI!") ;
6578
    write_data`WRITE_ADDRESS = target_address ;
6579
    write_data`WRITE_DATA    = wmem_data[0] ;
6580
    write_data`WRITE_SEL     = 4'hF ;
6581
 
6582
    wishbone_master.blk_write_data[0] = write_data ;
6583
 
6584
    write_data`WRITE_ADDRESS = target_address + 4 ;
6585
    write_data`WRITE_DATA    = wmem_data[1] ;
6586
    write_data`WRITE_SEL     = 4'hF ;
6587
 
6588
    wishbone_master.blk_write_data[1] = write_data ;
6589
 
6590
    write_flags`WB_TRANSFER_SIZE = 2 ;
6591
    write_flags`WB_TRANSFER_CAB  = 1 ;
6592
 
6593
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6594
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6595
 
6596
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6597
 
6598
    fork
6599
    begin
6600
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6601
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6602
        begin
6603
            $display("Transaction progress testing failed! Time %t ", $time) ;
6604
            $display("Bridge failed to process whole CAB memory write!") ;
6605
            test_fail("bridge failed to post whole CAB memory write") ;
6606
            disable main ;
6607
        end
6608
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6609
    end
6610
    begin
6611
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6612
        if ( ok !== 1 )
6613
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6614
        else
6615
            test_ok ;
6616
 
6617
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6618
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6619
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6620
 
6621
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6622
        if ( ok !== 1 )
6623
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6624
        else
6625
            test_ok ;
6626
 
6627
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6628
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6629
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6630
 
6631
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6632
        if ( ok !== 1 )
6633
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6634
        else
6635
            test_ok ;
6636
    end
6637
    join
6638
 
6639
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6640
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6641
 
6642
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6643
    // try same write with other terminations
6644
    fork
6645
    begin
6646
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6647
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6648
        begin
6649
            $display("Transaction progress testing failed! Time %t ", $time) ;
6650
            $display("Bridge failed to process whole CAB memory write!") ;
6651
            test_fail("bridge failed to post whole CAB memory write") ;
6652
            disable main ;
6653
        end
6654
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6655
    end
6656
    begin
6657
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6658
        if ( ok !== 1 )
6659
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6660
        else
6661
            test_ok ;
6662
 
6663
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6664
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6665
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6666
 
6667
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6668
        if ( ok !== 1 )
6669
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6670
        else
6671
            test_ok ;
6672
    end
6673
    join
6674
 
6675
    // repeat the write with normal completion
6676
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6677
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6678
 
6679
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6680
    fork
6681
    begin
6682
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6683
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6684
        begin
6685
            $display("Transaction progress testing failed! Time %t ", $time) ;
6686
            $display("Bridge failed to process whole CAB memory write!") ;
6687
            test_fail("bridge failed to post whole CAB memory write") ;
6688
            disable main ;
6689
        end
6690
    end
6691
    begin
6692
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6693
        if ( ok !== 1 )
6694
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6695
        else
6696
            test_ok ;
6697
    end
6698
    join
6699
 
6700
    // do the same thing with burst length of 3
6701
    write_data`WRITE_ADDRESS = target_address + 8 ;
6702
    write_data`WRITE_DATA    = wmem_data[2] ;
6703
    write_data`WRITE_SEL     = 4'hF ;
6704
 
6705
    wishbone_master.blk_write_data[2] = write_data ;
6706
 
6707
    write_flags`WB_TRANSFER_SIZE = 3 ;
6708
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6709
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6710
 
6711
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6712
 
6713
    fork
6714
    begin
6715
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6716
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6717
        begin
6718
            $display("Transaction progress testing failed! Time %t ", $time) ;
6719
            $display("Bridge failed to process whole CAB memory write!") ;
6720
            test_fail("bridge failed to post whole CAB memory write") ;
6721
            disable main ;
6722
        end
6723
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6724
    end
6725
    begin
6726
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6727
        if ( ok !== 1 )
6728
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6729
        else
6730
            test_ok ;
6731
 
6732
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6733
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6734
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6735
 
6736
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6737
        if ( ok !== 1 )
6738
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6739
        else
6740
            test_ok ;
6741
    end
6742
    join
6743
 
6744
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6745
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6746
 
6747
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6748
    fork
6749
    begin
6750
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6751
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6752
        begin
6753
            $display("Transaction progress testing failed! Time %t ", $time) ;
6754
            $display("Bridge failed to process whole CAB memory write!") ;
6755
            test_fail("bridge failed to post whole CAB memory write") ;
6756
            disable main ;
6757
        end
6758
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6759
    end
6760
    begin
6761
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6762
        if ( ok !== 1 )
6763
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6764
        else
6765
            test_ok ;
6766
 
6767
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6768
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6769
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6770
 
6771
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6772
        if ( ok !== 1 )
6773
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6774
        else
6775
            test_ok ;
6776
 
6777
    end
6778
    join
6779
 
6780
    // repeat with normal completion
6781
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6782
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6783
 
6784
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6785
    fork
6786
    begin
6787
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6788
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6789
        begin
6790
            $display("Transaction progress testing failed! Time %t ", $time) ;
6791
            $display("Bridge failed to process whole CAB memory write!") ;
6792
            test_fail("bridge failed to post whole CAB memory write") ;
6793
            disable main ;
6794
        end
6795
    end
6796
    begin
6797
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6798
        if ( ok !== 1 )
6799
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6800
        else
6801
            test_ok ;
6802
 
6803
    end
6804
    join
6805
 
6806
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6807
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6808
    begin
6809
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6810
        write_data`WRITE_DATA    = wmem_data[i] ;
6811
        write_data`WRITE_SEL     = 4'hF ;
6812
 
6813
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6814
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6815
 
6816
        wishbone_master.blk_write_data[i]   = write_data ;
6817
        wishbone_master.blk_read_data_in[i] = read_data ;
6818
    end
6819
 
6820
    write_flags`WB_TRANSFER_CAB      = 1 ;
6821
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6822
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6823
 
6824
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6825
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6826
 
6827
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6828
    fork
6829
    begin
6830
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6831
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6832
        begin
6833
            $display("Transaction progress testing failed! Time %t ", $time) ;
6834
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6835
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6836
            test_fail("bridge failed to post whole CAB memory write") ;
6837
            disable main ;
6838
        end
6839
 
6840
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6841
 
6842
        // read here just checks if data was transfered OK
6843
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6844
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6845
 
6846
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6847
 
6848
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6849
        begin
6850
            $display("Transaction progress testing failed! Time %t ", $time) ;
6851
            $display("Bridge processed CAB read wrong!") ;
6852
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6853
        end
6854
 
6855
    end
6856
    begin
6857
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6858
        if ( ok !== 1 )
6859
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6860
        else
6861
            test_ok ;
6862
 
6863
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6864
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6865
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6866
 
6867
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6868
        if ( ok !== 1 )
6869
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6870
        else
6871
            test_ok ;
6872
 
6873
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6874
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6875
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6876
 
6877
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6878
        if ( ok !== 1 )
6879
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6880
        else
6881
            test_ok ;
6882
 
6883
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6884
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6885
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6886
 
6887
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6888
        if ( ok !== 1 )
6889
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6890
        else
6891
            test_ok ;
6892
 
6893
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6894
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6895
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6896
 
6897
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6898
        if ( ok !== 1 )
6899
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6900
        else
6901
            test_ok ;
6902
 
6903
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6904
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6905
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6906
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6907
        begin
6908
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6909
            if ( ok !== 1 )
6910
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6911
        end
6912
    end
6913
    join
6914
 
6915
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6916
    begin
6917
        read_status = wishbone_master.blk_read_data_out[i] ;
6918
        if (read_status`READ_DATA !== wmem_data[i])
6919
        begin
6920
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6921
            test_fail("data read from target wasn't the same as data written to it") ;
6922
            ok = 0 ;
6923
        end
6924
    end
6925
 
6926
    if ( ok )
6927
        test_ok ;
6928
 
6929
    $display("Testing single read transaction progress from WB to PCI!") ;
6930
    read_data`READ_ADDRESS = target_address + 8 ;
6931
    read_data`READ_SEL     = 4'hF ;
6932
 
6933
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6934
 
6935
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6936
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6937
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6938
 
6939
    fork
6940
    begin
6941
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6942
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6943
        begin
6944
            $display("Transaction progress testing failed! Time %t ", $time) ;
6945
            $display("Bridge processed single read wrong!") ;
6946
            test_fail("bridge processed single read wrong") ;
6947
            disable main ;
6948
        end
6949
 
6950
        if (read_status`READ_DATA !== wmem_data[2])
6951
        begin
6952
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6953
            test_fail("data returned from single read was not as expected") ;
6954
        end
6955
        else
6956
        if ( ok )
6957
            test_ok ;
6958
    end
6959
    begin
6960
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
6961
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6962
 
6963
        if ( ok !== 1 )
6964
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6965
 
6966
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
6967
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6968
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6969
 
6970
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6971
        if ( ok !== 1 )
6972
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6973
    end
6974
    join
6975
 
6976
    $display("Testing CAB read transaction progress from WB to PCI!") ;
6977
 
6978
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6979
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6980
 
6981
    test_name = "FILL TARGET MEMORY WITH DATA" ;
6982
    // first fill target's memory with enough data to fill WBR_FIFO
6983
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
6984
    begin
6985
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6986
        write_data`WRITE_DATA    = wmem_data[i] ;
6987
        write_data`WRITE_SEL     = 4'hF ;
6988
 
6989
        wishbone_master.blk_write_data[i] = write_data ;
6990
    end
6991
 
6992
    write_flags`WB_TRANSFER_CAB = 1 ;
6993
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6994
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
6995
 
6996
    wishbone_master.wb_block_write( write_flags, write_status ) ;
6997
 
6998
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
6999
    begin
7000
        $display("Transaction progress testing failed! Time %t ", $time) ;
7001
        $display("Bridge processed CAB write wrong!") ;
7002
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7003
        disable main ;
7004
    end
7005
 
7006
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7007
    // perform single read to force write data to pci
7008
    read_data`READ_ADDRESS = target_address + 8;
7009
    read_data`READ_SEL     = 4'hF ;
7010
 
7011
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7012
 
7013
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7014
    begin
7015
        $display("Transaction progress testing failed! Time %t ", $time) ;
7016
        $display("Bridge processed single read wrong!") ;
7017
        test_fail("bridge didn't process single memory read as expected") ;
7018
        disable main ;
7019
    end
7020
 
7021
    wishbone_master.blk_read_data_in[0] = read_data ;
7022
 
7023
    read_data`READ_ADDRESS = target_address + 12 ;
7024
    read_data`READ_SEL     = 4'hF ;
7025
 
7026
    wishbone_master.blk_read_data_in[1] = read_data ;
7027
 
7028
    read_data`READ_ADDRESS = target_address + 16 ;
7029
    read_data`READ_SEL     = 4'hF ;
7030
 
7031
    wishbone_master.blk_read_data_in[2] = read_data ;
7032
 
7033
    write_flags`WB_TRANSFER_CAB  = 1 ;
7034
    write_flags`WB_TRANSFER_SIZE = 2 ;
7035
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7036
    read_status = 0 ;
7037
 
7038
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7039
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7040
 
7041
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7042
 
7043
    ok = 1 ;
7044
    fork
7045
    begin
7046
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7047
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7048
 
7049
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7050
        begin
7051
            $display("Transaction progress testing failed! Time %t ", $time) ;
7052
            $display("Bridge processed CAB read wrong!") ;
7053
            test_fail("bridge didn't process disconnected burst read as expected") ;
7054
        end
7055
        else
7056
        begin
7057
 
7058
            read_status = wishbone_master.blk_read_data_out[0] ;
7059
 
7060
            if (read_status`READ_DATA !== wmem_data[2])
7061
            begin
7062
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7063
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7064
            end
7065
            else
7066
                test_ok ;
7067
        end
7068
 
7069
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7070
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7071
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7072
 
7073
        read_status = 0 ;
7074
 
7075
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7076
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7077
 
7078
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7079
        begin
7080
            $display("Transaction progress testing failed! Time %t ", $time) ;
7081
            $display("Bridge processed CAB read wrong!") ;
7082
            test_fail("bridge didn't process disconnected burst read as expected") ;
7083
        end
7084
        else
7085
        begin
7086
 
7087
            read_status = wishbone_master.blk_read_data_out[0] ;
7088
 
7089
            if (read_status`READ_DATA !== wmem_data[3])
7090
            begin
7091
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7092
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7093
            end
7094
            else
7095
                test_ok ;
7096
        end
7097
 
7098
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7099
        // complete delayed read which was requested
7100
        read_data = wishbone_master.blk_read_data_in[2] ;
7101
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7102
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7103
 
7104
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7105
        begin
7106
            $display("Transaction progress testing failed! Time %t ", $time) ;
7107
            $display("Bridge processed single out of burst read wrong!") ;
7108
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7109
        end
7110
        else
7111
        begin
7112
 
7113
            if (read_status`READ_DATA !== wmem_data[4])
7114
            begin
7115
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7116
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7117
            end
7118
            else
7119
                test_ok ;
7120
        end
7121
 
7122
    end
7123
    begin
7124
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7125
 
7126
        if ( ok !== 1 )
7127
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7128
 
7129
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7130
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7131
 
7132
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7133
        if ( ok !== 1 )
7134
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7135
 
7136
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7137
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7138
 
7139
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7140
        if ( ok !== 1 )
7141
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7142
    end
7143
    join
7144
 
7145
    // now try burst read with normal termination
7146
    read_data`READ_ADDRESS = target_address + 12 ;
7147
    read_data`READ_SEL     = 4'hF ;
7148
 
7149
    wishbone_master.blk_read_data_in[0] = read_data ;
7150
 
7151
    read_data`READ_ADDRESS = target_address + 16 ;
7152
    read_data`READ_SEL     = 4'hF ;
7153
 
7154
    wishbone_master.blk_read_data_in[1] = read_data ;
7155
 
7156
    write_flags`WB_TRANSFER_SIZE = 2 ;
7157
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7158
    write_flags`WB_TRANSFER_CAB = 1 ;
7159
 
7160
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7161
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7162
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7163
 
7164
    fork
7165
    begin
7166
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7167
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7168
        begin
7169
            $display("Transaction progress testing failed! Time %t ", $time) ;
7170
            $display("Bridge processed CAB read wrong!") ;
7171
            test_fail("bridge didn't process burst read as expected") ;
7172
            ok = 0 ;
7173
        end
7174
    end
7175
    begin
7176
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7177
        if ( ok !== 1 )
7178
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7179
    end
7180
    join
7181
 
7182
    if ( ok )
7183
    begin
7184
        read_status = wishbone_master.blk_read_data_out[0] ;
7185
        if ( read_status`READ_DATA !== wmem_data[3] )
7186
        begin
7187
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7188
            test_fail("data provided from normaly terminated read was wrong") ;
7189
            ok = 0 ;
7190
        end
7191
 
7192
        read_status = wishbone_master.blk_read_data_out[1] ;
7193
        if ( read_status`READ_DATA !== wmem_data[4] )
7194
        begin
7195
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7196
            test_fail("data provided from normaly terminated read was wrong") ;
7197
            ok = 0 ;
7198
        end
7199
    end
7200
 
7201
    if ( ok )
7202
        test_ok ;
7203
 
7204
    // disable memory read line command and enable prefetch
7205
    // prepare image control register
7206
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7207
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7208
    if ( ok !== 1 )
7209
    begin
7210
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7211
        test_fail("WB Image Control register couldn't be written to") ;
7212
        disable main ;
7213
    end
7214
 
7215
    write_flags`WB_TRANSFER_SIZE = 4 ;
7216
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7217
    write_flags`WB_TRANSFER_CAB = 1 ;
7218
 
7219
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7220
 
7221
    for ( i = 0 ; i < 4 ; i = i + 1 )
7222
    begin
7223
        read_data`READ_ADDRESS = target_address + i*4 ;
7224
        read_data`READ_SEL     = 4'b1010 ;
7225
 
7226
        wishbone_master.blk_read_data_in[i] = read_data ;
7227
    end
7228
 
7229
    fork
7230
    begin
7231
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7232
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7233
        begin
7234
            $display("Transaction progress testing failed! Time %t ", $time) ;
7235
            $display("Bridge processed CAB read wrong!") ;
7236
            test_fail("bridge didn't process prefetched burst read as expected") ;
7237
            ok = 0 ;
7238
        end
7239
    end
7240
    begin
7241
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7242
        if ( ok !== 1 )
7243
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7244
    end
7245
    join
7246
 
7247
    if ( ok )
7248
    begin
7249
        for ( i = 0 ; i < 4 ; i = i + 1 )
7250
        begin
7251
            read_status = wishbone_master.blk_read_data_out[i] ;
7252
            if ( read_status`READ_DATA !== wmem_data[i] )
7253
            begin
7254
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7255
                test_fail("burst read returned unexpected data") ;
7256
                ok = 0 ;
7257
            end
7258
        end
7259
    end
7260
 
7261
    if ( ok )
7262
        test_ok ;
7263
 
7264
    // do one single read with different byte enables
7265
    read_data`READ_ADDRESS = target_address + 4 ;
7266
    read_data`READ_SEL     = 4'b1010 ;
7267
 
7268
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7269
    fork
7270
    begin
7271
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7272
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7273
        begin
7274
            $display("Transaction progress testing failed! Time %t ", $time) ;
7275
            $display("Bridge processed single read wrong!") ;
7276
            test_fail("bridge didn't process single memory read as expected") ;
7277
            ok = 0 ;
7278
        end
7279
    end
7280
    begin
7281
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7282
        if ( ok !== 1 )
7283
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7284
    end
7285
    join
7286
 
7287
    // check read data
7288
    if ( ok )
7289
    begin
7290
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7291
        begin
7292
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7293
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7294
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7295
            ok = 0 ;
7296
            test_fail("unexpected data received from single read") ;
7297
        end
7298
    end
7299
 
7300
    if ( ok )
7301
         test_ok ;
7302
 
7303
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7304
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7305
 
7306
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7307
    if ( ok !== 1 )
7308
    begin
7309
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7310
        test_fail("WB Image Control register could not be written") ;
7311
        disable main ;
7312
    end
7313
 
7314
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7315
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7316
    begin
7317
        read_data`READ_ADDRESS = target_address + i*4 ;
7318
        read_data`READ_SEL     = 4'b1111 ;
7319
 
7320
        wishbone_master.blk_read_data_in[i] = read_data ;
7321
    end
7322
 
7323
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7324
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7325
    write_flags`WB_TRANSFER_CAB = 1 ;
7326
 
7327
    fork
7328
    begin
7329
        read_status         = 0 ;
7330
        read_status`CYC_RTY = 1 ;
7331
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7332
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7333
 
7334
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7335
        begin
7336
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7337
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7338
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7339
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7340
            ok = 0 ;
7341
        end
7342
    end
7343
    begin
7344
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7345
        if ( ok !== 1 )
7346
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7347
    end
7348
    join
7349
 
7350
    // now repeat single read to flush redundant read initiated
7351
    write_flags`WB_TRANSFER_SIZE = 1 ;
7352
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7353
    write_flags`WB_TRANSFER_CAB = 1 ;
7354
 
7355
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7356
    read_data`READ_SEL     = 4'hF ;
7357
 
7358
    wishbone_master.blk_read_data_in[0] = read_data ;
7359
 
7360
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7361
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7362
 
7363
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7364
    begin
7365
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7366
        $display(" PCI bridge failed to process single CAB read!") ;
7367
        test_fail("single CAB write was not processed as expected") ;
7368
    end
7369
 
7370
    // because last read could be very long on PCI - delete target abort status
7371
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7372
 
7373
    // write unsupported value to cache line size register
7374
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7375
 
7376
    read_data`READ_ADDRESS = target_address ;
7377
    read_data`READ_SEL     = 4'hF ;
7378
    wishbone_master.blk_read_data_in[0] = read_data ;
7379
 
7380
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7381
    // perform a read
7382
    fork
7383
    begin
7384
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7385
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7386
        begin
7387
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7388
            $display(" PCI bridge failed to process single CAB read!") ;
7389
            test_fail("burst read was not processed as expected") ;
7390
            ok = 0 ;
7391
        end
7392
    end
7393
    begin
7394
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7395
        if ( ok !== 1 )
7396
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7397
    end
7398
    join
7399
 
7400
    if ( ok )
7401
        test_ok ;
7402
 
7403
    // write 2 to cache line size register
7404
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7405
 
7406
    // perform a read
7407
    fork
7408
    begin
7409
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7410
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7411
        begin
7412
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7413
            $display(" PCI bridge failed to process single CAB read!") ;
7414
            test_fail("burst read was not processed as expected") ;
7415
            ok = 0 ;
7416
        end
7417
    end
7418
    begin
7419
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7420
        if ( ok !== 1 )
7421
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7422
    end
7423
    join
7424
 
7425
    if ( ok )
7426
        test_ok ;
7427
 
7428
    // write 0 to cache line size
7429
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7430
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7431
 
7432
    // perform a read
7433
    fork
7434
    begin
7435
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7436
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7437
        begin
7438
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7439
            $display(" PCI bridge failed to process single CAB read!") ;
7440
            test_fail("burst read was not processed as expected") ;
7441
            ok = 0 ;
7442
        end
7443
    end
7444
    begin
7445
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7446
        if ( ok !== 1 )
7447
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7448
    end
7449
    join
7450
 
7451
    if ( ok )
7452
        test_ok ;
7453
 
7454
    // write normal value to cls register
7455
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7456
 
7457
    $display("Testing Master's latency timer operation!") ;
7458
    $display("Testing Latency timer during Master Writes!") ;
7459
 
7460
    for ( i = 0 ; i < 6 ; i = i + 1 )
7461
    begin
7462
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7463
        write_data`WRITE_SEL     = 4'b1111 ;
7464
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7465
 
7466
        wishbone_master.blk_write_data[i] = write_data ;
7467
    end
7468
 
7469
    write_flags`WB_TRANSFER_SIZE = 6 ;
7470
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7471
    write_flags`WB_TRANSFER_CAB = 1 ;
7472
 
7473
    // start wb write, pci write and monitor in parallel
7474
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7475
    fork
7476
    begin
7477
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7478
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7479
        begin
7480
            $display("Transaction progress testing failed! Time %t ", $time) ;
7481
            $display("Bridge failed to process CAB write!") ;
7482
            test_fail("bridge didn't post whole burst memory write") ;
7483
            disable main ;
7484
        end
7485
    end
7486
    begin
7487
        // wait for bridge's master to start transaction
7488
        @(posedge pci_clock) ;
7489
        while ( FRAME === 1 )
7490
            @(posedge pci_clock) ;
7491
 
7492
        // start behavioral master request
7493
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7494
               target_address, wmem_data[1023], `Test_All_Bytes,
7495
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7496
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7497
 
7498
        do_pause ( 1 ) ;
7499
    end
7500
    begin
7501
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7502
        if ( ok !== 1 )
7503
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7504
        else
7505
            test_ok ;
7506
    end
7507
    join
7508
 
7509
    // perform a read to check data
7510
    for ( i = 0 ; i < 6 ; i = i + 1 )
7511
    begin
7512
        read_data`READ_ADDRESS = target_address + i*4 ;
7513
        read_data`READ_SEL     = 4'b1111 ;
7514
 
7515
        wishbone_master.blk_read_data_in[i] = read_data ;
7516
    end
7517
 
7518
    write_flags`WB_TRANSFER_SIZE = 6 ;
7519
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7520
    write_flags`WB_TRANSFER_CAB = 1 ;
7521
 
7522
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7523
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7524
 
7525
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7526
    begin
7527
        $display("Transaction progress testing failed! Time %t ", $time) ;
7528
        $display("Bridge failed to process CAB read!") ;
7529
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7530
        disable main ;
7531
    end
7532
 
7533
    ok = 1 ;
7534
    for ( i = 0 ; i < 6 ; i = i + 1 )
7535
    begin
7536
        read_status = wishbone_master.blk_read_data_out[i] ;
7537
 
7538
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7539
        begin
7540
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7541
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7542
            test_fail("unexpected data read back from PCI") ;
7543
            ok = 0 ;
7544
        end
7545
    end
7546
 
7547
    if ( ok )
7548
        test_ok ;
7549
 
7550
    $display("Testing Latency timer during Master Reads!") ;
7551
 
7552
    // at least 2 words are transfered during Master Reads terminated with timeout
7553
    write_flags`WB_TRANSFER_SIZE = 2 ;
7554
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7555
    fork
7556
    begin
7557
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7558
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7559
        begin
7560
            $display("Transaction progress testing failed! Time %t ", $time) ;
7561
            $display("Bridge failed to process CAB read!") ;
7562
            test_fail("bridge didn't process burst read as expected") ;
7563
            ok = 0 ;
7564
        end
7565
    end
7566
    begin
7567
        // wait for bridge's master to start transaction
7568
        @(posedge pci_clock) ;
7569
        while ( FRAME === 1 )
7570
            @(posedge pci_clock) ;
7571
 
7572
        // start behavioral master request
7573
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7574
               target_address, wmem_data[0], `Test_All_Bytes,
7575
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7576
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7577
 
7578
        do_pause ( 1 ) ;
7579
    end
7580
    begin
7581
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7582
        if ( ok !== 1 )
7583
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7584
    end
7585
    join
7586
 
7587
    // check data provided by target
7588
    if ( ok )
7589
    begin
7590
        for ( i = 0 ; i < 2 ; i = i + 1 )
7591
        begin
7592
            read_status = wishbone_master.blk_read_data_out[i] ;
7593
 
7594
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7595
            begin
7596
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7597
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7598
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7599
                ok = 0 ;
7600
            end
7601
        end
7602
    end
7603
    if ( ok )
7604
        test_ok ;
7605
 
7606
    test_name = "DISABLE_IMAGE" ;
7607
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7608
    if ( ok !== 1 )
7609
    begin
7610
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7611
        test_fail("write to WB Address Mask register failed") ;
7612
        disable main ;
7613
    end
7614
 
7615
end
7616
endtask //wb_to_pci_transactions
7617
 
7618
task iack_cycle ;
7619
    reg `READ_STIM_TYPE   read_data ;
7620
    reg `READ_RETURN_TYPE read_status ;
7621
    reg `WB_TRANSFER_FLAGS flags ;
7622
 
7623
    reg [31:0] temp_var ;
7624
    reg ok ;
7625 45 mihad
    reg ok_wb ;
7626
    reg ok_pci ;
7627
 
7628
    reg [31:0] irq_vector ;
7629 15 mihad
begin
7630
 
7631 45 mihad
    ok     = 1 ;
7632
    ok_wb  = 1 ;
7633
    ok_pci = 1 ;
7634
 
7635 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7636
 
7637
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7638
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7639
 
7640
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7641
    read_data`READ_SEL     = 4'hF ;
7642
 
7643
    flags = 0 ;
7644
 
7645
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7646
 
7647
    irq_vector  = 32'hAAAA_AAAA ;
7648
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7649
 
7650 45 mihad
    // disable both pci blue behavioral targets
7651
    configuration_cycle_write
7652
    (
7653
        0,                          // bus number [7:0]
7654
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7655
        0,                          // function number [2:0]
7656
        1,                          // register number [5:0]
7657
        0,                          // type [1:0]
7658
        4'h1,                       // byte enables [3:0]
7659
        32'h0000_0044               // data to write [31:0]
7660
    ) ;
7661
 
7662
    configuration_cycle_write
7663
    (
7664
        0,                          // bus number [7:0]
7665
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7666
        0,                          // function number [2:0]
7667
        1,                          // register number [5:0]
7668
        0,                          // type [1:0]
7669
        4'h1,                       // byte enables [3:0]
7670
        32'h0000_0044               // data to write [31:0]
7671
    ) ;
7672
 
7673 15 mihad
    fork
7674
    begin
7675
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7676
    end
7677
    begin
7678 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7679
        if ( ok_pci !== 1 )
7680 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7681
    end
7682
    join
7683
 
7684
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7685
    begin
7686 45 mihad
        ok_wb = 0 ;
7687 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7688
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7689
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7690
    end
7691 45 mihad
 
7692
    if ( ok_pci && ok_wb )
7693 15 mihad
        test_ok ;
7694 45 mihad
 
7695
    ok_wb = 1 ;
7696
    ok_pci = 1 ;
7697
    ok = 1 ;
7698 15 mihad
 
7699 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7700
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7701 15 mihad
 
7702
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7703 45 mihad
    // enable pci blue behavioral target 1
7704
    configuration_cycle_write
7705
    (
7706
        0,                          // bus number [7:0]
7707
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7708
        0,                          // function number [2:0]
7709
        1,                          // register number [5:0]
7710
        0,                          // type [1:0]
7711
        4'h1,                       // byte enables [3:0]
7712
        32'h0000_0047               // data to write [31:0]
7713
    ) ;
7714 15 mihad
    fork
7715
    begin
7716
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7717
    end
7718
    begin
7719 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7720
        if ( ok_pci !== 1 )
7721 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7722
    end
7723
    join
7724
 
7725
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7726
    begin
7727 45 mihad
        ok_wb = 0 ;
7728 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7729
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7730
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7731
    end
7732
 
7733
    if ( read_status`READ_DATA !== irq_vector )
7734
    begin
7735
        $display(" Time %t ", $time ) ;
7736
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7737
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7738 45 mihad
        ok_wb = 0 ;
7739 15 mihad
    end
7740
 
7741 45 mihad
    if ( ok_pci && ok_wb )
7742 15 mihad
        test_ok ;
7743
 
7744 45 mihad
    ok_pci = 1 ;
7745
    ok_wb  = 1 ;
7746
    ok     = 1 ;
7747
 
7748 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7749 45 mihad
    irq_vector  = 32'h5555_5555 ;
7750
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7751
 
7752 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7753
    fork
7754
    begin
7755
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7756
    end
7757
    begin
7758 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7759
        if ( ok_pci !== 1 )
7760 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7761
    end
7762
    join
7763
 
7764
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7765
    begin
7766
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7767
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7768
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7769 45 mihad
        ok_wb = 0 ;
7770 15 mihad
    end
7771
 
7772 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7773 15 mihad
    begin
7774
        $display(" Time %t ", $time ) ;
7775 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7776 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7777 45 mihad
        ok_wb = 0 ;
7778 15 mihad
    end
7779
 
7780 45 mihad
    if (ok_pci && ok_wb)
7781 15 mihad
        test_ok ;
7782
 
7783 45 mihad
    ok_pci = 1 ;
7784
    ok_wb  = 1 ;
7785
    ok     = 1 ;
7786 15 mihad
 
7787 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7788
 
7789
    // set target to terminate with target abort
7790
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7791
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7792
 
7793
    fork
7794
    begin
7795
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7796
    end
7797
    begin
7798
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7799
        if ( ok_pci !== 1 )
7800
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7801
    end
7802
    join
7803
 
7804
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7805
    begin
7806
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7807
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7808
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7809
        ok_wb = 0 ;
7810
    end
7811
 
7812
    // set target to terminate with target abort
7813
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7814
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7815
 
7816
    // enable pci blue behavioral target 2
7817
    configuration_cycle_write
7818
    (
7819
        0,                          // bus number [7:0]
7820
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7821
        0,                          // function number [2:0]
7822
        1,                          // register number [5:0]
7823
        0,                          // type [1:0]
7824
        4'h1,                       // byte enables [3:0]
7825
        32'h0000_0047               // data to write [31:0]
7826
    ) ;
7827
 
7828
    // read PCI Device status
7829
    config_read(12'h4, 4'hC, temp_var) ;
7830
    if (temp_var[29] !== 1)
7831
    begin
7832
        $display("Time %t", $time) ;
7833
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7834
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7835
        ok_wb = 0 ;
7836
    end
7837
 
7838
    if (temp_var[28] !== 1)
7839
    begin
7840
        $display("Time %t", $time) ;
7841
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7842
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7843
        ok_wb = 0 ;
7844
    end
7845
 
7846
    // clearing the status bits
7847
        config_write(12'h4, temp_var, 4'hC, ok);
7848
 
7849
    if ( ok && ok_pci && ok_wb )
7850
        test_ok ;
7851
 
7852 15 mihad
end
7853
endtask //iack_cycle
7854
 
7855
task transaction_ordering ;
7856
    reg   [11:0] wb_ctrl_offset ;
7857
    reg   [11:0] wb_ba_offset ;
7858
    reg   [11:0] wb_am_offset ;
7859
    reg   [11:0] pci_ctrl_offset ;
7860
    reg   [11:0] pci_ba_offset ;
7861
    reg   [11:0] pci_am_offset ;
7862
    reg   [11:0] pci_device_ctrl_offset ;
7863
    reg   [11:0] wb_err_cs_offset ;
7864
    reg   [11:0] pci_err_cs_offset ;
7865
    reg   [11:0] icr_offset ;
7866
    reg   [11:0] isr_offset ;
7867
    reg   [11:0] lat_tim_cls_offset ;
7868
 
7869
    reg `WRITE_STIM_TYPE  write_data ;
7870
    reg `READ_STIM_TYPE   read_data ;
7871
    reg `READ_RETURN_TYPE read_status ;
7872
 
7873
    reg `WRITE_RETURN_TYPE write_status ;
7874
    reg `WB_TRANSFER_FLAGS write_flags ;
7875
    reg [31:0] temp_val1 ;
7876
    reg [31:0] temp_val2 ;
7877
    reg        ok   ;
7878
 
7879
    reg [31:0] wb_image_base ;
7880
    reg [31:0] wb_target_address ;
7881
    reg [31:0] pci_image_base ;
7882
    integer i ;
7883
 
7884
    reg     error_monitor_done ;
7885
begin:main
7886
    write_flags`INIT_WAITS = tb_init_waits ;
7887
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7888
 
7889
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7890
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7891
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7892
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7893
 
7894
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7895
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7896
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7897
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7898
 
7899
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7900
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7901
    lat_tim_cls_offset = 12'hC ;
7902
    pci_device_ctrl_offset    = 12'h4 ;
7903
 
7904
    wb_target_address  = `BEH_TAR1_MEM_START ;
7905
    wb_image_base      = 0 ;
7906
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7907
 
7908
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7909
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7910
    write_flags                    = 0 ;
7911
    write_flags`INIT_WAITS         = 0 ;
7912
    write_flags`SUBSEQ_WAITS       = 0 ;
7913
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7914
 
7915
    pci_image_base = Target_Base_Addr_R[1] ;
7916
 
7917
    // enable master & target operation
7918
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7919
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7920
    if ( ok !== 1 )
7921
    begin
7922
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7923
        test_fail("write to PCI Device Control register failed") ;
7924
        disable main ;
7925
    end
7926
 
7927
    // prepare image control register
7928
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7929
    if ( ok !== 1 )
7930
    begin
7931
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7932
        test_fail("write to WB Image Control register failed") ;
7933
        disable main ;
7934
    end
7935
 
7936
    // prepare base address register
7937
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7938
    if ( ok !== 1 )
7939
    begin
7940
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7941
        test_fail("write to WB Base Address register failed") ;
7942
        disable main ;
7943
    end
7944
 
7945
    // write address mask register
7946
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7947
    if ( ok !== 1 )
7948
    begin
7949
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7950
        test_fail("write to WB Address Mask register failed") ;
7951
        disable main ;
7952
    end
7953
 
7954
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7955
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7956
    if ( ok !== 1 )
7957
    begin
7958
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
7959
        test_fail("write to WB Error Control and Status register failed") ;
7960
        disable main ;
7961
    end
7962
 
7963
    // prepare image control register
7964
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7965
    if ( ok !== 1 )
7966
    begin
7967
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
7968
        test_fail("write to PCI Image Control register failed") ;
7969
        disable main ;
7970
    end
7971
 
7972
    // prepare base address register
7973
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
7974
    if ( ok !== 1 )
7975
    begin
7976
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
7977
        test_fail("write to PCI Base Address register failed") ;
7978
        disable main ;
7979
    end
7980
 
7981
    // write address mask register
7982
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7983
    if ( ok !== 1 )
7984
    begin
7985
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
7986
        test_fail("write to PCI Address Mask register failed") ;
7987
        disable main ;
7988
    end
7989
 
7990
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7991
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7992
    if ( ok !== 1 )
7993
    begin
7994
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
7995
        test_fail("write to PCI Error Control and Status register failed") ;
7996
        disable main ;
7997
    end
7998
 
7999
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8000
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8001
    if ( ok !== 1 )
8002
    begin
8003
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8004
        test_fail("write to Interrupt Control register failed") ;
8005
        disable main ;
8006
    end
8007
 
8008
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8009
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8010
    if ( ok !== 1 )
8011
    begin
8012
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8013
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8014
        disable main ;
8015
    end
8016
 
8017
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8018
 
8019
    // prepare wb_master write and read data
8020
    for ( i = 0 ; i < 4 ; i = i + 1 )
8021
    begin
8022
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8023
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8024
        write_data`WRITE_SEL     = 4'hF ;
8025
 
8026
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8027
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8028
 
8029
        wishbone_master.blk_write_data[i]   = write_data ;
8030
        wishbone_master.blk_read_data_in[i] = read_data ;
8031
    end
8032
 
8033
    // put wishbone slave in acknowledge and pci target in retry mode
8034
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8035
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8036
 
8037
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8038
 
8039
    fork
8040
    begin
8041
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8042
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8043
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8044
        begin
8045
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8046
            test_fail("Bridge didn't post single memory write as expected") ;
8047
        end
8048
 
8049
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8050
        if ( ok !== 1 )
8051
        begin
8052
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8053
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8054
            ok = 0 ;
8055
        end
8056
 
8057
        // now post single write to target - normal progress
8058
        if ( target_mem_image == 1 )
8059
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8060
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8061
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8062
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8063
        else
8064
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8065
 
8066
        do_pause( 1 ) ;
8067
 
8068
    end
8069
    begin:error_monitor_1
8070 35 mihad
        error_monitor_done = 0 ;
8071 15 mihad
        @(error_event_int) ;
8072
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8073
        ok = 0 ;
8074 35 mihad
        error_monitor_done = 1 ;
8075 15 mihad
    end
8076
    begin
8077
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8078
        if ( ok !== 1 )
8079
        begin
8080
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8081
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8082
        end
8083
        else
8084
        begin
8085 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8086
//            while ( FRAME === 0 || IRDY === 0 )
8087
//                @(posedge pci_clock) ;
8088 15 mihad
 
8089
            // enable response in PCI target
8090
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8091
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8092
 
8093
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8094
            if ( ok !== 1 )
8095
            begin
8096
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8097
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8098
            end
8099
        end
8100
 
8101 35 mihad
        #1 ;
8102
        if ( !error_monitor_done )
8103
            disable error_monitor_1 ;
8104 15 mihad
    end
8105
    join
8106
 
8107
    if ( ok )
8108
        test_ok ;
8109
 
8110
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8111
 
8112
    // put WISHBONE slave in retry mode
8113
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8114
 
8115
    fork
8116
    begin
8117
        // now post single write to target - normal progress
8118
        if ( target_mem_image == 1 )
8119
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8120
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8121
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8122
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8123
        else
8124
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8125
 
8126
        do_pause( 1 ) ;
8127
 
8128
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8129
        if ( ok !== 1 )
8130
        begin
8131
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8132
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8133
        end
8134
 
8135
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8136
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8137
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8138
        begin
8139
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8140
            test_fail("Bridge didn't post single memory write as expected") ;
8141
        end
8142
 
8143
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8144
        if ( ok !== 1 )
8145
        begin
8146
            $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) ;
8147
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8148
            ok = 0 ;
8149
        end
8150
 
8151
        wait ( CYC_O === 0 ) ;
8152
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8153
 
8154
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8155
        if ( ok !== 1 )
8156
        begin
8157
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8158
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8159
        end
8160
 
8161 35 mihad
        #1 ;
8162
        if ( !error_monitor_done )
8163
            disable error_monitor_2 ;
8164 15 mihad
    end
8165
    begin:error_monitor_2
8166 35 mihad
        error_monitor_done = 0 ;
8167 15 mihad
        @(error_event_int) ;
8168
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8169
        ok = 0 ;
8170 35 mihad
        error_monitor_done = 1 ;
8171 15 mihad
    end
8172
    join
8173
 
8174
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8175
 
8176
    // put wishbone slave in acknowledge and pci target in retry mode
8177
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8178
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8179
 
8180
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8181
 
8182
    fork
8183
    begin
8184
        write_flags`WB_TRANSFER_SIZE = 3 ;
8185
        write_flags`WB_TRANSFER_CAB  = 1 ;
8186
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8187
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8188
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8189
        begin
8190
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8191
            test_fail("Bridge didn't post burst memory write as expected") ;
8192
        end
8193
 
8194
        pci_transaction_progress_monitor( wb_target_address, `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
        // now post single write to target - normal progress
8203
        if ( target_mem_image == 1 )
8204
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8205
                        pci_image_base, 32'h5555_5555, 4'h0,
8206
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8207
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8208
        else
8209
        begin
8210
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8211
            do_pause( 1 ) ;
8212
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8213
        end
8214
 
8215
        do_pause( 1 ) ;
8216
 
8217
    end
8218
    begin:error_monitor_3
8219 35 mihad
        error_monitor_done = 0 ;
8220 15 mihad
        @(error_event_int) ;
8221
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8222
        ok = 0 ;
8223 35 mihad
        error_monitor_done = 1 ;
8224 15 mihad
    end
8225
    begin
8226
        if ( target_mem_image == 1 )
8227
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8228
        else
8229
        begin
8230
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8231
            if ( ok )
8232
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8233
        end
8234
 
8235
        if ( ok !== 1 )
8236
        begin
8237
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8238
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8239
        end
8240
        else
8241
        begin
8242 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8243
//            while ( FRAME === 0 || IRDY === 0 )
8244
//                @(posedge pci_clock) ;
8245 15 mihad
 
8246
            // enable response in PCI target
8247
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8248
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8249
 
8250
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8251
            if ( ok !== 1 )
8252
            begin
8253
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8254
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8255
            end
8256
        end
8257
 
8258 35 mihad
        #1 ;
8259
        if ( !error_monitor_done )
8260
            disable error_monitor_3 ;
8261 15 mihad
    end
8262
    join
8263
 
8264
    if ( ok )
8265
        test_ok ;
8266
 
8267
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8268
 
8269
    // put WISHBONE slave in retry mode
8270
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8271
 
8272
    fork
8273
    begin
8274
        // now post single write to target - normal progress
8275
        if ( target_mem_image == 1 )
8276
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8277
                        pci_image_base, 32'h5555_5555, 4'h0,
8278
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8279
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8280
        else
8281
        begin
8282
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8283
            do_pause( 1 ) ;
8284
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8285
        end
8286
 
8287
        do_pause( 1 ) ;
8288
 
8289
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8290
 
8291
        if ( ok !== 1 )
8292
        begin
8293
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8294
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8295
        end
8296
 
8297
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8298
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8299
        write_flags`WB_TRANSFER_CAB      = 1 ;
8300
 
8301
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8302
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8303
        begin
8304
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8305
            test_fail("Bridge didn't post burst memory write as expected") ;
8306
        end
8307
 
8308
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8309
        if ( ok !== 1 )
8310
        begin
8311
            $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) ;
8312
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8313
            ok = 0 ;
8314
        end
8315
 
8316
        @(posedge wb_clock) ;
8317
        while ( CYC_O === 1 )
8318
            @(posedge wb_clock) ;
8319
 
8320
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8321
 
8322
        if ( target_mem_image == 1 )
8323
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8324
        else
8325
        begin
8326
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8327
            if ( ok )
8328
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8329
        end
8330
 
8331 35 mihad
        #1 ;
8332
        if ( !error_monitor_done )
8333
            disable error_monitor_4 ;
8334 15 mihad
    end
8335
    begin:error_monitor_4
8336 35 mihad
        error_monitor_done = 0 ;
8337 15 mihad
        @(error_event_int) ;
8338
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8339
        ok = 0 ;
8340 35 mihad
        error_monitor_done = 1 ;
8341 15 mihad
    end
8342
    join
8343
 
8344
    if ( ok )
8345
        test_ok ;
8346
 
8347
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8348
 
8349
    // put wishbone slave in acknowledge and pci target in retry mode
8350
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8351
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8352
 
8353
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8354
 
8355
    master1_check_received_data = 1 ;
8356
 
8357
    error_monitor_done = 0 ;
8358
    fork
8359
    begin:error_monitor_5
8360
        @(error_event_int or error_monitor_done) ;
8361
        if ( !error_monitor_done )
8362
        begin
8363
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8364
            ok = 0 ;
8365
        end
8366
    end
8367
    begin
8368
 
8369
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8370
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8371
        begin
8372
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8373
            test_fail("Bridge didn't post single memory write as expected") ;
8374
        end
8375
 
8376
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8377
        if ( ok !== 1 )
8378
        begin
8379
            $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) ;
8380
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8381
            ok = 0 ;
8382
        end
8383
 
8384
        // start Read Through pci target
8385
        if ( target_mem_image == 1 )
8386
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8387
                          pci_image_base, 32'h5555_5555,
8388
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8389
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8390
        else
8391
            PCIU_IO_READ
8392
             (
8393
                `Test_Master_1,
8394
                pci_image_base,
8395
                32'h5555_5555,
8396
                4'h0,
8397
                1,
8398
                `Test_Target_Retry_On
8399
             );
8400
 
8401
         do_pause( 1 ) ;
8402
 
8403
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8404
         if ( ok !== 1 )
8405
         begin
8406
            $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) ;
8407
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8408
         end
8409
 
8410
         // repeat the read 4 times - it should be retried all the time by pci target
8411
        for ( i = 0 ; i < 4 ; i = i + 1 )
8412
        begin
8413
            if ( target_mem_image == 1 )
8414
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8415
                            pci_image_base, 32'h5555_5555,
8416
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8417
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8418
            else
8419
                PCIU_IO_READ
8420
                (
8421
                    `Test_Master_1,
8422
                    pci_image_base,
8423
                    32'h5555_5555,
8424
                    4'h0,
8425
                    1,
8426
                    `Test_Target_Retry_On
8427
                );
8428
 
8429
            do_pause( 1 ) ;
8430
        end
8431
 
8432
        // now do posted write through target - it must go through OK
8433
        if ( target_mem_image == 1 )
8434
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8435
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8436
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8437
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8438
        else
8439
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8440
 
8441
        do_pause( 1 ) ;
8442
 
8443
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8444
        if ( ok !== 1 )
8445
        begin
8446
           $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) ;
8447
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8448
        end
8449
 
8450
        // start a read through wb_slave
8451
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8452
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8453
        begin
8454
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8455
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8456
            ok = 0 ;
8457
        end
8458
 
8459 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8460
//        while ( FRAME === 0 || IRDY === 0 )
8461
//            @(posedge pci_clock) ;
8462 15 mihad
 
8463
        // set the target to normal completion
8464
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8465
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8466
 
8467
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8468
        if ( ok !== 1 )
8469
        begin
8470
            $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) ;
8471
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8472
            ok = 0 ;
8473
        end
8474
 
8475
        // now wait for delayed read to finish
8476
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8477
        if ( ok !== 1 )
8478
        begin
8479
            $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) ;
8480
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8481
            ok = 0 ;
8482
        end
8483
 
8484
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8485
        fork
8486
        begin
8487
                if ( target_mem_image == 1 )
8488
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8489
                                pci_image_base, 32'h5555_5555, 4'h0,
8490
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8491
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8492
                else
8493
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8494
 
8495
                do_pause( 1 ) ;
8496
                end
8497
                begin
8498
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8499
                end
8500
                join
8501
 
8502
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8503
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8504
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8505
        begin
8506
            $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) ;
8507
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8508
            ok = 0 ;
8509
        end
8510
 
8511
        fork
8512
        begin
8513
        // now complete a read from PCI Target
8514
            if ( target_mem_image == 1 )
8515
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8516
                            pci_image_base, 32'h5555_5555,
8517
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8518
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8519
            else
8520
                PCIU_IO_READ
8521
                (
8522
                    `Test_Master_1,
8523
                    pci_image_base,
8524
                    32'h5555_5555,
8525
                    4'h0,
8526
                    1,
8527
                    `Test_Target_Normal_Completion
8528
                );
8529
 
8530
            do_pause( 1 ) ;
8531
        end
8532
        begin
8533
            if ( target_mem_image == 1 )
8534
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8535
            else
8536
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8537
        end
8538
        join
8539
 
8540
        @(posedge pci_clock) ;
8541
        repeat( 4 )
8542
            @(posedge wb_clock) ;
8543
 
8544
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8545
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8546
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8547
        begin
8548
            $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) ;
8549
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8550
            ok = 0 ;
8551
        end
8552
 
8553
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8554
        if ( ok !== 1 )
8555
        begin
8556
            $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) ;
8557
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8558
            ok = 0 ;
8559
        end
8560
 
8561
        // finish a read on WISHBONE also
8562
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8563
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8564
        begin
8565
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8566
            test_fail("WB Slave didn't process single delayed read as expected") ;
8567
        end
8568
 
8569
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8570
        begin
8571
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8572
            ok = 0 ;
8573
        end
8574
 
8575
 
8576
        error_monitor_done = 1 ;
8577
    end
8578
    join
8579
 
8580
    if ( ok )
8581
        test_ok ;
8582
 
8583
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8584
 
8585
    // put wishbone slave in retry and pci target in completion mode
8586
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8587
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8588
 
8589
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8590
 
8591
    master1_check_received_data = 1 ;
8592
 
8593
    error_monitor_done = 0 ;
8594
    fork
8595
    begin:error_monitor_6
8596
        @(error_event_int or error_monitor_done) ;
8597
        if ( !error_monitor_done )
8598
        begin
8599
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8600
            ok = 0 ;
8601
        end
8602
    end
8603
    begin
8604
 
8605
        // do a write through Target
8606
        fork
8607
        begin
8608
            if ( target_mem_image == 1 )
8609
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8610
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8611
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8612
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8613
            else
8614
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8615
 
8616
            do_pause( 1 ) ;
8617
        end
8618
        begin
8619
            if ( target_mem_image == 1 )
8620
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8621
            else
8622
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8623
        end
8624
        join
8625
 
8626
        // start a read through WB slave
8627
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8628
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8629
        begin
8630
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8631
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8632
            ok = 0 ;
8633
        end
8634
 
8635
        // now wait for this read to finish on pci
8636
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8637
        if ( ok !== 1 )
8638
        begin
8639
            $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) ;
8640
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8641
            ok = 0 ;
8642
        end
8643
 
8644
        // repeat the read four times - it should be retried
8645
        for ( i = 0 ; i < 4 ; i = i + 1 )
8646
        begin
8647
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8648
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8649
            begin
8650
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8651
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8652
                ok = 0 ;
8653
            end
8654
        end
8655
 
8656
        // posted write through WB Slave - must go through
8657
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8658
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8659
        begin
8660
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8661
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8662
            ok = 0 ;
8663
        end
8664
 
8665
        // write must come through
8666
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8667
        if ( ok !== 1 )
8668
        begin
8669
            $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) ;
8670
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8671
            ok = 0 ;
8672
        end
8673
 
8674
        // do a read through pci target
8675
        if ( target_mem_image == 1 )
8676
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8677
                          pci_image_base + 12, 32'hDEAD_BEAF,
8678
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8679
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8680
        else
8681
            PCIU_IO_READ
8682
             (
8683
                `Test_Master_1,
8684
                pci_image_base + 12,
8685
                32'hDEAD_BEAF,
8686
                4'h0,
8687
                1,
8688
                `Test_Target_Retry_On
8689
             );
8690
 
8691
         do_pause( 1 ) ;
8692
 
8693
        // wait for current cycle to finish on WB
8694 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8695
//        @(posedge wb_clock) ;
8696
//        while( CYC_O === 1 )
8697
//            @(posedge wb_clock) ;
8698 15 mihad
 
8699
        // set slave response to acknowledge
8700
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8701
 
8702
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8703
        if ( ok !== 1 )
8704
        begin
8705
            $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) ;
8706
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8707
        end
8708
 
8709
        // check the read to finish on wb
8710
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8711
        if ( ok !== 1 )
8712
        begin
8713
            $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) ;
8714
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8715
        end
8716
 
8717
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8718
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8719
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8720
        begin
8721
            $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) ;
8722
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8723
            ok = 0 ;
8724
        end
8725
 
8726
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8727
        fork
8728
        begin
8729
            if ( target_mem_image == 1 )
8730
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8731
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8732
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8733
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8734
            else
8735
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8736
        end
8737
        begin
8738
            if ( target_mem_image == 1 )
8739
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8740
            else
8741
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8742
        end
8743
        join
8744
 
8745
        do_pause( 1 ) ;
8746
 
8747
        // complete a read in WB Slave Unit
8748
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8749
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8750
        begin
8751
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8752
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8753
            ok = 0 ;
8754
        end
8755
 
8756
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8757
        begin
8758
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8759
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8760
            ok = 0 ;
8761
        end
8762
 
8763
        // wait for statuses to be propagated from one side of bridge to another
8764
        repeat( 4 )
8765
            @(posedge pci_clock) ;
8766
 
8767
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8768
        fork
8769
        begin
8770
            if ( target_mem_image == 1 )
8771
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8772
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8773
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8774
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8775
            else
8776
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8777
 
8778
            do_pause( 1 ) ;
8779
        end
8780
        begin
8781
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8782
            if ( ok !== 1 )
8783
            begin
8784
                $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) ;
8785
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8786
            end
8787
        end
8788
        join
8789
 
8790
        // finish the last read in PCI Target Unit
8791
        if ( target_mem_image == 1 )
8792
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8793
                          pci_image_base + 12, 32'hDEAD_BEAF,
8794
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8795
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8796
        else
8797
            PCIU_IO_READ
8798
             (
8799
                `Test_Master_1,
8800
                pci_image_base + 12,
8801
                32'hDEAD_BEAF,
8802
                4'h0,
8803
                1,
8804
                `Test_Target_Normal_Completion
8805
             );
8806
 
8807
         do_pause( 1 ) ;
8808
 
8809
         error_monitor_done = 1 ;
8810
    end
8811
    join
8812
 
8813
    if ( ok )
8814
        test_ok ;
8815
 
8816
end
8817
endtask // transaction_ordering
8818
 
8819
task pci_transaction_progress_monitor ;
8820
    input [31:0] address ;
8821
    input [3:0]  bus_command ;
8822
    input [31:0] num_of_transfers ;
8823
    input [31:0] num_of_cycles ;
8824
    input check_transfers ;
8825
    input check_cycles ;
8826
    input doing_fast_back_to_back ;
8827
    output ok ;
8828
    reg in_use ;
8829
    integer deadlock_counter ;
8830
    integer transfer_counter ;
8831
    integer cycle_counter ;
8832
    integer deadlock_max_val ;
8833
begin:main
8834
 
8835
    if ( in_use === 1 )
8836
    begin
8837
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8838
        ok = 0 ;
8839
        disable main ;
8840
    end
8841
 
8842
    // approximate number of cycles on WB bus for maximum transaction length
8843
    deadlock_max_val = tb_init_waits + 100 +
8844
                       `WBW_DEPTH *
8845
                       (tb_subseq_waits + 1 +
8846
                       `ifdef REGISTER_WBS_OUTPUTS
8847
                       1) ;
8848
                       `else
8849
                       0) ;
8850
                       `endif
8851
 
8852
    // time used for maximum transaction length on WB
8853
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8854
 
8855
    // maximum pci clock cycles
8856
    `ifdef PCI33
8857
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8858
    `else
8859
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8860
    `endif
8861
 
8862
    in_use = 1 ;
8863
    ok     = 1 ;
8864
 
8865
    fork
8866
    begin:wait_start
8867
 
8868
        deadlock_counter = 0 ;
8869
 
8870
        @(posedge pci_clock) ;
8871
 
8872
        if ( doing_fast_back_to_back !== 1 )
8873
        begin
8874
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8875
            begin
8876 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8877
                    deadlock_counter = 0 ;
8878
                else
8879
                    deadlock_counter = deadlock_counter + 1 ;
8880 15 mihad
                @(posedge pci_clock) ;
8881
            end
8882
            if ( FRAME !== 1 )
8883
            begin
8884
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8885
                in_use = 0 ;
8886
                ok     = 0 ;
8887
                disable main ;
8888
            end
8889
        end
8890
 
8891
        deadlock_counter = 0 ;
8892
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8893
        begin
8894
            deadlock_counter = deadlock_counter + 1 ;
8895
            @(posedge pci_clock) ;
8896
        end
8897
 
8898
        if ( FRAME !== 0 )
8899
        begin
8900
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8901
            in_use = 0 ;
8902
            ok     = 0 ;
8903
            disable main ;
8904
        end
8905
    end //wait_start
8906
 
8907
    begin:addr_bc_monitor
8908
 
8909
        @(posedge pci_clock) ;
8910
 
8911
        if ( doing_fast_back_to_back !== 1 )
8912
        begin
8913
            while ( FRAME !== 1 )
8914
                @(posedge pci_clock) ;
8915
        end
8916
 
8917
        while( FRAME !== 0 )
8918
            @(posedge pci_clock) ;
8919
 
8920
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8921
        if ( bus_command !== `BC_IACK )
8922
        begin
8923
            if ( AD !== address )
8924
            begin
8925
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8926
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8927
                ok = 0 ;
8928
            end
8929
        end
8930
 
8931
        if ( CBE !== bus_command )
8932
        begin
8933
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8934
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8935
            ok = 0 ;
8936
        end
8937
    end //addr_bc_monitor
8938
 
8939
    begin:transfer_checker
8940
        transfer_counter = 0 ;
8941
 
8942
        @(posedge pci_clock) ;
8943
 
8944
        if ( doing_fast_back_to_back !== 1 )
8945
        begin
8946
            while ( FRAME !== 1 )
8947
                @(posedge pci_clock) ;
8948
        end
8949
 
8950
        while( FRAME !== 0 )
8951
            @(posedge pci_clock) ;
8952
 
8953
        while( FRAME === 0 )
8954
        begin
8955
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
8956
                transfer_counter = transfer_counter + 1 ;
8957
            @(posedge pci_clock) ;
8958
        end
8959
 
8960
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
8961
        begin
8962
            @(posedge pci_clock) ;
8963
        end
8964
 
8965
        if ( (TRDY === 0) && (DEVSEL === 0) )
8966
                transfer_counter = transfer_counter + 1 ;
8967
 
8968
        if ( check_transfers === 1 )
8969
        begin
8970
            if ( transfer_counter !== num_of_transfers )
8971
            begin
8972
                $display("pci_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
    begin:cycle_checker
8979
        if ( check_cycles )
8980
        begin
8981
            cycle_counter = 0 ;
8982
            @(posedge pci_clock) ;
8983
 
8984
            if ( doing_fast_back_to_back !== 1)
8985
            begin
8986
                while ( FRAME !== 1 )
8987
                    @(posedge pci_clock) ;
8988
            end
8989
 
8990
            while( FRAME !== 0 )
8991
                @(posedge pci_clock) ;
8992
 
8993
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
8994
            begin
8995
                cycle_counter = cycle_counter + 1 ;
8996
                @(posedge pci_clock) ;
8997
            end
8998
 
8999
            if ( FRAME !== 1 )
9000
            begin
9001
                while ((FRAME === 0) && (MAS0_GNT === 0))
9002
                    @(posedge pci_clock) ;
9003
 
9004
                if ( FRAME !== 1 )
9005
                begin
9006
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9007
                        @(posedge pci_clock) ;
9008
 
9009
                    @(posedge pci_clock) ;
9010
 
9011
                    if ( FRAME !== 1 )
9012
                    begin
9013
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9014
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9015
                        ok = 0 ;
9016
                    end
9017
                end
9018
            end
9019
        end
9020
    end // cycle_checker
9021
    join
9022
 
9023
    in_use = 0 ;
9024
end
9025
endtask //pci_transaction_progress_monitor
9026
 
9027
reg CYC_O_previous ;
9028
always@(posedge wb_clock or posedge reset)
9029
begin
9030
    if ( reset )
9031
        CYC_O_previous <= #1 1'b0 ;
9032
    else
9033
        CYC_O_previous <= #1 CYC_O ;
9034
end
9035
 
9036
task wb_transaction_progress_monitor ;
9037
    input [31:0] address ;
9038
    input        write ;
9039
    input [31:0] num_of_transfers ;
9040
    input check_transfers ;
9041
    output ok ;
9042
    reg in_use ;
9043
    integer deadlock_counter ;
9044
    integer transfer_counter ;
9045
    integer deadlock_max_val ;
9046
begin:main
9047
    if ( in_use === 1 )
9048
    begin
9049
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9050
        ok = 0 ;
9051
        disable main ;
9052
    end
9053
 
9054
    // number of cycles on WB bus for maximum transaction length
9055
    deadlock_max_val = 4 - tb_init_waits + 100 +
9056
                       `PCIW_DEPTH *
9057
                       (4 - tb_subseq_waits + 1) ;
9058
 
9059
    // time used for maximum transaction length on PCI
9060
    `ifdef PCI33
9061
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9062
    `else
9063
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9064
    `endif
9065
 
9066
    // maximum wb clock cycles
9067
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9068
 
9069
    in_use = 1 ;
9070
    ok     = 1 ;
9071
 
9072
    fork
9073
    begin:wait_start
9074
        deadlock_counter = 0 ;
9075
        @(posedge wb_clock) ;
9076
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9077
        begin
9078 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9079
                deadlock_counter = deadlock_counter + 1 ;
9080
            else
9081
                deadlock_counter = 0;
9082 15 mihad
            @(posedge wb_clock) ;
9083
        end
9084
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9085
        begin
9086
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9087
            in_use = 0 ;
9088
            ok     = 0 ;
9089
            disable main ;
9090
        end
9091
 
9092
        deadlock_counter = 0 ;
9093
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9094
        begin
9095
            deadlock_counter = deadlock_counter + 1 ;
9096
            @(posedge wb_clock) ;
9097
        end
9098
 
9099
        if ( CYC_O !== 1 )
9100
        begin
9101
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9102
            in_use = 0 ;
9103
            ok     = 0 ;
9104
            disable main ;
9105
        end
9106
    end //wait_start
9107
    begin:addr_monitor
9108
        @(posedge wb_clock) ;
9109
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9110
            @(posedge wb_clock) ;
9111
 
9112
        while( CYC_O !== 1 )
9113
            @(posedge wb_clock) ;
9114
 
9115
        while (STB_O !== 1 )
9116
            @(posedge wb_clock) ;
9117
 
9118
        if ( WE_O !== write )
9119
        begin
9120
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9121
            if ( write !== 1 )
9122
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9123
            else
9124
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9125
        end
9126
 
9127
        if ( ADR_O !== address )
9128
        begin
9129
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9130
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9131
            ok = 0 ;
9132
        end
9133
    end
9134
    begin:transfer_checker
9135
        transfer_counter = 0 ;
9136
        @(posedge wb_clock) ;
9137
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9138
            @(posedge wb_clock) ;
9139
 
9140
        while( CYC_O !== 1 )
9141
            @(posedge wb_clock) ;
9142
 
9143
        while( CYC_O === 1 )
9144
        begin
9145
            if ( (STB_O === 1) && (ACK_I === 1) )
9146
                transfer_counter = transfer_counter + 1 ;
9147
            @(posedge wb_clock) ;
9148
        end
9149
 
9150
        if ( check_transfers === 1 )
9151
        begin
9152
            if ( transfer_counter !== num_of_transfers )
9153
            begin
9154
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9155
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9156
                ok = 0 ;
9157
            end
9158
        end
9159
    end //transfer_checker
9160
    join
9161
 
9162
    in_use = 0 ;
9163
end
9164
endtask // wb_transaction_progress_monitor
9165
 
9166
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9167
// so they are not re-entered
9168
task wb_transaction_progress_monitor_backup ;
9169
    input [31:0] address ;
9170
    input        write ;
9171
    input [31:0] num_of_transfers ;
9172
    input check_transfers ;
9173
    output ok ;
9174
    reg in_use ;
9175
    integer deadlock_counter ;
9176
    integer transfer_counter ;
9177
    integer deadlock_max_val ;
9178
begin:main
9179
    if ( in_use === 1 )
9180
    begin
9181
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9182
        ok = 0 ;
9183
        disable main ;
9184
    end
9185
 
9186
    // number of cycles on WB bus for maximum transaction length
9187
    deadlock_max_val = 4 - tb_init_waits + 100 +
9188
                       `PCIW_DEPTH *
9189
                       (4 - tb_subseq_waits + 1) ;
9190
 
9191
    // time used for maximum transaction length on PCI
9192
    `ifdef PCI33
9193
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9194
    `else
9195
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9196
    `endif
9197
 
9198
    // maximum wb clock cycles
9199
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9200
 
9201
    in_use = 1 ;
9202
    ok     = 1 ;
9203
 
9204
    fork
9205
    begin:wait_start
9206
        deadlock_counter = 0 ;
9207
        @(posedge wb_clock) ;
9208
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9209
        begin
9210 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9211
                deadlock_counter = deadlock_counter + 1 ;
9212
            else
9213
                deadlock_counter = 0;
9214 15 mihad
            @(posedge wb_clock) ;
9215
        end
9216
        if ( CYC_O !== 0 )
9217
        begin
9218
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9219
            in_use = 0 ;
9220
            ok     = 0 ;
9221
            disable main ;
9222
        end
9223
 
9224
        deadlock_counter = 0 ;
9225
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9226
        begin
9227
            deadlock_counter = deadlock_counter + 1 ;
9228
            @(posedge wb_clock) ;
9229
        end
9230
 
9231
        if ( CYC_O !== 1 )
9232
        begin
9233
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9234
            in_use = 0 ;
9235
            ok     = 0 ;
9236
            disable main ;
9237
        end
9238
    end //wait_start
9239
    begin:addr_monitor
9240
        @(posedge wb_clock) ;
9241
        while ( CYC_O !== 0 )
9242
            @(posedge wb_clock) ;
9243
 
9244
        while( CYC_O !== 1 )
9245
            @(posedge wb_clock) ;
9246
 
9247
        while (STB_O !== 1 )
9248
            @(posedge wb_clock) ;
9249
 
9250
        if ( WE_O !== write )
9251
        begin
9252
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9253
            if ( write !== 1 )
9254
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9255
            else
9256
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9257
        end
9258
 
9259
        if ( ADR_O !== address )
9260
        begin
9261
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9262
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9263
            ok = 0 ;
9264
        end
9265
    end
9266
    begin:transfer_checker
9267
        transfer_counter = 0 ;
9268
        @(posedge wb_clock) ;
9269
        while ( CYC_O !== 0 )
9270
            @(posedge wb_clock) ;
9271
 
9272
        while( CYC_O !== 1 )
9273
            @(posedge wb_clock) ;
9274
 
9275
        while( CYC_O === 1 )
9276
        begin
9277
            if ( (STB_O === 1) && (ACK_I === 1) )
9278
                transfer_counter = transfer_counter + 1 ;
9279
            @(posedge wb_clock) ;
9280
        end
9281
 
9282
        if ( check_transfers === 1 )
9283
        begin
9284
            if ( transfer_counter !== num_of_transfers )
9285
            begin
9286
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9287
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9288
                ok = 0 ;
9289
            end
9290
        end
9291
    end //transfer_checker
9292
    join
9293
 
9294
    in_use = 0 ;
9295
end
9296
endtask // wb_transaction_progress_monitor_backup
9297
 
9298
task wb_transaction_stop ;
9299
    input [31:0] num_of_transfers ;
9300
    integer transfer_counter ;
9301
begin:main
9302
    begin:transfer_checker
9303
        transfer_counter = 0 ;
9304
        @(posedge wb_clock) ;
9305
        while ( CYC_O !== 0 )
9306
            @(posedge wb_clock) ;
9307
 
9308
        while( CYC_O !== 1 )
9309
            @(posedge wb_clock) ;
9310
 
9311
        if ( (STB_O === 1) && (ACK_I === 1) )
9312
            transfer_counter = transfer_counter + 1 ;
9313
 
9314
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9315
        begin
9316
            @(posedge wb_clock) ;
9317
            if ( (STB_O === 1) && (ACK_I === 1) )
9318
                transfer_counter = transfer_counter + 1 ;
9319
        end
9320
    end //transfer_checker
9321
end
9322
endtask // wb_transaction_stop
9323
 
9324
task musnt_respond ;
9325
    output ok ;
9326
    reg in_use ;
9327
    integer i ;
9328
begin:main
9329
    if ( in_use === 1 )
9330
    begin
9331
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9332
        #20 $stop ;
9333
        ok = 0 ;
9334
        disable main ;
9335
    end
9336
 
9337
    in_use = 1 ;
9338
    ok = 1 ;
9339
 
9340
    fork
9341
    begin:wait_start
9342
        @(negedge FRAME) ;
9343
        disable count ;
9344
    end
9345
    begin:count
9346
        i = 0 ;
9347
        while ( i < 1000 )
9348
        begin
9349
            @(posedge pci_clock) ;
9350
            i = i + 1 ;
9351
        end
9352
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9353
        ok = 0 ;
9354
        disable wait_start ;
9355
    end
9356
    join
9357
 
9358
    @(posedge pci_clock) ;
9359
    while ( FRAME === 0 && ok )
9360
    begin
9361
        if ( DEVSEL !== 1 )
9362
        begin
9363
            ok = 0 ;
9364
        end
9365
        @(posedge pci_clock) ;
9366
    end
9367
 
9368
    while ( IRDY === 0 && ok )
9369
    begin
9370
        if ( DEVSEL !== 1 )
9371
        begin
9372
            ok = 0 ;
9373
        end
9374
        @(posedge pci_clock) ;
9375
    end
9376
    in_use = 0 ;
9377
end
9378
endtask
9379
 
9380
function [31:0] wb_to_pci_addr_convert ;
9381
    input [31:0] wb_address ;
9382
    input [31:0] translation_address ;
9383
    input [31:0] translate ;
9384
 
9385
    reg   [31:0] temp_address ;
9386
begin
9387
    if ( translate !== 1 )
9388
    begin
9389
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9390
    end
9391
    else
9392
    begin
9393
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9394
    end
9395
 
9396
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9397
    wb_to_pci_addr_convert = temp_address ;
9398
end
9399
endfunction //wb_to_pci_addr_convert
9400
 
9401 45 mihad
`ifdef HOST
9402 15 mihad
task find_pci_devices ;
9403
    integer device_num ;
9404
    reg     found ;
9405
    reg [11:0] pci_ctrl_offset ;
9406
    reg ok ;
9407
    reg [31:0] data ;
9408 45 mihad
    reg [31:0] expected_data ;
9409
 
9410
    reg [5:0]  reg_num ;
9411 15 mihad
begin:main
9412 45 mihad
 
9413
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9414 15 mihad
    pci_ctrl_offset = 12'h004 ;
9415
 
9416
    // enable master & target operation
9417
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9418
 
9419
    if ( ok !== 1 )
9420
    begin
9421
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9422 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9423 15 mihad
        disable main ;
9424
    end
9425
    // find all possible devices on pci bus by performing configuration cycles
9426 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9427 15 mihad
    begin
9428
        find_device ( device_num, found ) ;
9429
 
9430
        // check pci status register - if device is not present, Received Master Abort bit must be set
9431
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9432
 
9433
        if ( (data[29] !== 0) && (found !== 0) )
9434 45 mihad
        begin
9435 15 mihad
            $display( "Time %t ", $time ) ;
9436
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9437
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9438 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9439
            ok = 0 ;
9440 15 mihad
        end
9441
 
9442
        if ( (data[29] !== 1) && (found !== 1) )
9443
        begin
9444
            $display( "Time %t ", $time ) ;
9445
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9446
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9447 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9448
            ok = 0 ;
9449 15 mihad
        end
9450
 
9451
        // clear Master Abort status if set
9452
        if ( data[29] !== 0 )
9453
        begin
9454
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9455
        end
9456 45 mihad
 
9457
        if (found === 1)
9458
        begin
9459
            // first check if found target is supposed to exist
9460
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9461
            begin
9462
                $display("Time %t", $time) ;
9463
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9464
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9465
                ok = 0 ;
9466
            end
9467
            else
9468
            begin
9469
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9470
                begin
9471
 
9472
                    data = 32'hFFFF_FFFF ;
9473
 
9474
                    expected_data = 0 ;
9475
 
9476
                    if (reg_num == 4)
9477
                    begin
9478
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9479
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9480
                    end
9481
                    else if (reg_num == 5)
9482
                    begin
9483
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9484
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9485
                    end
9486
 
9487
                    // write base address 0
9488
                    generate_configuration_cycle
9489
                    (
9490
                        'h0,            //bus_num
9491
                        device_num,     //device_num
9492
                        'h0,            //func_num
9493
                        reg_num,        //reg_num
9494
                        'h0,            //type
9495
                        4'hF,           // byte_enables
9496
                        data,           //data
9497
                        1'b1            //read0_write1
9498
                    );
9499
 
9500
                    // read data back
9501
                    generate_configuration_cycle
9502
                    (
9503
                        'h0,            //bus_num
9504
                        device_num,     //device_num
9505
                        'h0,            //func_num
9506
                        reg_num,        //reg_num
9507
                        'h0,            //type
9508
                        4'hF,           // byte_enables
9509
                        data,           //data
9510
                        1'b0            //read0_write1
9511
                    );
9512
 
9513
                    if (data !== expected_data)
9514
                    begin
9515
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9516
                        $display("Data read back not as expected!");
9517
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9518
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9519
                        ok = 0 ;
9520
                    end
9521
                end
9522
            end
9523
        end
9524 15 mihad
    end
9525 45 mihad
 
9526
    if (ok)
9527
        test_ok ;
9528 15 mihad
end //main
9529
endtask //find_pci_devices
9530
 
9531
task find_device ;
9532
    input [31:0] device_num ;
9533
    output  found ;
9534
 
9535
    reg [31:0] read_data ;
9536
begin
9537
    found = 1'b0 ;
9538
 
9539
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9540 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9541 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9542
    else
9543
    begin
9544
        $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]) ;
9545
        found = 1'b1 ;
9546
    end
9547
end
9548
endtask //find_device
9549 45 mihad
`endif
9550 15 mihad
 
9551
/*task set_bridge_parameters ;
9552
    reg [11:0] current_offset ;
9553
    reg [2:0] result ;
9554
    reg [31:0] write_data ;
9555
begin
9556
    // set burst size
9557
    // set latency timer
9558
    current_offset = 12'h00C ;
9559
    // set burst size to 16 and latency timer to 8
9560
    write_data     = {24'h0000_08, system_burst_size} ;
9561
    config_write(current_offset, write_data, 4'b1111) ;
9562
 
9563
    // set io image
9564
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9565
    write_data = 32'h0000_000_3 ;
9566
    config_write(current_offset, write_data, 4'b1111) ;
9567
 
9568
 
9569
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9570
    write_data = 32'h0001_000_1 ;
9571
    config_write(current_offset, write_data, 4'b1111) ;
9572
 
9573
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9574
    write_data = 32'hFFFF_0000 ;
9575
    config_write(current_offset, write_data, 4'b1111) ;
9576
 
9577
    // set memory image
9578
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9579
    write_data = 32'h0000_000_7 ;
9580
    config_write(current_offset, write_data, 4'b1111) ;
9581
 
9582
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9583
    write_data = 32'h0002_000_0 ;
9584
    config_write(current_offset, write_data, 4'b1111) ;
9585
 
9586
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9587
    write_data = 32'h0001_0000 ;
9588
    config_write(current_offset, write_data, 4'b1111) ;
9589
 
9590
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9591
    write_data = 32'hFFFF_0000 ;
9592
    config_write(current_offset, write_data, 4'b1111) ;
9593
 
9594
    // set parameters for bridge's target unit
9595
    // image control 0
9596
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9597
    write_data     = 32'h0000_0002 ;
9598
    config_write(current_offset, write_data, 4'b0001) ;
9599
 
9600
    // base_address 0
9601
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9602
    write_data      = 32'h2000_0000 ;
9603
    config_write(current_offset, write_data, 4'b1111) ;
9604
 
9605
    // address mask 0
9606
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9607
    write_data     = 32'hFFFF_F000 ;
9608
    config_write(current_offset, write_data, 4'b1111) ;
9609
 
9610
    // command register - enable response to io and mem space and PCI master
9611
    current_offset = 12'h004 ;
9612
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9613
    config_write(current_offset, write_data, 4'b1111) ;
9614
end
9615
endtask // set_bridge_parameters
9616
*/
9617
 
9618
task configuration_cycle_write ;
9619
    input [7:0]  bus_num ;
9620
    input [4:0]  device_num ;
9621
    input [2:0]  func_num ;
9622
    input [5:0]  reg_num ;
9623
    input [1:0]  type ;
9624
    input [3:0]  byte_enables ;
9625
    input [31:0] data ;
9626
 
9627
    reg [31:0] write_address ;
9628
    reg in_use ;
9629
    reg ok ;
9630
begin:main
9631
 
9632
    if ( in_use === 1 )
9633
    begin
9634 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9635 15 mihad
        disable main ;
9636
    end
9637
 
9638 45 mihad
    if ( (device_num > 20) && (type === 0) )
9639 15 mihad
    begin
9640
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9641
        disable main ;
9642
    end
9643
 
9644
    in_use = 1 ;
9645
 
9646 45 mihad
 
9647
`ifdef HOST
9648
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9649
`else
9650
`ifdef GUEST
9651
 
9652 15 mihad
    if ( type )
9653
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9654
    else
9655
    begin
9656
        write_address = 0 ;
9657
        write_address[10:0] = { func_num, reg_num, type } ;
9658
        write_address[11 + device_num] = 1'b1 ;
9659
    end
9660 45 mihad
 
9661
    fork
9662 15 mihad
    begin
9663 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9664
                            write_address,
9665
                            data, ~byte_enables,
9666
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9667
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9668
        do_pause(1) ;
9669 15 mihad
    end
9670 45 mihad
    begin
9671
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9672
    end
9673
    join
9674
`endif
9675
`endif
9676
 
9677
    in_use = 0 ;
9678
end
9679
endtask // configuration_cycle_write
9680 15 mihad
 
9681 45 mihad
task configuration_cycle_read ;
9682
    input [7:0]  bus_num ;
9683
    input [4:0]  device_num ;
9684
    input [2:0]  func_num ;
9685
    input [5:0]  reg_num ;
9686
    input [1:0]  type ;
9687
    input [3:0]  byte_enables ;
9688
    output [31:0] data ;
9689 15 mihad
 
9690 45 mihad
    reg [31:0] read_address ;
9691
    reg in_use ;
9692 15 mihad
 
9693 45 mihad
    reg master_check_data_prev ;
9694
begin:main
9695 15 mihad
 
9696 45 mihad
    if ( in_use === 1 )
9697 15 mihad
    begin
9698 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9699
        data = 32'hxxxx_xxxx ;
9700
        disable main ;
9701 15 mihad
    end
9702
 
9703 45 mihad
    in_use = 1 ;
9704 15 mihad
 
9705 45 mihad
`ifdef HOST
9706
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9707
`else
9708
`ifdef GUEST
9709
     master_check_data_prev = master1_check_received_data ;
9710 15 mihad
     if ( type )
9711 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9712 15 mihad
     else
9713
     begin
9714 45 mihad
         read_address = 0 ;
9715
         read_address[10:0] = { func_num, reg_num, type } ;
9716
         read_address[11 + device_num] = 1'b1 ;
9717 15 mihad
     end
9718 45 mihad
 
9719
     fork
9720
     begin
9721
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9722
                 read_address,
9723 15 mihad
                 data, ~byte_enables,
9724
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9725
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9726 45 mihad
         do_pause(1) ;
9727
     end
9728
     begin
9729
         @(master1_received_data_valid) ;
9730
         data = master1_received_data ;
9731
     end
9732
     join
9733 15 mihad
 
9734 45 mihad
    master1_check_received_data = master_check_data_prev ;
9735
`endif
9736
`endif
9737
 
9738 15 mihad
    in_use = 0 ;
9739
 
9740 45 mihad
end //main
9741
endtask // configuration_cycle_read
9742
 
9743
`ifdef HOST
9744
task generate_configuration_cycle ;
9745 15 mihad
    input [7:0]  bus_num ;
9746
    input [4:0]  device_num ;
9747
    input [2:0]  func_num ;
9748
    input [5:0]  reg_num ;
9749
    input [1:0]  type ;
9750
    input [3:0]  byte_enables ;
9751 45 mihad
    inout [31:0] data ;
9752
    input        read0_write1 ;
9753 15 mihad
 
9754
    reg `READ_STIM_TYPE read_data ;
9755
    reg `WB_TRANSFER_FLAGS  flags ;
9756
    reg `READ_RETURN_TYPE   read_status ;
9757
 
9758
    reg `WRITE_STIM_TYPE   write_data ;
9759
    reg `WRITE_RETURN_TYPE write_status ;
9760
 
9761 45 mihad
    reg [31:0] pci_address ;
9762 15 mihad
    reg in_use ;
9763 45 mihad
    reg ok ;
9764 15 mihad
 
9765
    reg [31:0] temp_var ;
9766
begin:main
9767
 
9768
    if ( in_use === 1 )
9769
    begin
9770 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
9771 15 mihad
        data = 32'hxxxx_xxxx ;
9772
        disable main ;
9773
    end
9774
 
9775 45 mihad
    in_use = 1 ;
9776
 
9777
    if ( type )
9778
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9779
    else
9780 15 mihad
    begin
9781 45 mihad
        pci_address = 0 ;
9782
        pci_address[10:0] = { func_num, reg_num, type } ;
9783
        if (device_num <= 20)
9784
            pci_address[11 + device_num] = 1'b1 ;
9785
    end
9786
 
9787
    // setup flags
9788
    flags = 0 ;
9789
    flags`INIT_WAITS   = tb_init_waits ;
9790
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
9791
 
9792
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9793
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9794
 
9795
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9796
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9797
    write_data`WRITE_SEL      = 4'hF ;
9798
    write_data`WRITE_TAG_STIM = 0 ;
9799
 
9800
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9801
 
9802
    // check if write succeeded
9803
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9804
    begin
9805
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9806 15 mihad
        data = 32'hxxxx_xxxx ;
9807 45 mihad
        in_use = 0 ;
9808 15 mihad
        disable main ;
9809
    end
9810
 
9811 45 mihad
    // setup flags for wb master to handle retries and read and write data
9812
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9813
 
9814
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9815
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
9816
    read_data`READ_SEL          = byte_enables ;
9817
    write_data`WRITE_SEL        = byte_enables ;
9818
    read_data`READ_TAG_STIM     = 0 ;
9819
    write_data`WRITE_TAG_STIM   = 0 ;
9820
    write_data`WRITE_DATA       = data ;
9821
 
9822
    ok = 0 ;
9823
 
9824
    fork
9825
    begin
9826
        if (read0_write1 === 0)
9827
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
9828
        else
9829
        if (read0_write1 === 1)
9830
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
9831
    end
9832
    begin
9833
        pci_transaction_progress_monitor
9834
        (
9835
            pci_address,                                            // expected address on PCI bus
9836
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
9837
            1,                                                      // expected number of succesfull data phases
9838
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9839
            1'b0,                                                   // monitor checking/not checking number of transfers
9840
            1'b0,                                                   // monitor checking/not checking number of cycles
9841
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9842
            ok                                                      // status - 1 success, 0 failure
9843
        ) ;
9844
    end
9845
    join
9846
 
9847
    // check if transfer succeeded
9848
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
9849
    begin
9850
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
9851
        data = 32'hxxxx_xxxx ;
9852
        in_use = 0 ;
9853
        disable main ;
9854
    end
9855
 
9856
    if (!ok)
9857
    begin
9858
        data = 32'hxxxx_xxxx ;
9859
        in_use = 0 ;
9860
        disable main ;
9861
    end
9862
 
9863
    if (read0_write1 === 0)
9864
        data = read_status`READ_DATA ;
9865
 
9866
    in_use = 0 ;
9867
end
9868
endtask // generate_configuration_cycle
9869
 
9870
task test_configuration_cycle_target_abort ;
9871
    reg `READ_STIM_TYPE read_data ;
9872
    reg `WB_TRANSFER_FLAGS  flags ;
9873
    reg `READ_RETURN_TYPE   read_status ;
9874
 
9875
    reg `WRITE_STIM_TYPE   write_data ;
9876
    reg `WRITE_RETURN_TYPE write_status ;
9877
 
9878
    reg [31:0] pci_address ;
9879
    reg in_use ;
9880
    reg ok_pci ;
9881
    reg ok_wb  ;
9882
    reg ok     ;
9883
 
9884
    reg [31:0] temp_var ;
9885
 
9886
begin:main
9887
 
9888
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
9889
 
9890
    if ( in_use === 1 )
9891
    begin
9892
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
9893
        disable main ;
9894
    end
9895
 
9896 15 mihad
    in_use = 1 ;
9897
 
9898 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
9899
 
9900 15 mihad
    // setup flags
9901
    flags = 0 ;
9902 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
9903
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
9904 15 mihad
 
9905
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9906
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9907
 
9908
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9909 45 mihad
    temp_var                  = 0 ;
9910
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
9911
    write_data`WRITE_DATA     = temp_var ;
9912 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
9913
    write_data`WRITE_TAG_STIM = 0 ;
9914
 
9915
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9916
 
9917
    // check if write succeeded
9918
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9919
    begin
9920
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9921 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
9922
        in_use = 0 ;
9923 15 mihad
        disable main ;
9924
    end
9925
 
9926 45 mihad
    // setup flags for wb master to handle retries and read and write data
9927 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9928
 
9929 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9930
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9931 15 mihad
 
9932 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9933
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
9934
    read_data`READ_SEL          = 4'hF ;
9935
    write_data`WRITE_SEL        = 4'hF ;
9936
    read_data`READ_TAG_STIM     = 0 ;
9937
    write_data`WRITE_TAG_STIM   = 0 ;
9938
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
9939
 
9940
    ok_pci = 0 ;
9941
    ok_wb  = 1 ;
9942
 
9943
    // set target to terminate with target abort
9944
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
9945
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
9946
    fork
9947
    begin
9948
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
9949
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
9950
        begin
9951
            $display("Time %t", $time) ;
9952
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
9953
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
9954
            ok_wb = 0 ;
9955
        end
9956
 
9957
        config_read( 12'h4, 4'hF, temp_var ) ;
9958
        if ( temp_var[29] !== 0 )
9959
        begin
9960
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
9961
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
9962
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
9963
            ok_wb = 0 ;
9964
        end
9965
 
9966
        if ( temp_var[28] !== 1 )
9967
        begin
9968
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
9969
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
9970
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
9971
            ok_wb = 0 ;
9972
        end
9973
 
9974
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
9975
 
9976
        if (ok !== 1)
9977
        begin
9978
            ok_wb = 0 ;
9979
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
9980
            $display("Write to PCI Device Status Register failed") ;
9981
            test_fail("Write to PCI Device Status Register failed") ;
9982
        end
9983
 
9984
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
9985
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
9986
        begin
9987
            $display("Time %t", $time) ;
9988
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
9989
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
9990
            ok_wb = 0 ;
9991
        end
9992
 
9993
        config_read( 12'h4, 4'hF, temp_var ) ;
9994
        if ( temp_var[29] !== 0 )
9995
        begin
9996
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
9997
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
9998
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
9999
            ok_wb = 0 ;
10000
        end
10001
 
10002
        if ( temp_var[28] !== 1 )
10003
        begin
10004
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10005
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10006
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10007
            ok_wb = 0 ;
10008
        end
10009
 
10010
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10011
 
10012
        if (ok !== 1)
10013
        begin
10014
            ok_wb = 0 ;
10015
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10016
            $display("Write to PCI Device Status Register failed") ;
10017
            test_fail("Write to PCI Device Status Register failed") ;
10018
        end
10019
    end
10020
    begin
10021
        pci_transaction_progress_monitor
10022
        (
10023
            pci_address,                                            // expected address on PCI bus
10024
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10025
            0,                                                      // expected number of succesfull data phases
10026
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10027
            1'b1,                                                   // monitor checking/not checking number of transfers
10028
            1'b0,                                                   // monitor checking/not checking number of cycles
10029
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10030
            ok_pci                                                  // status - 1 success, 0 failure
10031
        ) ;
10032
 
10033
        if (ok_pci)
10034
        begin
10035
            pci_transaction_progress_monitor
10036
            (
10037
                pci_address,                                            // expected address on PCI bus
10038
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10039
                0,                                                      // expected number of succesfull data phases
10040
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10041
                1'b1,                                                   // monitor checking/not checking number of transfers
10042
                1'b0,                                                   // monitor checking/not checking number of cycles
10043
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10044
                ok_pci                                                  // status - 1 success, 0 failure
10045
            ) ;
10046
        end
10047
 
10048
        if (!ok_pci)
10049
        begin
10050
            $display("Time %t", $time) ;
10051
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10052
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10053
        end
10054
    end
10055
    join
10056
 
10057
    if (ok_pci && ok_wb)
10058
    begin
10059
        test_ok ;
10060
    end
10061
 
10062
    in_use = 0 ;
10063
 
10064
    // set target to terminate normally
10065
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10066
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10067
end
10068
endtask // test_configuration_cycle_target_abort
10069
 
10070
task test_configuration_cycle_type1_generation ;
10071
    reg `READ_STIM_TYPE read_data ;
10072
    reg `WB_TRANSFER_FLAGS  flags ;
10073
    reg `READ_RETURN_TYPE   read_status ;
10074
 
10075
    reg `WRITE_STIM_TYPE   write_data ;
10076
    reg `WRITE_RETURN_TYPE write_status ;
10077
 
10078
    reg [31:0] pci_address ;
10079
    reg in_use ;
10080
    reg ok_pci ;
10081
    reg ok_wb  ;
10082
    reg ok     ;
10083
 
10084
    reg [31:0] temp_var ;
10085
 
10086
begin:main
10087
 
10088
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10089
    conf_cyc_type1_target_data = 0 ;
10090
    conf_cyc_type1_target_bus_num = 0;
10091
 
10092
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10093
 
10094
    if ( in_use === 1 )
10095
    begin
10096
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10097
        disable main ;
10098
    end
10099
 
10100
    in_use = 1 ;
10101
 
10102
    pci_address        = 32'hAAAA_AAAA ;
10103
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10104
 
10105
    // setup flags
10106
    flags = 0 ;
10107
    flags`INIT_WAITS   = tb_init_waits ;
10108
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10109
 
10110
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10111
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10112
 
10113
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10114
    write_data`WRITE_DATA     = pci_address ;
10115
    write_data`WRITE_SEL      = 4'hF ;
10116
    write_data`WRITE_TAG_STIM = 0 ;
10117
 
10118
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10119
 
10120
    // check if write succeeded
10121
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10122
    begin
10123
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10124
        test_fail("write to configuration cycle address register was not possible") ;
10125
        in_use = 0 ;
10126
        disable main ;
10127
    end
10128
 
10129
    // setup flags for wb master to handle retries and read and write data
10130
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10131
 
10132
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10133
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10134
 
10135
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10136
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10137
    read_data`READ_SEL          = 4'hF ;
10138
    write_data`WRITE_SEL        = 4'hF ;
10139
    read_data`READ_TAG_STIM     = 0 ;
10140
    write_data`WRITE_TAG_STIM   = 0 ;
10141
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10142
 
10143
    ok_pci = 0 ;
10144
    ok_wb  = 1 ;
10145
 
10146
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10147
    pci_address[31:24] = 0 ;
10148
    fork
10149
    begin
10150
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10151
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10152
        begin
10153
            $display("Time %t", $time) ;
10154
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10155
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10156
            ok_wb = 0 ;
10157
        end
10158
 
10159
        config_read( 12'h4, 4'hF, temp_var ) ;
10160
        if ( temp_var[29] !== 1 )
10161
        begin
10162
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10163
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10164
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10165
            ok_wb = 0 ;
10166
        end
10167
 
10168
        if ( temp_var[28] !== 0 )
10169
        begin
10170
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10171
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10172
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10173
            ok_wb = 0 ;
10174
        end
10175
 
10176
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10177
 
10178
        if (ok !== 1)
10179
        begin
10180
            ok_wb = 0 ;
10181
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10182
            $display("Write to PCI Device Status Register failed") ;
10183
            test_fail("Write to PCI Device Status Register failed") ;
10184
        end
10185
 
10186
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10187
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10188
        begin
10189
            $display("Time %t", $time) ;
10190
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10191
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10192
            ok_wb = 0 ;
10193
        end
10194
 
10195
        config_read( 12'h4, 4'hF, temp_var ) ;
10196
        if ( temp_var[29] !== 1 )
10197
        begin
10198
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10199
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10200
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10201
            ok_wb = 0 ;
10202
        end
10203
 
10204
        if ( temp_var[28] !== 0 )
10205
        begin
10206
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10207
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10208
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10209
            ok_wb = 0 ;
10210
        end
10211
 
10212
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10213
 
10214
        if (ok !== 1)
10215
        begin
10216
            ok_wb = 0 ;
10217
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10218
            $display("Write to PCI Device Status Register failed") ;
10219
            test_fail("Write to PCI Device Status Register failed") ;
10220
        end
10221
    end
10222
    begin
10223
        pci_transaction_progress_monitor
10224
        (
10225
            pci_address,                                            // expected address on PCI bus
10226
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10227
            0,                                                      // expected number of succesfull data phases
10228
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10229
            1'b1,                                                   // monitor checking/not checking number of transfers
10230
            1'b0,                                                   // monitor checking/not checking number of cycles
10231
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10232
            ok_pci                                                  // status - 1 success, 0 failure
10233
        ) ;
10234
 
10235
        if (ok_pci)
10236
        begin
10237
            pci_transaction_progress_monitor
10238
            (
10239
                pci_address,                                            // expected address on PCI bus
10240
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10241
                0,                                                      // expected number of succesfull data phases
10242
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10243
                1'b1,                                                   // monitor checking/not checking number of transfers
10244
                1'b0,                                                   // monitor checking/not checking number of cycles
10245
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10246
                ok_pci                                                  // status - 1 success, 0 failure
10247
            ) ;
10248
        end
10249
 
10250
        if (!ok_pci)
10251
        begin
10252
            $display("Time %t", $time) ;
10253
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10254
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10255
        end
10256
    end
10257
    join
10258
 
10259
    if (ok_pci && ok_wb)
10260
    begin
10261
        test_ok ;
10262
    end
10263
 
10264
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10265
    conf_cyc_type1_target_data = 0 ;
10266
    conf_cyc_type1_target_bus_num = 8'h55;
10267
 
10268
    pci_address      = 32'h5555_5555 ;
10269
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10270
 
10271
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10272
 
10273
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10274
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10275
 
10276
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10277
    write_data`WRITE_DATA     = pci_address ;
10278
    write_data`WRITE_SEL      = 4'hF ;
10279
    write_data`WRITE_TAG_STIM = 0 ;
10280
 
10281
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10282
 
10283
    // check if write succeeded
10284
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10285
    begin
10286
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10287
        test_fail("write to configuration cycle address register was not possible") ;
10288
        in_use = 0 ;
10289
        disable main ;
10290
    end
10291
 
10292
    // setup flags for wb master to handle retries and read and write data
10293
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10294
 
10295
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10296
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10297
 
10298
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10299
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10300
    read_data`READ_SEL          = 4'hF ;
10301
    write_data`WRITE_SEL        = 4'hF ;
10302
    read_data`READ_TAG_STIM     = 0 ;
10303
    write_data`WRITE_TAG_STIM   = 0 ;
10304
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10305
 
10306
    ok_pci = 0 ;
10307
    ok_wb  = 1 ;
10308
 
10309
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10310
    pci_address[31:24] = 0 ;
10311
    fork
10312
    begin
10313
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10314
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10315
        begin
10316
            $display("Time %t", $time) ;
10317
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10318
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10319
            ok_wb = 0 ;
10320
        end
10321
 
10322
        config_read( 12'h4, 4'hF, temp_var ) ;
10323
        if ( temp_var[29] !== 0 )
10324
        begin
10325
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10326
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10327
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10328
            ok_wb = 0 ;
10329
        end
10330
 
10331
        if ( temp_var[28] !== 1 )
10332
        begin
10333
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10334
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10335
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10336
            ok_wb = 0 ;
10337
        end
10338
 
10339
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10340
 
10341
        if (ok !== 1)
10342
        begin
10343
            ok_wb = 0 ;
10344
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10345
            $display("Write to PCI Device Status Register failed") ;
10346
            test_fail("Write to PCI Device Status Register failed") ;
10347
        end
10348
 
10349
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10350
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10351
        begin
10352
            $display("Time %t", $time) ;
10353
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10354
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10355
            ok_wb = 0 ;
10356
        end
10357
 
10358
        config_read( 12'h4, 4'hF, temp_var ) ;
10359
        if ( temp_var[29] !== 0 )
10360
        begin
10361
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10362
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10363
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10364
            ok_wb = 0 ;
10365
        end
10366
 
10367
        if ( temp_var[28] !== 1 )
10368
        begin
10369
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10370
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10371
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10372
            ok_wb = 0 ;
10373
        end
10374
 
10375
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10376
 
10377
        if (ok !== 1)
10378
        begin
10379
            ok_wb = 0 ;
10380
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10381
            $display("Write to PCI Device Status Register failed") ;
10382
            test_fail("Write to PCI Device Status Register failed") ;
10383
        end
10384
    end
10385
    begin
10386
        pci_transaction_progress_monitor
10387
        (
10388
            pci_address,                                            // expected address on PCI bus
10389
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10390
            0,                                                      // expected number of succesfull data phases
10391
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10392
            1'b1,                                                   // monitor checking/not checking number of transfers
10393
            1'b0,                                                   // monitor checking/not checking number of cycles
10394
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10395
            ok_pci                                                  // status - 1 success, 0 failure
10396
        ) ;
10397
 
10398
        if (ok_pci)
10399
        begin
10400
            pci_transaction_progress_monitor
10401
            (
10402
                pci_address,                                            // expected address on PCI bus
10403
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10404
                0,                                                      // expected number of succesfull data phases
10405
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10406
                1'b1,                                                   // monitor checking/not checking number of transfers
10407
                1'b0,                                                   // monitor checking/not checking number of cycles
10408
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10409
                ok_pci                                                  // status - 1 success, 0 failure
10410
            ) ;
10411
        end
10412
 
10413
        if (!ok_pci)
10414
        begin
10415
            $display("Time %t", $time) ;
10416
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10417
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10418
        end
10419
    end
10420
    join
10421
 
10422
    if (ok_pci && ok_wb)
10423
    begin
10424
        test_ok ;
10425
    end
10426
 
10427
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10428
 
10429
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10430
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10431
    conf_cyc_type1_target_bus_num = 8'hAA;
10432
 
10433
    pci_address      = 32'hAAAA_AAAA ;
10434
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10435
 
10436
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10437
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10438
 
10439
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10440
    write_data`WRITE_DATA     = pci_address ;
10441
    write_data`WRITE_SEL      = 4'hF ;
10442
    write_data`WRITE_TAG_STIM = 0 ;
10443
 
10444
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10445
 
10446
    // check if write succeeded
10447
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10448
    begin
10449
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10450
        test_fail("write to configuration cycle address register was not possible") ;
10451
        in_use = 0 ;
10452
        disable main ;
10453
    end
10454
 
10455
    // setup flags for wb master to handle retries and read and write data
10456
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10457
 
10458
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10459
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10460
 
10461
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10462
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10463
    read_data`READ_SEL          = 4'b0101 ;
10464
    write_data`WRITE_SEL        = 4'b1010 ;
10465
    read_data`READ_TAG_STIM     = 0 ;
10466
    write_data`WRITE_TAG_STIM   = 0 ;
10467
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10468
 
10469
    ok_pci = 0 ;
10470
    ok_wb  = 1 ;
10471
 
10472
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10473
    pci_address[31:24] = 0 ;
10474
 
10475
    fork
10476
    begin
10477
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10478
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10479
        begin
10480
            $display("Time %t", $time) ;
10481
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10482
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10483
            ok_wb = 0 ;
10484
        end
10485
 
10486
        config_read( 12'h4, 4'hF, temp_var ) ;
10487
        if ( temp_var[29] !== 0 )
10488
        begin
10489
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10490
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10491
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10492
            ok_wb = 0 ;
10493
        end
10494
 
10495
        if ( temp_var[28] !== 0 )
10496
        begin
10497
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10498
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10499
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10500
            ok_wb = 0 ;
10501
        end
10502
 
10503
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10504
 
10505
        if (ok !== 1)
10506
        begin
10507
            ok_wb = 0 ;
10508
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10509
            $display("Write to PCI Device Status Register failed") ;
10510
            test_fail("Write to PCI Device Status Register failed") ;
10511
        end
10512
 
10513
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10514
        begin
10515
            ok_wb = 0 ;
10516
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10517
            $display("Read Data provided by the bridge was not as expected!") ;
10518
            test_fail("Read Data provided by the bridge was not as expected") ;
10519
        end
10520
 
10521
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10522
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10523
        begin
10524
            $display("Time %t", $time) ;
10525
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10526
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10527
            ok_wb = 0 ;
10528
        end
10529
 
10530
        config_read( 12'h4, 4'hF, temp_var ) ;
10531
        if ( temp_var[29] !== 0 )
10532
        begin
10533
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10534
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10535
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10536
            ok_wb = 0 ;
10537
        end
10538
 
10539
        if ( temp_var[28] !== 0 )
10540
        begin
10541
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10542
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10543
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10544
            ok_wb = 0 ;
10545
        end
10546
 
10547
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10548
 
10549
        if (ok !== 1)
10550
        begin
10551
            ok_wb = 0 ;
10552
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10553
            $display("Write to PCI Device Status Register failed") ;
10554
            test_fail("Write to PCI Device Status Register failed") ;
10555
        end
10556
 
10557
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10558
        begin
10559
            ok_wb = 0 ;
10560
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10561
            $display("Data written by the bridge was not as expected!") ;
10562
            test_fail("Data written by the bridge was not as expected") ;
10563
        end
10564
 
10565
    end
10566
    begin
10567
        ok = 1 ;
10568
        repeat(8)
10569
        begin
10570
            pci_transaction_progress_monitor
10571
            (
10572
                pci_address,                                            // expected address on PCI bus
10573
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10574
                0,                                                      // expected number of succesfull data phases
10575
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10576
                1'b1,                                                   // monitor checking/not checking number of transfers
10577
                1'b0,                                                   // monitor checking/not checking number of cycles
10578
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10579
                ok_pci                                                  // status - 1 success, 0 failure
10580
            ) ;
10581
 
10582
            if (!ok_pci)
10583
            begin
10584
                ok = 0 ;
10585
                $display("Time %t", $time) ;
10586
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10587
            end
10588
        end
10589
 
10590
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10591
 
10592
        pci_transaction_progress_monitor
10593
        (
10594
            pci_address,                                            // expected address on PCI bus
10595
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10596
            1,                                                      // expected number of succesfull data phases
10597
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10598
            1'b1,                                                   // monitor checking/not checking number of transfers
10599
            1'b0,                                                   // monitor checking/not checking number of cycles
10600
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10601
            ok_pci                                                  // status - 1 success, 0 failure
10602
        ) ;
10603
 
10604
        if (!ok_pci)
10605
        begin
10606
            ok = 0 ;
10607
            $display("Time %t", $time) ;
10608
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10609
        end
10610
 
10611
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10612
        repeat(8)
10613
        begin
10614
            pci_transaction_progress_monitor
10615
            (
10616
                pci_address,                                            // expected address on PCI bus
10617
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10618
                0,                                                      // expected number of succesfull data phases
10619
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10620
                1'b1,                                                   // monitor checking/not checking number of transfers
10621
                1'b0,                                                   // monitor checking/not checking number of cycles
10622
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10623
                ok_pci                                                  // status - 1 success, 0 failure
10624
            ) ;
10625
 
10626
            if (!ok_pci)
10627
            begin
10628
                ok = 0 ;
10629
                $display("Time %t", $time) ;
10630
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10631
            end
10632
        end
10633
 
10634
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10635
        pci_transaction_progress_monitor
10636
        (
10637
            pci_address,                                            // expected address on PCI bus
10638
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10639
            1,                                                      // expected number of succesfull data phases
10640
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10641
            1'b1,                                                   // monitor checking/not checking number of transfers
10642
            1'b0,                                                   // monitor checking/not checking number of cycles
10643
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10644
            ok_pci                                                  // status - 1 success, 0 failure
10645
        ) ;
10646
 
10647
        if (!ok_pci)
10648
        begin
10649
            ok = 0 ;
10650
            $display("Time %t", $time) ;
10651
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10652
        end
10653
 
10654
        if (!ok)
10655
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10656
    end
10657
    join
10658
 
10659
    if (ok_pci && ok_wb)
10660
    begin
10661
        test_ok ;
10662
    end
10663
 
10664
    in_use = 0 ;
10665
end
10666
endtask // test_configuration_cycle_type1_generation
10667
`endif
10668
 
10669
task test_initial_conf_values ;
10670
    reg [11:0] register_offset ;
10671
    reg [31:0] expected_value ;
10672
    reg        failed ;
10673
`ifdef HOST
10674
    reg `READ_STIM_TYPE    read_data ;
10675
    reg `WB_TRANSFER_FLAGS flags ;
10676
    reg `READ_RETURN_TYPE  read_status ;
10677
 
10678
    reg `WRITE_STIM_TYPE   write_data ;
10679
    reg `WRITE_RETURN_TYPE write_status ;
10680
begin
10681
    failed     = 0 ;
10682
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10683
    flags      = 0 ;
10684
    read_data  = 0 ;
10685
    write_data = 0 ;
10686
 
10687
    read_data`READ_SEL = 4'hF ;
10688
 
10689
    flags`INIT_WAITS           = tb_init_waits ;
10690
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10691
 
10692
    // test MEM/IO map bit initial value in each PCI BAR
10693
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10694
 
10695
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10696
 
10697 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10698
 
10699 45 mihad
    `ifdef NO_CNF_IMAGE
10700
        `ifdef PCI_IMAGE0
10701
            if (`PCI_AM0)
10702
                expected_value = `PCI_BA0_MEM_IO ;
10703
            else
10704
                expected_value = 32'h0000_0000 ;
10705
        `else
10706
            expected_value = 32'h0000_0000 ;
10707
        `endif
10708
    `else
10709
        expected_value = 32'h0000_0000 ;
10710
    `endif
10711
 
10712 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10713
    begin
10714 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10715
        failed = 1 ;
10716 15 mihad
    end
10717 45 mihad
    else
10718
    begin
10719
        if (read_status`READ_DATA !== expected_value)
10720
        begin
10721
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10722
            failed = 1 ;
10723
        end
10724
    end
10725 15 mihad
 
10726 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10727 15 mihad
 
10728 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10729
 
10730
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10731
 
10732
    if (`PCI_AM1)
10733
        expected_value = `PCI_BA1_MEM_IO ;
10734
    else
10735
        expected_value = 32'h0000_0000 ;
10736
 
10737
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10738
    begin
10739
        test_fail("read from P_BA1 register didn't succeede") ;
10740
        failed = 1 ;
10741
    end
10742
    else
10743
    begin
10744
        if (read_status`READ_DATA !== expected_value)
10745
        begin
10746
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
10747
            failed = 1 ;
10748
        end
10749
    end
10750
 
10751
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
10752
 
10753
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10754
 
10755
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10756
 
10757
    `ifdef PCI_IMAGE2
10758
        if (`PCI_AM2)
10759
            expected_value = `PCI_BA2_MEM_IO ;
10760
        else
10761
            expected_value = 32'h0000_0000 ;
10762 15 mihad
    `else
10763 45 mihad
        expected_value = 32'h0000_0000 ;
10764
    `endif
10765 15 mihad
 
10766 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10767
    begin
10768
        test_fail("read from P_BA2 register didn't succeede") ;
10769
        failed = 1 ;
10770
    end
10771
    else
10772
    begin
10773
        if (read_status`READ_DATA !== expected_value)
10774
        begin
10775
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
10776
            failed = 1 ;
10777
        end
10778
    end
10779 15 mihad
 
10780 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
10781
 
10782
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10783
 
10784
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10785
 
10786
    `ifdef PCI_IMAGE3
10787
        if (`PCI_AM3)
10788
            expected_value = `PCI_BA3_MEM_IO ;
10789
        else
10790
            expected_value = 32'h0000_0000 ;
10791
    `else
10792
        expected_value = 32'h0000_0000 ;
10793 15 mihad
    `endif
10794 45 mihad
 
10795
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10796
    begin
10797
        test_fail("read from P_BA3 register didn't succeede") ;
10798
        failed = 1 ;
10799
    end
10800
    else
10801
    begin
10802
        if (read_status`READ_DATA !== expected_value)
10803
        begin
10804
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
10805
            failed = 1 ;
10806
        end
10807
    end
10808
 
10809
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
10810
 
10811
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10812
 
10813
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10814
 
10815
    `ifdef PCI_IMAGE4
10816
        if (`PCI_AM4)
10817
            expected_value = `PCI_BA4_MEM_IO ;
10818
        else
10819
            expected_value = 32'h0000_0000 ;
10820
    `else
10821
        expected_value = 32'h0000_0000 ;
10822 15 mihad
    `endif
10823
 
10824 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10825
    begin
10826
        test_fail("read from P_BA4 register didn't succeede") ;
10827
        failed = 1 ;
10828
    end
10829
    else
10830
    begin
10831
        if (read_status`READ_DATA !== expected_value)
10832
        begin
10833
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
10834
            failed = 1 ;
10835
        end
10836
    end
10837 15 mihad
 
10838 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
10839 15 mihad
 
10840 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10841
 
10842
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10843
 
10844
    `ifdef PCI_IMAGE5
10845
        if(`PCI_AM5)
10846
            expected_value = `PCI_BA5_MEM_IO ;
10847
        else
10848
            expected_value = 32'h0000_0000 ;
10849
    `else
10850
        expected_value = 32'h0000_0000 ;
10851
    `endif
10852
 
10853
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10854
    begin
10855
        test_fail("read from P_BA5 register didn't succeede") ;
10856
        failed = 1 ;
10857
    end
10858
    else
10859
    begin
10860
        if (read_status`READ_DATA !== expected_value)
10861
        begin
10862
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
10863
            failed = 1 ;
10864
        end
10865
    end
10866
 
10867
    // test Address Mask initial values
10868
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
10869
 
10870
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10871
 
10872
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10873
 
10874
    `ifdef NO_CNF_IMAGE
10875
        `ifdef PCI_IMAGE0
10876
            expected_value = {`PCI_AM0, 12'h000};
10877
 
10878
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10879
        `else
10880
            expected_value = 32'h0000_0000 ;
10881
        `endif
10882
    `else
10883
        expected_value = 32'hFFFF_FFFF ;
10884
 
10885
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10886
    `endif
10887
 
10888
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10889
    begin
10890
        test_fail("read from P_AM0 register didn't succeede") ;
10891
        failed = 1 ;
10892
    end
10893
    else
10894
    begin
10895
        if (read_status`READ_DATA !== expected_value)
10896
        begin
10897
            test_fail("AM0 initial value was not set as defined");
10898
            failed = 1 ;
10899
        end
10900
    end
10901
 
10902
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
10903
 
10904
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10905
 
10906
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10907
 
10908
    expected_value = {`PCI_AM1, 12'h000};
10909
 
10910
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10911
 
10912
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10913
    begin
10914
        test_fail("read from P_AM1 register didn't succeede") ;
10915
        failed = 1 ;
10916
    end
10917
    else
10918
    begin
10919
        if (read_status`READ_DATA !== expected_value)
10920
        begin
10921
            test_fail("AM1 initial value was not set as defined");
10922
            failed = 1 ;
10923
        end
10924
    end
10925
 
10926
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
10927
 
10928
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10929
 
10930
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10931
 
10932
    `ifdef PCI_IMAGE2
10933
        expected_value = {`PCI_AM2, 12'h000};
10934
 
10935
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10936
    `else
10937
        expected_value = 32'h0000_0000 ;
10938
    `endif
10939
 
10940
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10941
    begin
10942
        test_fail("read from P_AM2 register didn't succeede") ;
10943
        failed = 1 ;
10944
    end
10945
    else
10946
    begin
10947
        if (read_status`READ_DATA !== expected_value)
10948
        begin
10949
            test_fail("AM2 initial value was not set as defined");
10950
            failed = 1 ;
10951
        end
10952
    end
10953
 
10954
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
10955
 
10956
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10957
 
10958
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10959
 
10960
    `ifdef PCI_IMAGE3
10961
        expected_value = {`PCI_AM3, 12'h000};
10962
 
10963
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10964
    `else
10965
        expected_value = 32'h0000_0000 ;
10966
    `endif
10967
 
10968
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10969
    begin
10970
        test_fail("read from P_AM3 register didn't succeede") ;
10971
        failed = 1 ;
10972
    end
10973
    else
10974
    begin
10975
        if (read_status`READ_DATA !== expected_value)
10976
        begin
10977
            test_fail("AM3 initial value was not set as defined");
10978
            failed = 1 ;
10979
        end
10980
    end
10981
 
10982
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
10983
 
10984
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10985
 
10986
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10987
 
10988
    `ifdef PCI_IMAGE4
10989
        expected_value = {`PCI_AM4, 12'h000};
10990
 
10991
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10992
    `else
10993
        expected_value = 32'h0000_0000 ;
10994
    `endif
10995
 
10996
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10997
    begin
10998
        test_fail("read from P_AM4 register didn't succeede") ;
10999
        failed = 1 ;
11000
    end
11001
    else
11002
    begin
11003
        if (read_status`READ_DATA !== expected_value)
11004
        begin
11005
            test_fail("AM4 initial value was not set as defined");
11006
            failed = 1 ;
11007
        end
11008
    end
11009
 
11010
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11011
 
11012
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11013
 
11014
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11015
 
11016
    `ifdef PCI_IMAGE5
11017
        expected_value = {`PCI_AM5, 12'h000};
11018
 
11019
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11020
    `else
11021
        expected_value = 32'h0000_0000 ;
11022
    `endif
11023
 
11024
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11025
    begin
11026
        test_fail("read from P_AM5 register didn't succeede") ;
11027
        failed = 1 ;
11028
    end
11029
    else
11030
    begin
11031
        if (read_status`READ_DATA !== expected_value)
11032
        begin
11033
            test_fail("AM5 initial value was not set as defined");
11034
            failed = 1 ;
11035
        end
11036
    end
11037
 
11038
`endif
11039
 
11040
`ifdef GUEST
11041
    reg [31:0] read_data ;
11042
begin
11043
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11044
    failed    = 0 ;
11045
 
11046
    // check all images' BARs
11047
 
11048
    // BAR0
11049
    configuration_cycle_read
11050
    (
11051
        8'h00,                          // bus number [7:0]
11052
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11053
        3'h0,                           // function number [2:0]
11054
        6'h4,                           // register number [5:0]
11055
        2'h0,                           // type [1:0]
11056
        4'hF,                           // byte enables [3:0]
11057
        read_data                       // data returned from configuration read [31:0]
11058
    ) ;
11059
 
11060
    expected_value = 32'h0000_0000 ;
11061
 
11062
    if( read_data !== expected_value)
11063
    begin
11064
        test_fail("initial value of BAR0 register not as expected") ;
11065
        failed = 1 ;
11066
    end
11067
 
11068
    // BAR1
11069
    configuration_cycle_read
11070
    (
11071
        8'h00,                          // bus number [7:0]
11072
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11073
        3'h0,                           // function number [2:0]
11074
        6'h5,                           // register number [5:0]
11075
        2'h0,                           // type [1:0]
11076
        4'hF,                           // byte enables [3:0]
11077
        read_data                       // data returned from configuration read [31:0]
11078
    ) ;
11079
 
11080
    if (`PCI_AM1)
11081
        expected_value = `PCI_BA1_MEM_IO ;
11082
    else
11083
        expected_value = 32'h0000_0000 ;
11084
 
11085
    if( read_data !== expected_value)
11086
    begin
11087
        test_fail("initial value of BAR1 register not as expected") ;
11088
        failed = 1 ;
11089
    end
11090
 
11091
    // BAR2
11092
    configuration_cycle_read
11093
    (
11094
        8'h00,                          // bus number [7:0]
11095
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11096
        3'h0,                           // function number [2:0]
11097
        6'h6,                           // register number [5:0]
11098
        2'h0,                           // type [1:0]
11099
        4'hF,                           // byte enables [3:0]
11100
        read_data                       // data returned from configuration read [31:0]
11101
    ) ;
11102
 
11103
    `ifdef PCI_IMAGE2
11104
    if (`PCI_AM2)
11105
        expected_value = `PCI_BA2_MEM_IO ;
11106
    else
11107
        expected_value = 32'h0000_0000 ;
11108
    `else
11109
    expected_value = 32'h0 ;
11110
    `endif
11111
 
11112
    if( read_data !== expected_value)
11113
    begin
11114
        test_fail("initial value of BAR2 register not as expected") ;
11115
        failed = 1 ;
11116
    end
11117
 
11118
    // BAR3
11119
    configuration_cycle_read
11120
    (
11121
        8'h00,                          // bus number [7:0]
11122
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11123
        3'h0,                           // function number [2:0]
11124
        6'h7,                           // register number [5:0]
11125
        2'h0,                           // type [1:0]
11126
        4'hF,                           // byte enables [3:0]
11127
        read_data                       // data returned from configuration read [31:0]
11128
    ) ;
11129
 
11130
    `ifdef PCI_IMAGE3
11131
    if(`PCI_AM3)
11132
        expected_value = `PCI_BA3_MEM_IO ;
11133
    else
11134
        expected_value = 32'h0000_0000 ;
11135
    `else
11136
    expected_value = 32'h0 ;
11137
    `endif
11138
 
11139
    if( read_data !== expected_value)
11140
    begin
11141
        test_fail("initial value of BAR3 register not as expected") ;
11142
        failed = 1 ;
11143
    end
11144
 
11145
    // BAR4
11146
    configuration_cycle_read
11147
    (
11148
        8'h00,                          // bus number [7:0]
11149
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11150
        3'h0,                           // function number [2:0]
11151
        6'h8,                           // register number [5:0]
11152
        2'h0,                           // type [1:0]
11153
        4'hF,                           // byte enables [3:0]
11154
        read_data                       // data returned from configuration read [31:0]
11155
    ) ;
11156
 
11157
    `ifdef PCI_IMAGE4
11158
    if (`PCI_AM4)
11159
        expected_value = `PCI_BA4_MEM_IO ;
11160
    else
11161
        expected_value = 32'h0000_0000 ;
11162
    `else
11163
    expected_value = 32'h0 ;
11164
    `endif
11165
 
11166
    if( read_data !== expected_value)
11167
    begin
11168
        test_fail("initial value of BAR4 register not as expected") ;
11169
        failed = 1 ;
11170
    end
11171
 
11172
    // BAR5
11173
    configuration_cycle_read
11174
    (
11175
        8'h00,                          // bus number [7:0]
11176
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11177
        3'h0,                           // function number [2:0]
11178
        6'h9,                           // register number [5:0]
11179
        2'h0,                           // type [1:0]
11180
        4'hF,                           // byte enables [3:0]
11181
        read_data                       // data returned from configuration read [31:0]
11182
    ) ;
11183
 
11184
    `ifdef PCI_IMAGE5
11185
    if(`PCI_AM5)
11186
        expected_value = `PCI_BA5_MEM_IO ;
11187
    else
11188
        expected_value = 32'h0000_0000 ;
11189
    `else
11190
    expected_value = 32'h0 ;
11191
    `endif
11192
 
11193
    if( read_data !== expected_value)
11194
    begin
11195
        test_fail("initial value of BAR5 register not as expected") ;
11196
        failed = 1 ;
11197
    end
11198
 
11199
    // write all 1s to BAR0
11200
    read_data = 32'hFFFF_FFFF ;
11201
 
11202
    // BAR0
11203
    configuration_cycle_write
11204
    (
11205
        8'h00,                          // bus number [7:0]
11206
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11207
        3'h0,                           // function number [2:0]
11208
        6'h4,                           // register number [5:0]
11209
        2'h0,                           // type [1:0]
11210
        4'hF,                           // byte enables [3:0]
11211
        read_data                       // data to write [31:0]
11212
    ) ;
11213
 
11214
    expected_value = 32'hFFFF_FFFF ;
11215
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11216
 
11217
    configuration_cycle_read
11218
    (
11219
        8'h00,                          // bus number [7:0]
11220
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11221
        3'h0,                           // function number [2:0]
11222
        6'h4,                           // register number [5:0]
11223
        2'h0,                           // type [1:0]
11224
        4'hF,                           // byte enables [3:0]
11225
        read_data                       // data to write [31:0]
11226
    ) ;
11227
 
11228
    if ( read_data !== expected_value )
11229
    begin
11230
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11231
        failed = 1 ;
11232
    end
11233
 
11234
    // write all 1s to BAR1
11235
    read_data = 32'hFFFF_FFFF ;
11236
 
11237
    // BAR1
11238
    configuration_cycle_write
11239
    (
11240
        8'h00,                          // bus number [7:0]
11241
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11242
        3'h0,                           // function number [2:0]
11243
        6'h5,                           // register number [5:0]
11244
        2'h0,                           // type [1:0]
11245
        4'hF,                           // byte enables [3:0]
11246
        read_data                       // data to write [31:0]
11247
    ) ;
11248
 
11249
    expected_value = {`PCI_AM1, 12'h000} ;
11250
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11251
    if (`PCI_AM1)
11252
        expected_value[0] = `PCI_BA1_MEM_IO ;
11253
 
11254
    configuration_cycle_read
11255
    (
11256
        8'h00,                          // bus number [7:0]
11257
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11258
        3'h0,                           // function number [2:0]
11259
        6'h5,                           // register number [5:0]
11260
        2'h0,                           // type [1:0]
11261
        4'hF,                           // byte enables [3:0]
11262
        read_data                       // data to write [31:0]
11263
    ) ;
11264
 
11265
    if ( read_data !== expected_value )
11266
    begin
11267
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11268
        failed = 1 ;
11269
    end
11270
 
11271
    // write all 1s to BAR2
11272
    read_data = 32'hFFFF_FFFF ;
11273
 
11274
    // BAR2
11275
    configuration_cycle_write
11276
    (
11277
        8'h00,                          // bus number [7:0]
11278
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11279
        3'h0,                           // function number [2:0]
11280
        6'h6,                           // register number [5:0]
11281
        2'h0,                           // type [1:0]
11282
        4'hF,                           // byte enables [3:0]
11283
        read_data                       // data to write [31:0]
11284
    ) ;
11285
 
11286
`ifdef PCI_IMAGE2
11287
    expected_value = {`PCI_AM2, 12'h000} ;
11288
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11289
    if (`PCI_AM2)
11290
        expected_value[0] = `PCI_BA2_MEM_IO ;
11291
`else
11292
    expected_value = 0 ;
11293
`endif
11294
 
11295
    configuration_cycle_read
11296
    (
11297
        8'h00,                          // bus number [7:0]
11298
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11299
        3'h0,                           // function number [2:0]
11300
        6'h6,                           // register number [5:0]
11301
        2'h0,                           // type [1:0]
11302
        4'hF,                           // byte enables [3:0]
11303
        read_data                       // data to write [31:0]
11304
    ) ;
11305
 
11306
    if ( read_data !== expected_value )
11307
    begin
11308
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11309
        failed = 1 ;
11310
    end
11311
 
11312
    // write all 1s to BAR3
11313
    read_data = 32'hFFFF_FFFF ;
11314
 
11315
    // BAR3
11316
    configuration_cycle_write
11317
    (
11318
        8'h00,                          // bus number [7:0]
11319
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11320
        3'h0,                           // function number [2:0]
11321
        6'h7,                           // register number [5:0]
11322
        2'h0,                           // type [1:0]
11323
        4'hF,                           // byte enables [3:0]
11324
        read_data                       // data to write [31:0]
11325
    ) ;
11326
 
11327
`ifdef PCI_IMAGE3
11328
    expected_value = {`PCI_AM3, 12'h000} ;
11329
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11330
    if(`PCI_AM3)
11331
        expected_value[0] = `PCI_BA3_MEM_IO ;
11332
`else
11333
    expected_value = 0 ;
11334
`endif
11335
 
11336
    configuration_cycle_read
11337
    (
11338
        8'h00,                          // bus number [7:0]
11339
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11340
        3'h0,                           // function number [2:0]
11341
        6'h7,                           // register number [5:0]
11342
        2'h0,                           // type [1:0]
11343
        4'hF,                           // byte enables [3:0]
11344
        read_data                       // data to write [31:0]
11345
    ) ;
11346
 
11347
    if ( read_data !== expected_value )
11348
    begin
11349
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11350
        failed = 1 ;
11351
    end
11352
 
11353
    // write all 1s to BAR4
11354
    read_data = 32'hFFFF_FFFF ;
11355
 
11356
    // BAR4
11357
    configuration_cycle_write
11358
    (
11359
        8'h00,                          // bus number [7:0]
11360
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11361
        3'h0,                           // function number [2:0]
11362
        6'h8,                           // register number [5:0]
11363
        2'h0,                           // type [1:0]
11364
        4'hF,                           // byte enables [3:0]
11365
        read_data                       // data to write [31:0]
11366
    ) ;
11367
 
11368
`ifdef PCI_IMAGE4
11369
    expected_value = {`PCI_AM4, 12'h000} ;
11370
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11371
    if(`PCI_AM4)
11372
        expected_value[0] = `PCI_BA4_MEM_IO ;
11373
`else
11374
    expected_value = 0 ;
11375
`endif
11376
 
11377
    configuration_cycle_read
11378
    (
11379
        8'h00,                          // bus number [7:0]
11380
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11381
        3'h0,                           // function number [2:0]
11382
        6'h8,                           // register number [5:0]
11383
        2'h0,                           // type [1:0]
11384
        4'hF,                           // byte enables [3:0]
11385
        read_data                       // data to write [31:0]
11386
    ) ;
11387
 
11388
    if ( read_data !== expected_value )
11389
    begin
11390
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11391
        failed = 1 ;
11392
    end
11393
 
11394
    // write all 1s to BAR5
11395
    read_data = 32'hFFFF_FFFF ;
11396
 
11397
    // BAR5
11398
    configuration_cycle_write
11399
    (
11400
        8'h00,                          // bus number [7:0]
11401
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11402
        3'h0,                           // function number [2:0]
11403
        6'h9,                           // register number [5:0]
11404
        2'h0,                           // type [1:0]
11405
        4'hF,                           // byte enables [3:0]
11406
        read_data                       // data to write [31:0]
11407
    ) ;
11408
 
11409
`ifdef PCI_IMAGE5
11410
    expected_value = {`PCI_AM5, 12'h000} ;
11411
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11412
    if(`PCI_AM5)
11413
        expected_value[0] = `PCI_BA5_MEM_IO ;
11414
`else
11415
    expected_value = 0 ;
11416
`endif
11417
 
11418
    configuration_cycle_read
11419
    (
11420
        8'h00,                          // bus number [7:0]
11421
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11422
        3'h0,                           // function number [2:0]
11423
        6'h9,                           // register number [5:0]
11424
        2'h0,                           // type [1:0]
11425
        4'hF,                           // byte enables [3:0]
11426
        read_data                       // data to write [31:0]
11427
    ) ;
11428
 
11429
    if ( read_data !== expected_value )
11430
    begin
11431
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11432
        failed = 1 ;
11433
    end
11434
`endif
11435
 
11436
    if (!failed)
11437
        test_ok ;
11438
end
11439
endtask
11440
 
11441 15 mihad
task display_warning;
11442
    input [31:0] error_address ;
11443
    input [31:0] expected_data ;
11444
    input [31:0] actual ;
11445
begin
11446
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11447
end
11448
endtask // display warning
11449
 
11450
/*############################################################################
11451
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11452
=====================
11453
############################################################################*/
11454
 
11455
// Task reslease the PCI bus for 'delay' clocks
11456
task do_pause;
11457
  input  [15:0] delay;
11458
  reg    [15:0] cnt;
11459
  begin
11460
    test_start <= 1'b0;  // no device is allowed to take this
11461
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11462
    begin
11463
      if (~pci_reset_comb)
11464
      begin
11465
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11466
      end
11467
      `NO_ELSE;
11468
    end
11469
  end
11470
endtask // do_pause
11471
 
11472
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11473
task DO_REF;
11474
  input  [79:0] name;
11475
  input  [2:0] master_number;
11476
  input  [PCI_BUS_DATA_RANGE:0] address;
11477
  input  [3:0] command;
11478
  input  [PCI_BUS_DATA_RANGE:0] data;
11479
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11480
  input  [9:0] size;
11481
  input   make_addr_par_error, make_data_par_error;
11482
  input  [7:0] master_wait_states;
11483
  input  [7:0] target_wait_states;
11484
  input  [1:0] target_devsel_speed;
11485
  input   fast_back_to_back;
11486
  input  [2:0] target_termination;
11487
  input   expect_master_abort;
11488
  reg     waiting;
11489
  begin
11490
// Cautiously wait for previous command to be done
11491
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11492
    begin
11493
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11494
      begin
11495
        if (~pci_reset_comb)
11496
        begin
11497
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11498
        end
11499
        `NO_ELSE;
11500
      end
11501
      else
11502
      begin
11503
        waiting = 1'b0;  // ready to do next command
11504
      end
11505
    end
11506
    next_test_name[79:0] <= name[79:0];
11507
    test_master_number <= master_number[2:0];
11508
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11509
    test_command[3:0] <= command[3:0] ;
11510
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11511
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11512
    test_size <= size;
11513
    test_make_addr_par_error <= make_addr_par_error;
11514
    test_make_data_par_error <= make_data_par_error;
11515
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11516
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11517
    test_target_initial_wait_states <= target_wait_states[7:4];
11518
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11519
    test_target_devsel_speed <= target_devsel_speed[1:0];
11520
    test_fast_back_to_back <= fast_back_to_back;
11521
    test_target_termination <= target_termination[2:0];
11522
    test_expect_master_abort <= expect_master_abort;
11523
    test_start <= 1'b1;
11524
    if (~pci_reset_comb)
11525
    begin
11526
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11527
    end
11528
    `NO_ELSE;
11529
// wait for new command to start
11530
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11531
    begin
11532
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11533
      begin
11534
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11535
      end
11536
      else
11537
      begin
11538
        waiting = 1'b0;  // ready to do next command
11539
      end
11540
    end
11541
  end
11542
endtask // DO_REF
11543
 
11544
// Use Macros defined in pci_defines.vh as paramaters
11545
 
11546
// DO_REF (name[79:0], master_number[2:0],
11547
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11548
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11549
//          make_addr_par_error, make_data_par_error,
11550
//          master_wait_states[8:0], target_wait_states[8:0],
11551
//          target_devsel_speed[1:0], fast_back_to_back,
11552
//          target_termination[2:0],
11553
//          expect_master_abort);
11554
//
11555
// Example:
11556
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11557
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11558
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11559
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11560
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11561
 
11562
// Access a location with no high-order bits set, assuring that no device responds
11563
task PCIU_CONFIG_READ_MASTER_ABORT;
11564
  input  [79:0] name;
11565
  input  [2:0] master_number;
11566
  input  [9:0] size;
11567
  begin
11568
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11569
               PCI_COMMAND_CONFIG_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11570
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
11571
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11572
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11573
  end
11574
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11575
 
11576
// Access a location with no high-order bits set, assuring that no device responds
11577
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11578
  input  [79:0] name;
11579
  input  [2:0] master_number;
11580
  input  [9:0] size;
11581
  begin
11582
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11583
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11584
              `Test_Addr_Perr, `Test_Data_Perr, `Test_One_Zero_Master_WS,
11585
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11586
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11587
  end
11588
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11589
 
11590
// Access a location with no high-order bits set, assuring that no device responds
11591
task PCIU_MEM_READ_MASTER_ABORT;
11592
  input  [79:0] name;
11593
  input  [2:0] master_number;
11594
  input  [9:0] size;
11595
  begin
11596
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11597
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11598
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11599
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11600
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11601
  end
11602
endtask // PCIU_MEM_READ_MASTER_ABORT
11603
 
11604
// Access a location with no high-order bits set, assuring that no device responds
11605
task PCIU_MEM_WRITE_MASTER_ABORT;
11606
  input  [79:0] name;
11607
  input  [2:0] master_number;
11608
  input  [9:0] size;
11609
  begin
11610
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11611
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11612
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11613
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11614
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11615
  end
11616
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11617
 
11618
// Do variable length transfers with various paramaters
11619
task PCIU_CONFIG_READ;
11620
  input  [79:0] name;
11621
  input  [2:0] master_number;
11622
  input  [PCI_BUS_DATA_RANGE:0] address;
11623
  input  [PCI_BUS_DATA_RANGE:0] data;
11624
  input  [3:0] be ;
11625
  input  [9:0] size;
11626
  input  [7:0] master_wait_states;
11627
  input  [7:0] target_wait_states;
11628
  input  [1:0] target_devsel_speed;
11629
  input  [2:0] target_termination;
11630
  begin
11631
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11632
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11633
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11634
              8'h0_0, target_wait_states[7:0],
11635
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11636
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11637
  end
11638
endtask // PCIU_CONFIG_READ
11639
 
11640
task PCIU_CONFIG_WRITE;
11641
  input  [79:0] name;
11642
  input  [2:0] master_number;
11643
  input  [PCI_BUS_DATA_RANGE:0] address;
11644
  input  [PCI_BUS_DATA_RANGE:0] data;
11645
  input  [3:0] be ;
11646
  input  [9:0] size;
11647
  input  [7:0] master_wait_states;
11648
  input  [7:0] target_wait_states;
11649
  input  [1:0] target_devsel_speed;
11650
  input  [2:0] target_termination;
11651
  begin
11652
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11653
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11654
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11655
              8'h0_0, target_wait_states[7:0],
11656
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11657
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11658
  end
11659
endtask // PCIU_CONFIG_WRITE
11660
 
11661
task PCIU_READ;
11662
  input  [2:0] master_number;
11663
  input  [PCI_BUS_DATA_RANGE:0] address;
11664
  input  [3:0] command;
11665
  input  [PCI_BUS_DATA_RANGE:0] data;
11666
  input  [3:0] byte_en;
11667
  input  [9:0] size;
11668
  input  [7:0] master_wait_states;
11669
  input  [7:0] target_wait_states;
11670
  input  [1:0] target_devsel_speed;
11671
  input  [2:0] target_termination;
11672
  reg    [79:0] name;
11673
  begin
11674
    if (command == `BC_MEM_READ)
11675
        name = "MEM_READ  " ;
11676
    else if (command == `BC_MEM_READ_LN)
11677
        name = "MEM_RD_LN " ;
11678
    else if (command == `BC_MEM_READ_MUL )
11679
        name = "MEM_RD_MUL" ;
11680
    else
11681
        name = "WRONG_READ" ;
11682
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11683
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11684
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11685
              8'h0_0, target_wait_states[7:0],
11686
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11687
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11688
  end
11689
endtask // PCIU_READ
11690
 
11691
task PCIU_MEM_READ;
11692
  input  [79:0] name;
11693
  input  [2:0] master_number;
11694
  input  [PCI_BUS_DATA_RANGE:0] address;
11695
  input  [PCI_BUS_DATA_RANGE:0] data;
11696
  input  [9:0] size;
11697
  input  [7:0] master_wait_states;
11698
  input  [7:0] target_wait_states;
11699
  input  [1:0] target_devsel_speed;
11700
  input  [2:0] target_termination;
11701
  begin
11702
 
11703
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11704
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11705
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11706
              8'h0_0, target_wait_states[7:0],
11707
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11708
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11709
  end
11710
endtask // PCIU_MEM_READ
11711
 
11712
task PCIU_IO_READ;
11713
  input  [2:0] master_number;
11714
  input  [PCI_BUS_DATA_RANGE:0] address;
11715
  input  [PCI_BUS_DATA_RANGE:0] data;
11716
  input  [3:0] byte_en ;
11717
  input  [9:0] size;
11718
  input  [2:0] target_termination ;
11719
  begin
11720
 
11721
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11722
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11723
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11724
              8'h0_0, `Test_One_Zero_Target_WS,
11725
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11726
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11727
  end
11728
endtask // PCIU_IO_READ
11729
 
11730
task PCIU_IO_READ_MAKE_PERR;
11731
  input  [2:0] master_number;
11732
  input  [PCI_BUS_DATA_RANGE:0] address;
11733
  input  [PCI_BUS_DATA_RANGE:0] data;
11734
  input  [3:0] byte_en ;
11735
  input  [9:0] size;
11736
  input  [2:0] target_termination ;
11737
  begin
11738
 
11739
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11740
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11741
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11742
              8'h0_0, `Test_One_Zero_Target_WS,
11743
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11744
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11745
  end
11746
endtask // PCIU_IO_READ_MAKE_PERR
11747
 
11748
task PCIU_MEM_READ_LN;
11749
  input  [79:0] name;
11750
  input  [2:0] master_number;
11751
  input  [PCI_BUS_DATA_RANGE:0] address;
11752
  input  [PCI_BUS_DATA_RANGE:0] data;
11753
  input  [9:0] size;
11754
  input  [7:0] master_wait_states;
11755
  input  [7:0] target_wait_states;
11756
  input  [1:0] target_devsel_speed;
11757
  input  [2:0] target_termination;
11758
  begin
11759
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11760
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11761
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11762
              8'h0_0, target_wait_states[7:0],
11763
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11764
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11765
  end
11766
endtask // PCIU_MEM_READ_LN
11767
 
11768
task PCIU_MEM_READ_MUL;
11769
  input  [79:0] name;
11770
  input  [2:0] master_number;
11771
  input  [PCI_BUS_DATA_RANGE:0] address;
11772
  input  [PCI_BUS_DATA_RANGE:0] data;
11773
  input  [9:0] size;
11774
  input  [7:0] master_wait_states;
11775
  input  [7:0] target_wait_states;
11776
  input  [1:0] target_devsel_speed;
11777
  input  [2:0] target_termination;
11778
  begin
11779
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11780
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11781
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11782
              8'h0_0, target_wait_states[7:0],
11783
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11784
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11785
  end
11786
endtask // PCIU_MEM_READ_MUL
11787
 
11788
task PCIU_MEM_READ_MAKE_PERR;
11789
  input  [79:0] name;
11790
  input  [2:0] master_number;
11791
  input  [PCI_BUS_DATA_RANGE:0] address;
11792
  input  [PCI_BUS_DATA_RANGE:0] data;
11793
  input  [9:0] size;
11794
  input  [7:0] master_wait_states;
11795
  input  [7:0] target_wait_states;
11796
  input  [1:0] target_devsel_speed;
11797
  input  [2:0] target_termination;
11798
  begin
11799
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11800
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11801
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11802
              8'h0_0, target_wait_states[7:0],
11803
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11804
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11805
  end
11806
endtask // PCIU_MEM_READ_MAKE_PERR
11807
 
11808
task PCIU_MEM_WRITE;
11809
  input  [79:0] name;
11810
  input  [2:0] master_number;
11811
  input  [PCI_BUS_DATA_RANGE:0] address;
11812
  input  [PCI_BUS_DATA_RANGE:0] data;
11813
  input  [3:0] byte_en;
11814
  input  [9:0] size;
11815
  input  [7:0] master_wait_states;
11816
  input  [7:0] target_wait_states;
11817
  input  [1:0] target_devsel_speed;
11818
  input  [2:0] target_termination;
11819
  begin
11820
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11821
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11822
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11823
              8'h0_0, target_wait_states[7:0],
11824
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11825
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11826
  end
11827
endtask // PCIU_MEM_WRITE
11828
 
11829
task PCIU_IO_WRITE;
11830
  input  [2:0] master_number;
11831
  input  [PCI_BUS_DATA_RANGE:0] address;
11832
  input  [PCI_BUS_DATA_RANGE:0] data;
11833
  input  [3:0] byte_en;
11834
  input  [9:0] size;
11835
  input  [2:0] target_termination ;
11836
  begin
11837
 
11838
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11839
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11840
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11841
              8'h0_0, `Test_One_Zero_Target_WS,
11842
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11843
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11844
  end
11845
endtask // PCIU_IO_WRITE
11846
 
11847
task PCIU_IO_WRITE_MAKE_PERR ;
11848
  input  [2:0] master_number;
11849
  input  [PCI_BUS_DATA_RANGE:0] address;
11850
  input  [PCI_BUS_DATA_RANGE:0] data;
11851
  input  [3:0] byte_en;
11852
  input  [9:0] size;
11853
  input  [2:0] target_termination ;
11854
  begin
11855
 
11856
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11857
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11858
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11859
              8'h0_0, `Test_One_Zero_Target_WS,
11860
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11861
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11862
  end
11863
endtask // PCIU_IO_WRITE
11864
 
11865
task PCIU_MEM_WRITE_MAKE_SERR;
11866
  input  [79:0] name;
11867
  input  [2:0] master_number;
11868
  input  [PCI_BUS_DATA_RANGE:0] address;
11869
  input  [PCI_BUS_DATA_RANGE:0] data;
11870
  input  [9:0] size;
11871
  input  [7:0] master_wait_states;
11872
  input  [7:0] target_wait_states;
11873
  input  [1:0] target_devsel_speed;
11874
  input  [2:0] target_termination;
11875
  begin
11876
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11877
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11878
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
11879
              8'h0_0, target_wait_states[7:0],
11880
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11881
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11882
  end
11883
endtask // PCIU_MEM_WRITE_MAKE_SERR
11884
 
11885
task PCIU_MEM_WRITE_MAKE_PERR;
11886
  input  [79:0] name;
11887
  input  [2:0] master_number;
11888
  input  [PCI_BUS_DATA_RANGE:0] address;
11889
  input  [PCI_BUS_DATA_RANGE:0] data;
11890
  input  [9:0] size;
11891
  input  [7:0] master_wait_states;
11892
  input  [7:0] target_wait_states;
11893
  input  [1:0] target_devsel_speed;
11894
  input  [2:0] target_termination;
11895
  begin
11896
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11897
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11898
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11899
              8'h0_0, target_wait_states[7:0],
11900
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11901
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11902
  end
11903
endtask // PCIU_MEM_WRITE
11904
 
11905
/*--------------------------------------------------------------------------
11906
Initialization CASES
11907
--------------------------------------------------------------------------*/
11908
 
11909
// Initialize the basic Config Registers of the PCI bridge target device
11910
task configure_bridge_target;
11911
    reg [11:0] offset ;
11912
    reg [31:0] data ;
11913
    `ifdef HOST
11914
    reg `WRITE_STIM_TYPE   write_data ;
11915
    reg `WB_TRANSFER_FLAGS write_flags ;
11916
    reg `WRITE_RETURN_TYPE write_status ;
11917
    `else
11918
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
11919
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
11920
    `endif
11921
 
11922
    reg [31:0] temp_var ;
11923
begin
11924
`ifdef HOST //  set Header
11925
    offset  = 12'h4 ; // PCI Header Command register
11926
    data    = 32'h0000_0007 ; // enable master & target operation
11927
 
11928
    write_flags                      = 0 ;
11929
    write_flags`INIT_WAITS           = tb_init_waits ;
11930
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
11931
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
11932
 
11933
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
11934
    write_data`WRITE_SEL      = 4'h1 ;
11935
    write_data`WRITE_TAG_STIM = 0 ;
11936
    write_data`WRITE_DATA     = data ;
11937
 
11938
    next_test_name[79:0] <= "Init_Tar_R";
11939
 
11940
    $display(" bridge target - Enabling master and target operation!");
11941
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
11942
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
11943
    begin
11944
        $display("Write to configuration space failed! Time %t ", $time) ;
11945
    end
11946
 
11947
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
11948
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11949
 
11950
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
11951
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
11952
 
11953
    write_data`WRITE_ADDRESS  = temp_var + offset ;
11954
    write_data`WRITE_SEL      = 4'hf ;
11955
    write_data`WRITE_TAG_STIM = 0 ;
11956
    write_data`WRITE_DATA     = data ;
11957
 
11958
 `ifdef  NO_CNF_IMAGE
11959
  `ifdef PCI_IMAGE0 //      set P_BA0
11960
 
11961
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
11962
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
11963
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
11964
    begin
11965
        $display("Write to configuration space failed! Time %t ", $time) ;
11966
    end
11967
  `endif
11968
 `else //      set P_BA0
11969
 
11970
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
11971
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
11972
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
11973
    begin
11974
        $display("Write to configuration space failed! Time %t ", $time) ;
11975
    end
11976
 `endif
11977
 
11978
`else // GUEST, set Header, set P_BA0
11979
    data            = 32'h0000_0007 ; // enable master & target operation
11980
    byte_enables    = 4'hF ;
11981
    $display(" bridge target - Enabling master and target operation!");
11982 45 mihad
    configuration_cycle_write(0,                        // bus number
11983
                              `TAR0_IDSEL_INDEX - 11,   // device number
11984
                              0,                        // function number
11985
                              1,                        // register number
11986
                              0,                        // type of configuration cycle
11987
                              byte_enables,             // byte enables
11988
                              data                      // data
11989 15 mihad
                             ) ;
11990
 
11991
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
11992
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
11993
    byte_enables = 4'hf ;
11994 45 mihad
    configuration_cycle_write(0,                        // bus number
11995
                              `TAR0_IDSEL_INDEX - 11,   // device number
11996
                              0,                        // function number
11997
                              4,                        // register number
11998
                              0,                        // type of configuration cycle
11999
                              byte_enables,             // byte enables
12000
                              data                      // data
12001 15 mihad
                             ) ;
12002
 
12003
`endif
12004
end
12005
endtask // configure_bridge_target
12006
 
12007
// Initialize the basic Config Registers of the PCI bridge target device
12008
task configure_bridge_target_base_addresses;
12009
    reg [11:0] offset ;
12010
    reg [31:0] data ;
12011
    `ifdef HOST
12012
    reg `WRITE_STIM_TYPE   write_data ;
12013
    reg `WB_TRANSFER_FLAGS write_flags ;
12014
    reg `WRITE_RETURN_TYPE write_status ;
12015
    `else
12016
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12017
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12018
    `endif
12019
 
12020
    reg [31:0] temp_var ;
12021
begin
12022
`ifdef HOST //  set Header
12023
    offset  = 12'h4 ; // PCI Header Command register
12024
    data    = 32'h0000_0007 ; // enable master & target operation
12025
 
12026
    write_flags                    = 0 ;
12027
    write_flags`INIT_WAITS         = tb_init_waits ;
12028
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12029
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12030
 
12031
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12032
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12033
 
12034
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12035
    write_data`WRITE_SEL      = 4'h1 ;
12036
    write_data`WRITE_TAG_STIM = 0 ;
12037
    write_data`WRITE_DATA     = data ;
12038
 
12039
    next_test_name[79:0] <= "Init_Tar_R";
12040
 
12041
    $display(" bridge target - Enabling master and target operation!");
12042
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12043
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12044
    begin
12045
        $display("Write to configuration space failed! Time %t ", $time) ;
12046
    end
12047
 
12048
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12049
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12050
 
12051
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12052
    write_data`WRITE_SEL      = 4'hf ;
12053
    write_data`WRITE_TAG_STIM = 0 ;
12054
    write_data`WRITE_DATA     = data ;
12055
 
12056
 `ifdef  NO_CNF_IMAGE
12057
  `ifdef PCI_IMAGE0 //      set P_BA0
12058
 
12059
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12060
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12061
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12062
    begin
12063
        $display("Write to configuration space failed! Time %t ", $time) ;
12064
    end
12065
  `endif
12066
 `else //      set P_BA0
12067
 
12068
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12069
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12070
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12071
    begin
12072
        $display("Write to configuration space failed! Time %t ", $time) ;
12073
    end
12074
 `endif
12075
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12076
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12077
 
12078
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12079
    write_data`WRITE_SEL      = 4'hf ;
12080
    write_data`WRITE_TAG_STIM = 0 ;
12081
    write_data`WRITE_DATA     = data ;
12082
 
12083
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12084
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12085
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12086
    begin
12087
        $display("Write to configuration space failed! Time %t ", $time) ;
12088
    end
12089
 `ifdef PCI_IMAGE2
12090
 
12091
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12092
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12093
 
12094
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12095
    write_data`WRITE_SEL      = 4'hf ;
12096
    write_data`WRITE_TAG_STIM = 0 ;
12097
    write_data`WRITE_DATA     = data ;
12098
 
12099
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12100
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12101
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12102
    begin
12103
        $display("Write to configuration space failed! Time %t ", $time) ;
12104
    end
12105
 `endif
12106
 `ifdef PCI_IMAGE3
12107
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12108
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12109
 
12110
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12111
    write_data`WRITE_SEL      = 4'hf ;
12112
    write_data`WRITE_TAG_STIM = 0 ;
12113
    write_data`WRITE_DATA     = data ;
12114
 
12115
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12116
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12117
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12118
    begin
12119
        $display("Write to configuration space failed! Time %t ", $time) ;
12120
    end
12121
 `endif
12122
 `ifdef PCI_IMAGE4
12123
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12124
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12125
 
12126
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12127
    write_data`WRITE_SEL      = 4'hf ;
12128
    write_data`WRITE_TAG_STIM = 0 ;
12129
    write_data`WRITE_DATA     = data ;
12130
 
12131
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12132
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12133
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12134
    begin
12135
        $display("Write to configuration space failed! Time %t ", $time) ;
12136
    end
12137
 `endif
12138
 `ifdef PCI_IMAGE5
12139
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12140
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12141
 
12142
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12143
    write_data`WRITE_SEL      = 4'hf ;
12144
    write_data`WRITE_TAG_STIM = 0 ;
12145
    write_data`WRITE_DATA     = data ;
12146
 
12147
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12148
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12149
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12150
    begin
12151
        $display("Write to configuration space failed! Time %t ", $time) ;
12152
    end
12153
 `endif
12154
 
12155
`else // GUEST, set Header, set P_BA0
12156
    data            = 32'h0000_0007 ; // enable master & target operation
12157
    byte_enables    = 4'hF ;
12158
    $display(" bridge target - Enabling master and target operation!");
12159 45 mihad
    configuration_cycle_write(0,                        // bus number
12160
                              `TAR0_IDSEL_INDEX - 11,   // device number
12161
                              0,                        // function number
12162
                              1,                        // register number
12163
                              0,                        // type of configuration cycle
12164
                              byte_enables,             // byte enables
12165
                              data                      // data
12166 15 mihad
                             ) ;
12167
 
12168
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12169
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12170
    byte_enables = 4'hf ;
12171 45 mihad
    configuration_cycle_write(0,                        // bus number
12172
                              `TAR0_IDSEL_INDEX - 11,   // device number
12173
                              0,                        // function number
12174
                              4,                        // register number
12175
                              0,                        // type of configuration cycle
12176
                              byte_enables,             // byte enables
12177
                              data                      // data
12178 15 mihad
                             ) ;
12179
 
12180
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12181
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12182
    byte_enables = 4'hf ;
12183 45 mihad
    configuration_cycle_write(0,                        // bus number
12184
                              `TAR0_IDSEL_INDEX - 11,   // device number
12185
                              0,                        // function number
12186
                              5,                        // register number
12187
                              0,                        // type of configuration cycle
12188
                              byte_enables,             // byte enables
12189
                              data                      // data
12190 15 mihad
                             ) ;
12191
 `ifdef PCI_IMAGE2
12192
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12193
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12194
    byte_enables = 4'hf ;
12195 45 mihad
    configuration_cycle_write(0,                        // bus number
12196
                              `TAR0_IDSEL_INDEX - 11,   // device number
12197
                              0,                        // function number
12198
                              6,                        // register number
12199
                              0,                        // type of configuration cycle
12200
                              byte_enables,             // byte enables
12201
                              data                      // data
12202 15 mihad
                             ) ;
12203
 `endif
12204
 `ifdef PCI_IMAGE3
12205
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12206
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12207
    byte_enables = 4'hf ;
12208 45 mihad
    configuration_cycle_write(0,                        // bus number
12209
                              `TAR0_IDSEL_INDEX - 11,   // device number
12210
                              0,                        // function number
12211
                              7,                        // register number
12212
                              0,                        // type of configuration cycle
12213
                              byte_enables,             // byte enables
12214
                              data                      // data
12215 15 mihad
                             ) ;
12216
 `endif
12217
 `ifdef PCI_IMAGE4
12218
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12219
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12220
    byte_enables = 4'hf ;
12221 45 mihad
    configuration_cycle_write(0,                        // bus number
12222
                              `TAR0_IDSEL_INDEX - 11,   // device number
12223
                              0,                        // function number
12224
                              8,                        // register number
12225
                              0,                        // type of configuration cycle
12226
                              byte_enables,             // byte enables
12227
                              data                      // data
12228 15 mihad
                             ) ;
12229
 `endif
12230
 `ifdef PCI_IMAGE5
12231
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12232
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12233
    byte_enables = 4'hf ;
12234 45 mihad
    configuration_cycle_write(0,                        // bus number
12235
                              `TAR0_IDSEL_INDEX - 11,   // device number
12236
                              0,                        // function number
12237
                              9,                        // register number
12238
                              0,                        // type of configuration cycle
12239
                              byte_enables,             // byte enables
12240
                              data                      // data
12241 15 mihad
                             ) ;
12242
 `endif
12243
`endif
12244
end
12245
endtask // configure_bridge_target_base_addresses
12246
 
12247
/*--------------------------------------------------------------------------
12248
Test CASES
12249
--------------------------------------------------------------------------*/
12250
 
12251
// function converts PCI address to WB with the same data as the pci_decoder does
12252
function [31:0] pci_to_wb_addr_convert ;
12253
 
12254
    input [31:0] pci_address ;
12255
    input [31:0] translation_address ;
12256
    input [31:0] translate ;
12257
 
12258
    reg   [31:0] temp_address ;
12259
begin
12260
    if ( translate !== 1 )
12261
    begin
12262
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12263
    end
12264
    else
12265
    begin
12266
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12267
    end
12268
 
12269
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12270
    pci_to_wb_addr_convert = temp_address ;
12271
end
12272
endfunction // pci_to_wb_addr_convert
12273
 
12274
// Test normal write and read to WB slave
12275
task test_normal_wr_rd;
12276
  input  [2:0]  Master_ID;
12277
  input  [PCI_BUS_DATA_RANGE:0] Address;
12278
  input  [PCI_BUS_DATA_RANGE:0] Data;
12279
  input  [3:0]  Be;
12280
  input  [2:0]  Image_num;
12281
  input  [9:0]  Set_size;
12282
  input         Set_addr_translation;
12283
  input         Set_prefetch_enable;
12284
  input  [7:0]  Cache_lsize;
12285
  input         Set_wb_wait_states;
12286
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12287
 
12288
  reg    [31:0] rd_address;
12289
  reg    [31:0] rd_data;
12290
  reg    [3:0]  rd_be;
12291
  reg    [11:0] addr_offset;
12292
  reg    [31:0] read_data;
12293
  reg           continue ;
12294
  reg           ok   ;
12295
  reg    [31:0] expect_address ;
12296
  reg    [31:0] expect_rd_address ;
12297
  reg           expect_we ;
12298
  reg    [9:0]  expect_length_wr ;
12299
  reg    [9:0]  expect_length_rd ;
12300
  reg    [9:0]  expect_length_rd1 ;
12301
  reg    [9:0]  expect_length_rd2 ;
12302
  reg    [3:0]  use_rd_cmd ;
12303
  integer       i ;
12304 35 mihad
  reg           error_monitor_done ;
12305 15 mihad
begin:main
12306
 
12307
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12308
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12309
    $display(" - errors will be reported, but they should not occur!");
12310
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12311
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12312
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12313
    if ( ok !== 1 )
12314
    begin
12315
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12316
        test_fail("write to P_ERR_CS register didn't succeede") ;
12317
        disable main;
12318
    end
12319
 
12320
    `ifdef  ADDR_TRAN_IMPL
12321
 
12322
    // set or clear address translation
12323
    if (Set_addr_translation)
12324
    begin
12325
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12326
        $display(" - address translation will be performed!");
12327
    end
12328
    else
12329
    begin
12330
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12331
        $display(" - address translation will not be performed!");
12332
    end
12333
    // set or clear pre-fetch enable
12334
    if (Set_prefetch_enable)
12335
    begin
12336
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12337
        $display(" - bursts can be performed!");
12338
    end
12339
    else
12340
    begin
12341
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12342
        $display(" - bursts can not be performed!");
12343
    end
12344
 
12345
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12346
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12347
    if ( ok !== 1 )
12348
    begin
12349
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12350
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12351
        disable main;
12352
    end
12353
 
12354
    // predict the address and control signals on WB bus
12355
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12356
    expect_we      = 1'b1 ; // WRITE
12357
 
12358
    `else
12359
 
12360
    // address translation is not implemented
12361
    $display("Address translation is NOT implemented for PCI images!");
12362
    // set or clear pre-fetch enable
12363
    if (Set_prefetch_enable)
12364
    begin
12365
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12366
        $display(" - bursts can be performed!");
12367
    end
12368
    else
12369
    begin
12370
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12371
        $display(" - bursts can not be performed!");
12372
    end
12373
 
12374
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12375
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12376
    if ( ok !== 1 )
12377
    begin
12378
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12379
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12380
        disable main;
12381
    end
12382
 
12383
    // predict the address and control signals on WB bus
12384
    expect_address = Address ;
12385
    expect_we      = 1'b1 ; // WRITE
12386
 
12387
    `endif
12388
 
12389
    // set WB SLAVE parameters
12390
    if (Set_wb_wait_states)
12391
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12392
    else
12393
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12394
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12395
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12396
 
12397
    if ( Set_size > (`PCIW_DEPTH - 2) )
12398
    begin
12399
        expect_length_wr = `PCIW_DEPTH - 2 ;
12400
    end
12401
    else
12402
    begin
12403
        expect_length_wr = Set_size ;
12404
    end
12405
    // write through the PCI bridge to WB slave
12406
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12407
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12408
 
12409
    fork
12410
    begin
12411
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12412
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12413
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12414
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12415
        do_pause( 1 ) ;
12416
    end
12417
    begin
12418
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12419
       if ( ok !== 1 )
12420
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12421
       else
12422
           test_ok ;
12423
    end
12424
    join
12425
 
12426
    // predict the address and control signals on WB bus
12427
    expect_we      = 1'b0 ; // READ
12428
 
12429
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12430
    $display("Memory read through PCI bridge to WB slave!");
12431
 
12432
    if ( expect_length_wr == 1 )
12433
    begin
12434
        if (Set_prefetch_enable)
12435
        begin
12436
            expect_length_rd1 = Cache_lsize ;
12437
            expect_length_rd2 = 0 ;
12438
                // If PCI behavioral master must check received DATA
12439
                master2_check_received_data = 0 ;
12440
                    master1_check_received_data = 0 ;
12441
        end
12442
        else
12443
        begin
12444
            expect_length_rd1 = 1 ;
12445
            expect_length_rd2 = 0 ;
12446
                // If PCI behavioral master must check received DATA
12447
                master2_check_received_data = 1 ;
12448
                    master1_check_received_data = 1 ;
12449
        end
12450
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12451
        expect_length_rd  = expect_length_rd1 ;
12452
    end
12453
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12454
    begin
12455
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12456
        expect_length_rd2 = 0 ;
12457
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12458
        expect_length_rd  = expect_length_rd1 ;
12459
                // If PCI behavioral master must check received DATA
12460
        master2_check_received_data = 1 ;
12461
            master1_check_received_data = 1 ;
12462
    end
12463
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12464
    begin
12465
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12466
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12467
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12468
        expect_length_rd  = expect_length_rd1 ;
12469
                // If PCI behavioral master must check received DATA
12470
                master2_check_received_data = 1 ;
12471
            master1_check_received_data = 1 ;
12472
    end
12473
    else
12474
    begin
12475
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12476
        begin
12477
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12478
            expect_length_rd2 = 0 ;
12479
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12480
            expect_length_rd  = expect_length_rd1 ;
12481
                // If PCI behavioral master must check received DATA
12482
                master2_check_received_data = 0 ;
12483
                    master1_check_received_data = 0 ;
12484
        end
12485
        else
12486
        begin
12487
            if ( expect_length_wr > Cache_lsize )
12488
            begin
12489
                expect_length_rd1 = Cache_lsize ;
12490
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12491
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12492
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12493
                else
12494
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12495
                expect_length_rd  = expect_length_rd1 ;
12496
                        // If PCI behavioral master must check received DATA
12497
                        master2_check_received_data = 1 ;
12498
                            master1_check_received_data = 1 ;
12499
            end
12500
            else
12501
            begin
12502
                expect_length_rd1 = Cache_lsize ;
12503
                expect_length_rd2 = 0 ;
12504
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12505
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12506
                else
12507
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12508
                expect_length_rd  = expect_length_wr ;
12509
                                if ( expect_length_wr == Cache_lsize )
12510
                        begin
12511
                                // If PCI behavioral master must check received DATA
12512
                                master2_check_received_data = 1 ;
12513
                                    master1_check_received_data = 1 ;
12514
                                end
12515
                                else
12516
                                begin
12517
                                // If PCI behavioral master must check received DATA
12518
                                master2_check_received_data = 0 ;
12519
                                    master1_check_received_data = 0 ;
12520
                end
12521
            end
12522
        end
12523
    end
12524
 
12525
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12526
    expect_rd_address = expect_address ;
12527
    rd_data[31:0] = Data[31:0];
12528
    rd_be[3:0] = Be[3:0];
12529
 
12530
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12531
    while (expect_length_rd2 > 0)
12532
    begin
12533
        // do read
12534
        $display("Read %d words!", expect_length_rd);
12535
 
12536
        fork
12537
        begin
12538
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12539
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12540
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12541
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12542
 
12543
            wb_transaction_stop( expect_length_rd - 1) ;
12544
 
12545
            do_pause( 1 ) ;
12546
        end
12547
        begin
12548
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12549
            if ( ok !== 1 )
12550
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12551
 
12552
            repeat( 3 )
12553
                @(posedge pci_clock) ;
12554
 
12555
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12556
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12557
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12558
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12559
 
12560
            do_pause( 1 ) ;
12561
            while ( FRAME === 0 )
12562
                @(posedge pci_clock) ;
12563
 
12564
            while ( IRDY === 0 )
12565
                @(posedge pci_clock) ;
12566
 
12567 35 mihad
            #1 ;
12568
            if ( !error_monitor_done )
12569
                disable monitor_error_event1 ;
12570 15 mihad
        end
12571
        begin:monitor_error_event1
12572 35 mihad
            error_monitor_done = 0 ;
12573 15 mihad
            @(error_event_int) ;
12574
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12575
            ok = 0 ;
12576 35 mihad
            error_monitor_done = 1 ;
12577 15 mihad
        end
12578
        join
12579
 
12580
        // increasing the starting address for PCI master and for WB transaction monitor
12581
        rd_address = rd_address + (4 * expect_length_rd) ;
12582
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12583
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12584
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12585
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12586
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12587
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12588
        for (i=0; i<expect_length_rd; i=i+1)
12589
            rd_be[3:0] = {Be[2:0], Be[3]};
12590
 
12591
        // set parameters for next read
12592
        if ( expect_length_rd2 == 1 )
12593
        begin
12594
                if (Set_prefetch_enable)
12595
                begin
12596
                    expect_length_rd1 = Cache_lsize ;
12597
                    expect_length_rd2 = 0 ;
12598
                        // If PCI behavioral master must check received DATA
12599
                        master2_check_received_data = 0 ;
12600
                            master1_check_received_data = 0 ;
12601
                end
12602
                else
12603
                begin
12604
                    expect_length_rd1 = 1 ;
12605
                    expect_length_rd2 = 0 ;
12606
                        // If PCI behavioral master must check received DATA
12607
                        master2_check_received_data = 1 ;
12608
                            master1_check_received_data = 1 ;
12609
                end
12610
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12611
            expect_length_rd  = expect_length_rd1 ;
12612
        end
12613
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12614
        begin
12615
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12616
            expect_length_rd2 = 0 ;
12617
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12618
            expect_length_rd  = expect_length_rd1 ;
12619
                        // If PCI behavioral master must check received DATA
12620
                        master2_check_received_data = 1 ;
12621
                    master1_check_received_data = 1 ;
12622
        end
12623
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12624
        begin
12625
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12626
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12627
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12628
            expect_length_rd  = expect_length_rd1 ;
12629
                        // If PCI behavioral master must check received DATA
12630
                        master2_check_received_data = 1 ;
12631
                    master1_check_received_data = 1 ;
12632
        end
12633
        else
12634
        begin
12635
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12636
            begin
12637
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12638
                expect_length_rd2 = 0 ;
12639
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12640
                expect_length_rd  = expect_length_rd1 ;
12641
                        // If PCI behavioral master must check received DATA
12642
                        master2_check_received_data = 0 ;
12643
                            master1_check_received_data = 0 ;
12644
            end
12645
            else
12646
            begin
12647
                if ( expect_length_rd2 > Cache_lsize )
12648
                begin
12649
                    expect_length_rd1 = Cache_lsize ;
12650
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12651
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12652
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12653
                    else
12654
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12655
                    expect_length_rd  = expect_length_rd1 ;
12656
                                // If PCI behavioral master must check received DATA
12657
                                master2_check_received_data = 1 ;
12658
                                    master1_check_received_data = 1 ;
12659
                end
12660
                else
12661
                begin
12662
                    expect_length_rd  = expect_length_rd2 ;
12663
                    expect_length_rd1 = Cache_lsize ;
12664
                    expect_length_rd2 = 0 ;
12665
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12666
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12667
                    else
12668
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12669
                                        if ( expect_length_rd2 == Cache_lsize )
12670
                                begin
12671
                                        // If PCI behavioral master must check received DATA
12672
                                        master2_check_received_data = 1 ;
12673
                                            master1_check_received_data = 1 ;
12674
                                        end
12675
                                        else
12676
                                        begin
12677
                                        // If PCI behavioral master must check received DATA
12678
                                        master2_check_received_data = 0 ;
12679
                                            master1_check_received_data = 0 ;
12680
                        end
12681
                end
12682
            end
12683
        end
12684
    end
12685
    // do last read
12686
    $display("Read %d words!", expect_length_rd);
12687
 
12688
    fork
12689
    begin
12690
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12691
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12692
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12693
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12694
 
12695
        wb_transaction_stop(expect_length_rd - 1) ;
12696
        do_pause( 1 ) ;
12697
    end
12698
    begin
12699
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12700
 
12701
        do_pause(3) ;
12702
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12703
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12704
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12705
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12706
        do_pause(1) ;
12707
 
12708
        while ( FRAME === 0 )
12709
            @(posedge pci_clock) ;
12710
 
12711
        while ( IRDY === 0 )
12712
            @(posedge pci_clock) ;
12713
 
12714 35 mihad
        #1 ;
12715
        if ( !error_monitor_done )
12716
            disable monitor_error_event2 ;
12717 15 mihad
    end
12718
    begin:monitor_error_event2
12719 35 mihad
        error_monitor_done = 0 ;
12720 15 mihad
        @(error_event_int) ;
12721
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12722
        ok = 0 ;
12723 35 mihad
        error_monitor_done = 1 ;
12724 15 mihad
    end
12725
    join
12726
 
12727
    if ( ok )
12728
        test_ok ;
12729
 
12730
    // Check that no ERRORs were reported
12731
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12732
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
12733
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12734
    config_read( addr_offset, 4'hF, read_data ) ;
12735
    if ( read_data[8] !== 0 )
12736
    begin
12737
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
12738
        test_fail("error status was set even though no errors occured on WB bus") ;
12739
    end
12740
    else
12741
    begin
12742
        $display("No error was signaled, as expected!");
12743
        test_ok ;
12744
    end
12745
 
12746
end // main
12747
endtask // test_normal_wr_rd
12748
 
12749
// Test erroneous write to WB slave
12750
task test_wb_error_wr;
12751
  input  [2:0]  Master_ID;
12752
  input  [PCI_BUS_DATA_RANGE:0] Address;
12753
  input  [PCI_BUS_DATA_RANGE:0] Data;
12754
  input  [3:0]  Be;
12755
  input  [2:0]  Image_num;
12756
  input  [9:0]  Set_size;
12757
  input         Set_err_and_int_report;
12758
  input         Set_wb_wait_states;
12759
  input  [1:0]  Imm_BefLast_Last_error;
12760
 
12761
  reg    [11:0] addr_offset;
12762
  reg    [31:0] read_data;
12763
  reg           continue ;
12764
  reg           ok   ;
12765
  reg    [9:0]  expect_length ;
12766
  reg    [31:0] expect_address ;
12767
  reg    [0:0]  expect_we ;
12768
  reg    [31:0] rd_address;
12769
  reg    [31:0] rd_data;
12770
  reg    [3:0]  rd_be;
12771
  integer       i ;
12772
begin:main
12773
    if (Set_err_and_int_report)
12774
    begin
12775
        // enable ERROR reporting, because error must be reported and interrupt if required!
12776
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12777
        $display(" - errors will be reported when they will occur!");
12778
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
12779
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12780
        $display(" - interrupt will be reported when error will occur!");
12781
    end
12782
    else
12783
    begin
12784
        // disable ERROR reporting, because error and interrupt must not be reported!
12785
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12786
        $display(" - errors will NOT be reported when they will occur!");
12787
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
12788
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12789
        $display(" - interrupt will NOT be reported when error will occur!");
12790
    end
12791
    // enable/disable ERROR reporting
12792
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
12793
 
12794
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12795
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
12796
    if ( ok !== 1 )
12797
    begin
12798
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12799
        test_fail("PCI Error Control and Status register could not be written") ;
12800
        disable main;
12801
    end
12802
    // enable/disable INTERRUPT reporting
12803
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12804
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
12805
    if ( ok !== 1 )
12806
    begin
12807
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
12808
        test_fail("Interrupt Control register could not be written") ;
12809
        disable main;
12810
    end
12811
 
12812
    `ifdef  ADDR_TRAN_IMPL
12813
 
12814
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
12815
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12816
    config_read( addr_offset, 4'hF, read_data ) ;
12817
    if ( read_data[2] !== 0 )
12818
    begin
12819
        $display("Address translation is set for PCI image%d!", Image_num);
12820
        // predict the address and control signals on WB bus
12821
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
12822
        expect_we      = 1'b1 ; // WRITE
12823
    end
12824
    else
12825
    begin
12826
        $display("Address translation is NOT set for PCI image%d!", Image_num);
12827
        // predict the address and control signals on WB bus
12828
        expect_address = Address ;
12829
        expect_we      = 1'b1 ; // WRITE
12830
    end
12831
 
12832
    `else
12833
 
12834
    // address translation is not implemented
12835
    $display("Address translation is NOT implemented for PCI images!");
12836
    // predict the address and control signals on WB bus
12837
    expect_address = Address ;
12838
    expect_we      = 1'b1 ; // WRITE
12839
 
12840
    `endif
12841
 
12842
    if ( Set_size > (`PCIW_DEPTH - 2) )
12843
    begin
12844
        expect_length = `PCIW_DEPTH - 2 ;
12845
    end
12846
    else
12847
    begin
12848
        expect_length = Set_size ;
12849
    end
12850
 
12851
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
12852
    begin
12853
        $display("ERR termination with first data!");
12854
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
12855
    end
12856
    else if (Imm_BefLast_Last_error == 1)
12857
    begin
12858
        $display("ERR termination before last data!");
12859
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
12860
    end
12861
    else
12862
    begin
12863
        $display("ERR termination with last data!");
12864
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
12865
    end
12866
 
12867
    // write through the PCI bridge to WB slave
12868
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
12869
    fork
12870
    begin
12871
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12872
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12873
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12874
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12875
        do_pause( 1 ) ;
12876
    end
12877
    begin
12878
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
12879
        begin
12880
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
12881
            if ( ok !== 1 )
12882
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12883
        end
12884
        else if (Imm_BefLast_Last_error == 1)
12885
        begin
12886
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
12887
            if ( ok !== 1 )
12888
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12889
        end
12890
        else
12891
        begin
12892
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
12893
            if ( ok !== 1 )
12894
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12895
        end
12896
    end
12897
    begin
12898
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
12899
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12900
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12901
        else if (Imm_BefLast_Last_error == 1)
12902
        begin
12903
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12904
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12905
            wb_transaction_stop(expect_length-2) ;
12906
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12907
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12908
        end
12909
        else
12910
        begin
12911
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12912
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12913
            wb_transaction_stop(expect_length-1) ;
12914
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
12915
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
12916
        end
12917
    end
12918
    join
12919
 
12920
    if ( ok )
12921
        test_ok ;
12922
 
12923
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
12924
    begin
12925
        rd_data[31:0] = Data[31:0];
12926
        rd_address[31:0] = expect_address;
12927
        rd_be[3:0] = Be[3:0];
12928
    end
12929
    else if (Imm_BefLast_Last_error == 1)
12930
    begin
12931
        rd_data[31:24] = Data[31:24] + expect_length - 2;
12932
        rd_data[23:16] = Data[23:16] + expect_length - 2;
12933
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
12934
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
12935
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
12936
        rd_be[3:0] = Be[3:0];
12937
        for (i=0; i<(expect_length-2); i=i+1)
12938
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
12939
    end
12940
    else
12941
    begin
12942
        rd_data[31:24] = Data[31:24] + expect_length - 1;
12943
        rd_data[23:16] = Data[23:16] + expect_length - 1;
12944
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
12945
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
12946
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
12947
        rd_be[3:0] = Be[3:0];
12948
        for (i=0; i<(expect_length-1); i=i+1)
12949
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
12950
    end
12951
 
12952
    master2_check_received_data = 0 ;
12953
    master1_check_received_data = 0 ;
12954
 
12955
    // Check if ERRORs were reported
12956
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
12957
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12958
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
12959
 
12960
    ok = 1 ;
12961
    config_read( addr_offset, 4'hF, read_data ) ;
12962
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
12963
    begin
12964
        $display("Error was signaled and reported, as expected!");
12965
        if (read_data[31:28] === rd_be)
12966
            $display("Byte enables written into P_ERR_CS register are as expected!");
12967
        else
12968
        begin
12969
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
12970
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
12971
            ok = 0 ;
12972
        end
12973
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
12974
            $display("Bus command written into P_ERR_CS register is as expected!");
12975
        else
12976
        begin
12977
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
12978
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
12979
            ok = 0 ;
12980
        end
12981
 
12982
        if ( ok )
12983
            test_ok ;
12984
 
12985
        $display("Reading the PCI Error Data register P_ERR_DATA.");
12986
 
12987
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
12988
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
12989
        config_read( addr_offset, 4'hF, read_data ) ;
12990
        if (read_data === rd_data)
12991
        begin
12992
            $display("Data written into P_ERR_DATA register is as expected!");
12993
            test_ok ;
12994
        end
12995
        else
12996
        begin
12997
            $display("Data written into P_ERR_DATA register is NOT as expected!");
12998
            test_fail("PCI Erroneous Data register value was wrong") ;
12999
        end
13000
 
13001
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13002
 
13003
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13004
 
13005
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13006
        config_read( addr_offset, 4'hF, read_data ) ;
13007
        if (read_data === rd_address)
13008
        begin
13009
            $display("Address written into P_ERR_ADDR register is as expected!");
13010
            test_ok ;
13011
        end
13012
        else
13013
        begin
13014
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13015
            test_fail("PCI Erroneous Address register value was wrong") ;
13016
        end
13017
    end
13018
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13019
    begin
13020
        $display("Error was signaled and not reported, as expected!");
13021
        test_ok ;
13022
    end
13023
    else
13024
    begin
13025
        $display("Error was signaled and reported, as NOT expected!");
13026
        test_fail("Error status bit was set event though error reporting was disabled") ;
13027
    end
13028
 
13029
    // Check if Interrupts were reported
13030
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13031
 
13032
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13033
    ok = 1 ;
13034
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13035
    config_read( addr_offset, 4'hF, read_data ) ;
13036
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13037
    begin
13038
        $display("Interrupts was signaled and reported, as expected!");
13039
    end
13040
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13041
    begin
13042
        $display("Interrupts was signaled and not reported, as expected!");
13043
    end
13044
    else
13045
    begin
13046
        $display("Interrupt was signaled and reported, as NOT expected!");
13047
        test_fail("PCI Error Interrupt status was set when not expected") ;
13048
        ok = 0 ;
13049
    end
13050
 
13051
    `ifdef HOST
13052
    repeat( 4 )
13053
        @(posedge wb_clock) ;
13054
 
13055
    if ( INT_O === Set_err_and_int_report )
13056
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13057
    else
13058
    begin
13059
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13060
        test_fail("Interrupt request didn't have expected value") ;
13061
        ok = 0 ;
13062
    end
13063
 
13064
    `else // GUEST
13065
    repeat( 4 )
13066
        @(posedge pci_clock) ;
13067
 
13068
    if ( INTA === !Set_err_and_int_report )
13069
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13070
    else
13071
    begin
13072
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13073
        test_fail("Interrupt request didn't have expected value") ;
13074
        ok = 0 ;
13075
    end
13076
 
13077
    `endif
13078
 
13079
    if ( ok )
13080
        test_ok ;
13081
 
13082
    if (Set_err_and_int_report)
13083
    begin
13084
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13085
        $display("Error and Interrupt must be cleared!");
13086
        // clear  ERROR reporting bit
13087
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13088
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13089
        if ( ok !== 1 )
13090
        begin
13091
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13092
            test_fail("PCI Error Control and Status register could not be written to") ;
13093
            disable main;
13094
        end
13095
 
13096
        // clear INTERRUPT reporting bit
13097
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13098
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13099
        if ( ok !== 1 )
13100
        begin
13101
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13102
            test_fail("Interrupt Status register could not be written to") ;
13103
            disable main;
13104
        end
13105
 
13106
        test_ok ;
13107
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13108
        `ifdef HOST
13109
 
13110
        repeat(4)
13111
            @(posedge wb_clock) ;
13112
        if ( INT_O === 1'b0 )
13113
        begin
13114
            $display("Interrupt pin INT_O was correctly cleared!");
13115
            test_ok ;
13116
        end
13117
        else
13118
        begin
13119
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13120
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13121
            disable main;
13122
        end
13123
 
13124
        `else // GUEST
13125
 
13126
        repeat(4)
13127
            @(posedge pci_clock) ;
13128
        if ( INTA === 1'b1 )
13129
        begin
13130
            $display("Interrupt pin INTA was correctly cleared!");
13131
            test_ok ;
13132
        end
13133
        else
13134
        begin
13135
            $display("Interrupt pin INTA was NOT correctly cleared!");
13136
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13137
            disable main;
13138
        end
13139
 
13140
        `endif
13141
 
13142
    end
13143
    else
13144
    begin
13145
        $display("Error and Interrupt don't need to be cleared!");
13146
    end
13147
end // main
13148
endtask // test_wb_error_wr
13149
 
13150
task test_wb_error_rd;
13151
    reg    [11:0] addr_offset ;
13152
    reg    [11:0] ctrl_offset ;
13153
    reg    [11:0] ba_offset ;
13154
    reg    [11:0] am_offset ;
13155
    reg    [11:0] ta_offset ;
13156
    reg    [31:0] read_data;
13157
    reg           ok   ;
13158
    reg    [9:0]  expect_length ;
13159
    reg    [31:0] expect_address ;
13160
    reg    [0:0]  expect_we ;
13161
    reg    [31:0] rd_address;
13162
    reg    [31:0] rd_data;
13163
    reg    [3:0]  rd_be;
13164
    integer       i ;
13165
    reg           do_mem_aborts ;
13166
    reg           do_io_aborts ;
13167 35 mihad
    reg           error_monitor_done ;
13168 15 mihad
begin:main
13169
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13170
 
13171
    if ( target_mem_image !== -1 )
13172
    begin
13173
        do_mem_aborts = 1 ;
13174
 
13175
        if (target_mem_image === 1)
13176
        begin
13177
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13178
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13179
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13180
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13181
        end
13182
        else if (target_mem_image === 2)
13183
        begin
13184
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13185
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13186
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13187
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13188
        end
13189
        else if (target_mem_image === 3)
13190
        begin
13191
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13192
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13193
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13194
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13195
        end
13196
        else if (target_mem_image === 4)
13197
        begin
13198
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13199
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13200
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13201
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13202
        end
13203
        else if (target_mem_image === 5)
13204
        begin
13205
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13206
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13207
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13208
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13209
        end
13210
    end
13211
    else
13212
        do_mem_aborts = 0 ;
13213
 
13214
    if ( do_mem_aborts )
13215
    begin
13216
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13217
 
13218
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13219
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13220
        if ( ok !== 1 )
13221
        begin
13222
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13223
            test_fail("PCI Error Control and Status register could not be written") ;
13224
            disable main;
13225
        end
13226
 
13227
        // enable INTERRUPT reporting
13228
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13229
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13230
        if ( ok !== 1 )
13231
        begin
13232
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13233
            test_fail("Interrupt Control register could not be written") ;
13234
            disable main;
13235
        end
13236
 
13237
        addr_offset = 12'h010 + (4*target_mem_image) ;
13238
 
13239
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13240
        if ( ok !== 1 )
13241
        begin
13242
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13243
            test_fail("PCI Base Address register could not be written") ;
13244
            disable main;
13245
        end
13246
 
13247
        // disable address translation and enable prefetch so read bursts can be performed
13248
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13249
        if ( ok !== 1 )
13250
        begin
13251
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13252
            test_fail("PCI Image Control register could not be written") ;
13253
            disable main;
13254
        end
13255
 
13256
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13257
        if ( ok !== 1 )
13258
        begin
13259
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13260
            test_fail("PCI Address Mask register could not be written") ;
13261
            disable main;
13262
        end
13263
 
13264
        addr_offset = 12'h00C ;
13265
 
13266
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13267
        if ( ok !== 1 )
13268
        begin
13269
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13270
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13271
            disable main;
13272
        end
13273
 
13274
        // disable PCI master data checking
13275
        master1_check_received_data = 0 ;
13276
 
13277
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13278
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13279
 
13280
 
13281
        // do a single read error terminated on WB bus
13282
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13283
 
13284
        fork
13285
        begin
13286
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13287
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13288
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13289
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13290
 
13291
            do_pause( 1 ) ;
13292
        end
13293
        begin
13294
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13295
 
13296
            if ( ok !== 1 )
13297
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13298
 
13299
            do_pause(3) ;
13300
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13301
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13302
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13303
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13304
            do_pause(1) ;
13305
 
13306
            while ( FRAME === 0 )
13307
                @(posedge pci_clock) ;
13308
 
13309
            while ( IRDY === 0 )
13310
                @(posedge pci_clock) ;
13311
 
13312 35 mihad
            #1 ;
13313
            if ( !error_monitor_done )
13314
                disable monitor_error_event1 ;
13315 15 mihad
        end
13316
        begin:monitor_error_event1
13317 35 mihad
            error_monitor_done = 0 ;
13318 15 mihad
            @(error_event_int) ;
13319
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13320
            ok = 0 ;
13321 35 mihad
            error_monitor_done = 1 ;
13322 15 mihad
        end
13323
        join
13324
 
13325
        if ( ok )
13326
            test_ok ;
13327 26 mihad
 
13328
        @(posedge pci_clock) ;
13329
        @(posedge pci_clock) ;
13330
        @(posedge wb_clock) ;
13331
        @(posedge wb_clock) ;
13332 15 mihad
 
13333
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13334
        addr_offset = 12'h004 ;
13335
        config_read(addr_offset, 4'hF, read_data) ;
13336
        ok = 1 ;
13337
        if ( read_data[27] !== 1 )
13338
        begin
13339
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13340
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13341
            ok = 0 ;
13342
        end
13343
        if ( read_data[28] !== 0 )
13344
        begin
13345
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13346
            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") ;
13347
            ok = 0 ;
13348
        end
13349
        if ( read_data[29] !== 0 )
13350
        begin
13351
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13352
            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") ;
13353
            ok = 0 ;
13354
        end
13355
 
13356
        // clear statuses
13357
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13358
        if ( !ok )
13359
        begin
13360
            test_fail("write to PCI Device Status register failed") ;
13361
            $display("Couldn't write PCI Device Status register") ;
13362
            disable main ;
13363
        end
13364
 
13365
        if ( ok )
13366
            test_ok ;
13367
 
13368
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13369
 
13370
        ok = 1 ;
13371
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13372
 
13373
        config_read(addr_offset, 4'hF, read_data) ;
13374
        if (read_data[8] !== 0)
13375
        begin
13376
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13377
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13378
            ok = 0 ;
13379
        end
13380
        else
13381
            test_ok ;
13382
 
13383
        if ( ok !== 1 )
13384
        begin
13385
            config_write(addr_offset, read_data, 4'hF, ok) ;
13386
            if ( !ok )
13387
            begin
13388
                test_fail("PCI Error Control and Status register could not be written") ;
13389
                disable main ;
13390
            end
13391
        end
13392
 
13393
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13394
        fork
13395
        begin
13396
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13397
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13398
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13399
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13400
 
13401
            do_pause( 1 ) ;
13402
        end
13403
        begin
13404
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13405
 
13406
            if ( ok !== 1 )
13407
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13408
 
13409
            do_pause(3) ;
13410
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13411
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13412
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13413
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13414
            do_pause(1) ;
13415
 
13416
            while ( FRAME === 0 )
13417
                @(posedge pci_clock) ;
13418
 
13419
            while ( IRDY === 0 )
13420
                @(posedge pci_clock) ;
13421
 
13422 35 mihad
            #1 ;
13423
            if ( !error_monitor_done )
13424
                disable monitor_error_event2 ;
13425 15 mihad
        end
13426
        begin:monitor_error_event2
13427 35 mihad
            error_monitor_done = 0 ;
13428 15 mihad
            @(error_event_int) ;
13429
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13430
            ok = 0 ;
13431 35 mihad
            error_monitor_done = 1 ;
13432 15 mihad
        end
13433
        join
13434
 
13435
        if ( ok )
13436
            test_ok ;
13437
 
13438 26 mihad
        @(posedge pci_clock) ;
13439
        @(posedge pci_clock) ;
13440
        @(posedge wb_clock) ;
13441
        @(posedge wb_clock) ;
13442
 
13443 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13444
        addr_offset = 12'h004 ;
13445
        config_read(addr_offset, 4'hF, read_data) ;
13446
        ok = 1 ;
13447
        if ( read_data[27] !== 1 )
13448
        begin
13449
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13450
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13451
            ok = 0 ;
13452
        end
13453
        if ( read_data[28] !== 0 )
13454
        begin
13455
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13456
            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") ;
13457
            ok = 0 ;
13458
        end
13459
        if ( read_data[29] !== 0 )
13460
        begin
13461
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13462
            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") ;
13463
            ok = 0 ;
13464
        end
13465
 
13466
        // clear statuses
13467
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13468
        if ( !ok )
13469
        begin
13470
            test_fail("write to PCI Device Status register failed") ;
13471
            $display("Couldn't write PCI Device Status register") ;
13472
            disable main ;
13473
        end
13474
 
13475
        if ( ok )
13476
            test_ok ;
13477
 
13478
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13479
 
13480
        ok = 1 ;
13481
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13482
 
13483
        config_read(addr_offset, 4'hF, read_data) ;
13484
        if (read_data[8] !== 0)
13485
        begin
13486
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13487
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13488
            ok = 0 ;
13489
        end
13490
        else
13491
            test_ok ;
13492
 
13493
        if ( ok !== 1 )
13494
        begin
13495
            config_write(addr_offset, read_data, 4'hF, ok) ;
13496
            if ( !ok )
13497
            begin
13498
                test_fail("PCI Error Control and Status register could not be written") ;
13499
                disable main ;
13500
            end
13501
        end
13502
 
13503
        // do a single read error terminated on WB bus
13504
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13505
 
13506
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13507
 
13508
        fork
13509
        begin
13510
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13511
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13512
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13513
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13514
 
13515
            do_pause( 1 ) ;
13516
        end
13517
        begin
13518
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13519
 
13520
            if ( ok !== 1 )
13521
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13522
 
13523
            do_pause(3) ;
13524
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13525
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13526
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13527
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13528
            do_pause(1) ;
13529
 
13530
            while ( FRAME === 0 )
13531
                @(posedge pci_clock) ;
13532
 
13533
            while ( IRDY === 0 )
13534
                @(posedge pci_clock) ;
13535
 
13536 35 mihad
            if ( !error_monitor_done )
13537
                disable monitor_error_event3 ;
13538 15 mihad
        end
13539
        begin:monitor_error_event3
13540 35 mihad
            error_monitor_done = 0 ;
13541 15 mihad
            @(error_event_int) ;
13542
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13543
            ok = 0 ;
13544 35 mihad
            error_monitor_done = 1 ;
13545 15 mihad
        end
13546
        join
13547
 
13548
        if ( ok )
13549
            test_ok ;
13550
 
13551 26 mihad
        @(posedge pci_clock) ;
13552
        @(posedge pci_clock) ;
13553
        @(posedge wb_clock) ;
13554
        @(posedge wb_clock) ;
13555
 
13556 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13557
        addr_offset = 12'h004 ;
13558
        config_read(addr_offset, 4'hF, read_data) ;
13559
        ok = 1 ;
13560
        if ( read_data[27] !== 1 )
13561
        begin
13562
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13563
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13564
            ok = 0 ;
13565
        end
13566
        if ( read_data[28] !== 0 )
13567
        begin
13568
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13569
            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") ;
13570
            ok = 0 ;
13571
        end
13572
        if ( read_data[29] !== 0 )
13573
        begin
13574
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13575
            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") ;
13576
            ok = 0 ;
13577
        end
13578
 
13579
        // clear statuses
13580
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13581
        if ( !ok )
13582
        begin
13583
            test_fail("write to PCI Device Status register failed") ;
13584
            $display("Couldn't write PCI Device Status register") ;
13585
            disable main ;
13586
        end
13587
 
13588
        if ( ok )
13589
            test_ok ;
13590
 
13591
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13592
 
13593
        ok = 1 ;
13594
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13595
 
13596
        config_read(addr_offset, 4'hF, read_data) ;
13597
        if (read_data[8] !== 0)
13598
        begin
13599
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13600
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13601
            ok = 0 ;
13602
        end
13603
        else
13604
            test_ok ;
13605
 
13606
        if ( ok !== 1 )
13607
        begin
13608
            config_write(addr_offset, read_data, 4'hF, ok) ;
13609
            if ( !ok )
13610
            begin
13611
                test_fail("PCI Error Control and Status register could not be written") ;
13612
                disable main ;
13613
            end
13614
        end
13615
 
13616
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13617
 
13618
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13619
 
13620
        fork
13621
        begin
13622
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13623
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13624
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13625
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13626
 
13627
            do_pause( 1 ) ;
13628
        end
13629
        begin
13630
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13631
 
13632
            if ( ok !== 1 )
13633
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13634
 
13635
            do_pause(3) ;
13636
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13637
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13638
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13639
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13640
            do_pause(1) ;
13641
 
13642
            while ( FRAME === 0 )
13643
                @(posedge pci_clock) ;
13644
 
13645
            while ( IRDY === 0 )
13646
                @(posedge pci_clock) ;
13647
 
13648 35 mihad
            #1 ;
13649
            if ( !error_monitor_done )
13650
                disable monitor_error_event4 ;
13651 15 mihad
        end
13652
        begin:monitor_error_event4
13653 35 mihad
            error_monitor_done = 0 ;
13654 15 mihad
            @(error_event_int) ;
13655
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13656
            ok = 0 ;
13657 35 mihad
            error_monitor_done = 1 ;
13658 15 mihad
        end
13659
        begin
13660
            wb_transaction_stop( 1 ) ;
13661
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13662
        end
13663
        join
13664
 
13665
        if ( ok )
13666
            test_ok ;
13667
 
13668 26 mihad
        @(posedge pci_clock) ;
13669
        @(posedge pci_clock) ;
13670
        @(posedge wb_clock) ;
13671
        @(posedge wb_clock) ;
13672
 
13673 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13674
        addr_offset = 12'h004 ;
13675
        config_read(addr_offset, 4'hF, read_data) ;
13676
        ok = 1 ;
13677
        if ( read_data[27] !== 1 )
13678
        begin
13679
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13680
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13681
            ok = 0 ;
13682
        end
13683
        if ( read_data[28] !== 0 )
13684
        begin
13685
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13686
            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") ;
13687
            ok = 0 ;
13688
        end
13689
        if ( read_data[29] !== 0 )
13690
        begin
13691
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13692
            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") ;
13693
            ok = 0 ;
13694
        end
13695
 
13696
        // clear statuses
13697
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13698
        if ( !ok )
13699
        begin
13700
            test_fail("write to PCI Device Status register failed") ;
13701
            $display("Couldn't write PCI Device Status register") ;
13702
            disable main ;
13703
        end
13704
 
13705
        if ( ok )
13706
            test_ok ;
13707
 
13708
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13709
 
13710
        ok = 1 ;
13711
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13712
 
13713
        config_read(addr_offset, 4'hF, read_data) ;
13714
        if (read_data[8] !== 0)
13715
        begin
13716
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13717
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13718
            ok = 0 ;
13719
        end
13720
        else
13721
            test_ok ;
13722
 
13723
        if ( ok !== 1 )
13724
        begin
13725
            config_write(addr_offset, read_data, 4'hF, ok) ;
13726
            if ( !ok )
13727
            begin
13728
                test_fail("PCI Error Control and Status register could not be written") ;
13729
                disable main ;
13730
            end
13731
        end
13732
 
13733
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13734
 
13735
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13736
 
13737
        fork
13738
        begin
13739
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13740
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13741
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13742
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13743
 
13744
            do_pause( 1 ) ;
13745
        end
13746
        begin
13747
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13748
 
13749
            if ( ok !== 1 )
13750
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13751
 
13752
            do_pause(3) ;
13753
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13754
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13755
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13756
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13757
            do_pause(1) ;
13758
 
13759
            while ( FRAME === 0 )
13760
                @(posedge pci_clock) ;
13761
 
13762
            while ( IRDY === 0 )
13763
                @(posedge pci_clock) ;
13764
 
13765 35 mihad
            #1 ;
13766
            if ( !error_monitor_done )
13767
                disable monitor_error_event5 ;
13768 15 mihad
        end
13769
        begin:monitor_error_event5
13770 35 mihad
            error_monitor_done = 0 ;
13771 15 mihad
            @(error_event_int) ;
13772
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13773
            ok = 0 ;
13774 35 mihad
            error_monitor_done = 1 ;
13775 15 mihad
        end
13776
        begin
13777
            wb_transaction_stop( 3 ) ;
13778
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13779
        end
13780
        join
13781
 
13782
        if ( ok )
13783
            test_ok ;
13784
 
13785 26 mihad
        @(posedge pci_clock) ;
13786
        @(posedge pci_clock) ;
13787
        @(posedge wb_clock) ;
13788
        @(posedge wb_clock) ;
13789
 
13790 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13791
        addr_offset = 12'h004 ;
13792
        config_read(addr_offset, 4'hF, read_data) ;
13793
        ok = 1 ;
13794
        if ( read_data[27] !== 1 )
13795
        begin
13796
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13797
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13798
            ok = 0 ;
13799
        end
13800
        if ( read_data[28] !== 0 )
13801
        begin
13802
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13803
            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") ;
13804
            ok = 0 ;
13805
        end
13806
        if ( read_data[29] !== 0 )
13807
        begin
13808
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13809
            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") ;
13810
            ok = 0 ;
13811
        end
13812
 
13813
        // clear statuses
13814
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13815
        if ( !ok )
13816
        begin
13817
            test_fail("write to PCI Device Status register failed") ;
13818
            $display("Couldn't write PCI Device Status register") ;
13819
            disable main ;
13820
        end
13821
 
13822
        if ( ok )
13823
            test_ok ;
13824
 
13825
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13826
 
13827
        ok = 1 ;
13828
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13829
 
13830
        config_read(addr_offset, 4'hF, read_data) ;
13831
        if (read_data[8] !== 0)
13832
        begin
13833
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13834
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13835
            ok = 0 ;
13836
        end
13837
        else
13838
            test_ok ;
13839
 
13840
        if ( ok !== 1 )
13841
        begin
13842
            config_write(addr_offset, read_data, 4'hF, ok) ;
13843
            if ( !ok )
13844
            begin
13845
                test_fail("PCI Error Control and Status register could not be written") ;
13846
                disable main ;
13847
            end
13848
        end
13849
 
13850
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
13851
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13852
        fork
13853
        begin
13854
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13855
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13856
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13857
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13858
 
13859
            do_pause( 1 ) ;
13860
        end
13861
        begin
13862
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13863
 
13864
            if ( ok !== 1 )
13865
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13866
 
13867
            do_pause(3) ;
13868
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13869
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13870
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13871
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13872
            do_pause(1) ;
13873
 
13874
            while ( FRAME === 0 )
13875
                @(posedge pci_clock) ;
13876
 
13877
            while ( IRDY === 0 )
13878
                @(posedge pci_clock) ;
13879
 
13880 35 mihad
            #1 ;
13881
            if ( !error_monitor_done )
13882
                disable monitor_error_event6 ;
13883 15 mihad
        end
13884
        begin:monitor_error_event6
13885 35 mihad
            error_monitor_done = 0 ;
13886 15 mihad
            @(error_event_int) ;
13887
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13888
            ok = 0 ;
13889 35 mihad
            error_monitor_done = 1 ;
13890 15 mihad
        end
13891
        begin
13892
            wb_transaction_stop( 3 ) ;
13893
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13894
        end
13895
        join
13896
 
13897
        if ( ok )
13898
            test_ok ;
13899
 
13900 26 mihad
        @(posedge pci_clock) ;
13901
        @(posedge pci_clock) ;
13902
        @(posedge wb_clock) ;
13903
        @(posedge wb_clock) ;
13904
 
13905 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13906
        addr_offset = 12'h004 ;
13907
        config_read(addr_offset, 4'hF, read_data) ;
13908
        ok = 1 ;
13909
        if ( read_data[27] !== 1 )
13910
        begin
13911
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13912
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13913
            ok = 0 ;
13914
        end
13915
        if ( read_data[28] !== 0 )
13916
        begin
13917
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13918
            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") ;
13919
            ok = 0 ;
13920
        end
13921
        if ( read_data[29] !== 0 )
13922
        begin
13923
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13924
            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") ;
13925
            ok = 0 ;
13926
        end
13927
 
13928
        // clear statuses
13929
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13930
        if ( !ok )
13931
        begin
13932
            test_fail("write to PCI Device Status register failed") ;
13933
            $display("Couldn't write PCI Device Status register") ;
13934
            disable main ;
13935
        end
13936
 
13937
        if ( ok )
13938
            test_ok ;
13939
 
13940
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13941
 
13942
        ok = 1 ;
13943
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13944
 
13945
        config_read(addr_offset, 4'hF, read_data) ;
13946
        if (read_data[8] !== 0)
13947
        begin
13948
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13949
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13950
            ok = 0 ;
13951
        end
13952
        else
13953
            test_ok ;
13954
 
13955
        if ( ok !== 1 )
13956
        begin
13957
            config_write(addr_offset, read_data, 4'hF, ok) ;
13958
            if ( !ok )
13959
            begin
13960
                test_fail("PCI Error Control and Status register could not be written") ;
13961
                disable main ;
13962
            end
13963
        end
13964
 
13965
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13966
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13967
        fork
13968
        begin
13969
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13970
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
13971
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13972
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13973
 
13974
            do_pause( 1 ) ;
13975
        end
13976
        begin
13977
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
13978
 
13979
            if ( ok !== 1 )
13980
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13981
 
13982
            do_pause(3) ;
13983
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13984
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
13985
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13986
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13987
            do_pause(1) ;
13988
 
13989
            while ( FRAME === 0 )
13990
                @(posedge pci_clock) ;
13991
 
13992
            while ( IRDY === 0 )
13993
                @(posedge pci_clock) ;
13994
 
13995 35 mihad
            #1 ;
13996
            if ( !error_monitor_done )
13997
                disable monitor_error_event7 ;
13998 15 mihad
        end
13999
        begin:monitor_error_event7
14000 35 mihad
            error_monitor_done = 0 ;
14001 15 mihad
            @(error_event_int) ;
14002
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14003
            ok = 0 ;
14004 35 mihad
            error_monitor_done = 1 ;
14005 15 mihad
        end
14006
        begin
14007
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14008
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14009
        end
14010
        join
14011
 
14012
        if ( ok )
14013
            test_ok ;
14014
 
14015 26 mihad
        @(posedge pci_clock) ;
14016
        @(posedge pci_clock) ;
14017
        @(posedge wb_clock) ;
14018
        @(posedge wb_clock) ;
14019
 
14020 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14021
        addr_offset = 12'h004 ;
14022
        config_read(addr_offset, 4'hF, read_data) ;
14023
        ok = 1 ;
14024
        if ( read_data[27] !== 1 )
14025
        begin
14026
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14027
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14028
            ok = 0 ;
14029
        end
14030
        if ( read_data[28] !== 0 )
14031
        begin
14032
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14033
            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") ;
14034
            ok = 0 ;
14035
        end
14036
        if ( read_data[29] !== 0 )
14037
        begin
14038
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14039
            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") ;
14040
            ok = 0 ;
14041
        end
14042
 
14043
        // clear statuses
14044
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14045
        if ( !ok )
14046
        begin
14047
            test_fail("write to PCI Device Status register failed") ;
14048
            $display("Couldn't write PCI Device Status register") ;
14049
            disable main ;
14050
        end
14051
 
14052
        if ( ok )
14053
            test_ok ;
14054
 
14055
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14056
 
14057
        ok = 1 ;
14058
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14059
 
14060
        config_read(addr_offset, 4'hF, read_data) ;
14061
        if (read_data[8] !== 0)
14062
        begin
14063
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14064
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14065
            ok = 0 ;
14066
        end
14067
        else
14068
            test_ok ;
14069
 
14070
        if ( ok !== 1 )
14071
        begin
14072
            config_write(addr_offset, read_data, 4'hF, ok) ;
14073
            if ( !ok )
14074
            begin
14075
                test_fail("PCI Error Control and Status register could not be written") ;
14076
                disable main ;
14077
            end
14078
        end
14079
 
14080
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14081
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14082
        fork
14083
        begin
14084
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14085
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14086
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14087
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14088
 
14089
            do_pause( 1 ) ;
14090
        end
14091
        begin
14092
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14093
 
14094
            if ( ok !== 1 )
14095
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14096
 
14097
            do_pause(3) ;
14098
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14099
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14100
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14101
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14102
            do_pause(1) ;
14103
 
14104
            while ( FRAME === 0 )
14105
                @(posedge pci_clock) ;
14106
 
14107
            while ( IRDY === 0 )
14108
                @(posedge pci_clock) ;
14109
 
14110 35 mihad
            #1 ;
14111
            if ( !error_monitor_done )
14112
                disable monitor_error_event8 ;
14113 15 mihad
        end
14114
        begin:monitor_error_event8
14115 35 mihad
            error_monitor_done = 0 ;
14116 15 mihad
            @(error_event_int) ;
14117
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14118
            ok = 0 ;
14119 35 mihad
            error_monitor_done = 1 ;
14120 15 mihad
        end
14121
        begin
14122
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14123
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14124
        end
14125
        join
14126
 
14127
        if ( ok )
14128
            test_ok ;
14129
 
14130 26 mihad
        @(posedge pci_clock) ;
14131
        @(posedge pci_clock) ;
14132
        @(posedge wb_clock) ;
14133
        @(posedge wb_clock) ;
14134
 
14135 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14136
 
14137
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14138
        addr_offset = 12'h004 ;
14139
        config_read(addr_offset, 4'hF, read_data) ;
14140
        ok = 1 ;
14141
        if ( read_data[27] !== 1 )
14142
        begin
14143
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14144
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14145
            ok = 0 ;
14146
        end
14147
        if ( read_data[28] !== 0 )
14148
        begin
14149
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14150
            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") ;
14151
            ok = 0 ;
14152
        end
14153
        if ( read_data[29] !== 0 )
14154
        begin
14155
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14156
            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") ;
14157
            ok = 0 ;
14158
        end
14159
 
14160
        // clear statuses
14161
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14162
        if ( !ok )
14163
        begin
14164
            test_fail("write to PCI Device Status register failed") ;
14165
            $display("Couldn't write PCI Device Status register") ;
14166
            disable main ;
14167
        end
14168
 
14169
        if ( ok )
14170
            test_ok ;
14171
 
14172
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14173
 
14174
        ok = 1 ;
14175
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14176
 
14177
        config_read(addr_offset, 4'hF, read_data) ;
14178
        if (read_data[8] !== 0)
14179
        begin
14180
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14181
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14182
            ok = 0 ;
14183
        end
14184
        else
14185
            test_ok ;
14186
 
14187
        if ( ok !== 1 )
14188
        begin
14189
            config_write(addr_offset, read_data, 4'hF, ok) ;
14190
            if ( !ok )
14191
            begin
14192
                test_fail("PCI Error Control and Status register could not be written") ;
14193
                disable main ;
14194
            end
14195
        end
14196
 
14197
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14198
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14199
        fork
14200
        begin
14201
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14202
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14203
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14204
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14205
 
14206
            do_pause( 1 ) ;
14207
        end
14208
        begin
14209
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14210
 
14211
            if ( ok !== 1 )
14212
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14213
 
14214
            do_pause(3) ;
14215
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14216
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14217
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14218
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14219
            do_pause(1) ;
14220
 
14221
            while ( FRAME === 0 )
14222
                @(posedge pci_clock) ;
14223
 
14224
            while ( IRDY === 0 )
14225
                @(posedge pci_clock) ;
14226
 
14227 35 mihad
            #1 ;
14228
            if ( !error_monitor_done )
14229
                disable monitor_error_event9 ;
14230 15 mihad
        end
14231
        begin:monitor_error_event9
14232 35 mihad
            error_monitor_done = 0 ;
14233 15 mihad
            @(error_event_int) ;
14234
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14235
            ok = 0 ;
14236 35 mihad
            error_monitor_done = 1 ;
14237 15 mihad
        end
14238
        begin
14239
            wb_transaction_stop( 3 ) ;
14240
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14241
        end
14242
        join
14243
 
14244
        if ( ok )
14245
            test_ok ;
14246
 
14247
        // now check all other statuses too
14248
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14249
        ok = 1 ;
14250
 
14251
        addr_offset = 12'h004 ;
14252
        config_read(addr_offset, 4'hF, read_data) ;
14253
        if (read_data[31] !== 0)
14254
        begin
14255
            $display("Detected Parity Error bit set for no reason") ;
14256
            test_fail("Detected Parity Error bit was set for no reason") ;
14257
            ok = 0 ;
14258
        end
14259
 
14260
        if (read_data[30] !== 0)
14261
        begin
14262
            $display("Signaled System Error bit set for no reason") ;
14263
            test_fail("Signaled System Error bit was set for no reason") ;
14264
            ok = 0 ;
14265
        end
14266
 
14267
        if (read_data[29] !== 0)
14268
        begin
14269
            $display("Received Master Abort bit set for no reason") ;
14270
            test_fail("Received Master Abort bit was set for no reason") ;
14271
            ok = 0 ;
14272
        end
14273
 
14274
        if (read_data[28] !== 0)
14275
        begin
14276
            $display("Received Target Abort bit set for no reason");
14277
            test_fail("Received Target Abort bit was set for no reason") ;
14278
            ok = 0 ;
14279
        end
14280
 
14281
        if (read_data[27] !== 0)
14282
        begin
14283
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14284
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14285
            ok = 0 ;
14286
        end
14287
 
14288
        if (read_data[24] !== 0)
14289
        begin
14290
            $display("Master Data Parity Error bit set for no reason") ;
14291
            test_fail("Master Data Parity Error bit was set for no reason") ;
14292
            ok = 0 ;
14293
        end
14294
 
14295
        if ( ok )
14296
            test_ok ;
14297
 
14298
        test_name = "DISABLE IMAGE" ;
14299 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14300 15 mihad
        if ( ok !== 1 )
14301
        begin
14302
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14303
            test_fail("PCI Address Mask register could not be written") ;
14304
            disable main;
14305
        end
14306
    end
14307
 
14308
    if ( target_io_image !== -1 )
14309
    begin
14310
        do_io_aborts = 1 ;
14311
 
14312
        if (target_io_image === 1)
14313
        begin
14314
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14315
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14316
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14317
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14318
        end
14319
        else if (target_io_image === 2)
14320
        begin
14321
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14322
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14323
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14324
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14325
        end
14326
        else if (target_io_image === 3)
14327
        begin
14328
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14329
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14330
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14331
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14332
        end
14333
        else if (target_io_image === 4)
14334
        begin
14335
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14336
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14337
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14338
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14339
        end
14340
        else if (target_io_image === 5)
14341
        begin
14342
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14343
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14344
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14345
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14346
        end
14347
    end
14348
    else
14349
        do_io_aborts = 0 ;
14350
 
14351
    if ( do_io_aborts )
14352
    begin
14353
 
14354
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14355
 
14356
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14357
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14358
        if ( ok !== 1 )
14359
        begin
14360
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14361
            test_fail("PCI Error Control and Status register could not be written") ;
14362
            disable main;
14363
        end
14364
 
14365
        // enable INTERRUPT reporting
14366
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14367
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14368
        if ( ok !== 1 )
14369
        begin
14370
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14371
            test_fail("Interrupt Control register could not be written") ;
14372
            disable main;
14373
        end
14374
 
14375
        addr_offset = 12'h010 + (4*target_io_image) ;
14376
 
14377
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14378
        if ( ok !== 1 )
14379
        begin
14380
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14381
            test_fail("PCI Base Address register could not be written") ;
14382
            disable main;
14383
        end
14384
 
14385
        // disable address translation and enable prefetch so read bursts can be performed
14386
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14387
        if ( ok !== 1 )
14388
        begin
14389
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14390
            test_fail("PCI Image Control register could not be written") ;
14391
            disable main;
14392
        end
14393
 
14394
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14395
        if ( ok !== 1 )
14396
        begin
14397
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14398
            test_fail("PCI Address Mask register could not be written") ;
14399
            disable main;
14400
        end
14401
 
14402
        addr_offset = 12'h00C ;
14403
 
14404
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14405
        if ( ok !== 1 )
14406
        begin
14407
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14408
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14409
            disable main;
14410
        end
14411
 
14412
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14413
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14414
 
14415
        // do a single read error terminated on WB bus
14416
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14417
 
14418
        fork
14419
        begin
14420
            PCIU_IO_READ
14421
             (
14422
                `Test_Master_1,
14423
                Target_Base_Addr_R[target_io_image],
14424
                32'hAAAA_5555,
14425
                4'h0,
14426
                1,
14427
                `Test_Target_Retry_On
14428
             );
14429
 
14430
            do_pause( 1 ) ;
14431
        end
14432
        begin
14433
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14434
 
14435
            if ( ok !== 1 )
14436
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14437
 
14438
            do_pause(3) ;
14439
 
14440
            PCIU_IO_READ
14441
             (
14442
                `Test_Master_1,
14443
                Target_Base_Addr_R[target_io_image],
14444
                32'hAAAA_5555,
14445
                4'h0,
14446
                1,
14447
                `Test_Target_Abort_On
14448
             );
14449
 
14450
            do_pause( 1 ) ;
14451
 
14452
            while ( FRAME === 0 )
14453
                @(posedge pci_clock) ;
14454
 
14455
            while ( IRDY === 0 )
14456
                @(posedge pci_clock) ;
14457
 
14458 35 mihad
            #1 ;
14459
            if ( !error_monitor_done )
14460
                disable monitor_error_event10 ;
14461 15 mihad
        end
14462
        begin:monitor_error_event10
14463 35 mihad
            error_monitor_done = 0 ;
14464 15 mihad
            @(error_event_int) ;
14465
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14466
            ok = 0 ;
14467 35 mihad
            error_monitor_done = 1 ;
14468 15 mihad
        end
14469
        join
14470
 
14471
        if ( ok )
14472
            test_ok ;
14473
 
14474 26 mihad
        @(posedge pci_clock) ;
14475
        @(posedge pci_clock) ;
14476
        @(posedge wb_clock) ;
14477
        @(posedge wb_clock) ;
14478
 
14479 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14480
        addr_offset = 12'h004 ;
14481
        config_read(addr_offset, 4'hF, read_data) ;
14482
        ok = 1 ;
14483
        if ( read_data[27] !== 1 )
14484
        begin
14485
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14486
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14487
            ok = 0 ;
14488
        end
14489
        if ( read_data[28] !== 0 )
14490
        begin
14491
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14492
            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") ;
14493
            ok = 0 ;
14494
        end
14495
        if ( read_data[29] !== 0 )
14496
        begin
14497
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14498
            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") ;
14499
            ok = 0 ;
14500
        end
14501
 
14502
        // clear statuses
14503
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14504
        if ( !ok )
14505
        begin
14506
            test_fail("write to PCI Device Status register failed") ;
14507
            $display("Couldn't write PCI Device Status register") ;
14508
            disable main ;
14509
        end
14510
 
14511
        if ( ok )
14512
            test_ok ;
14513
 
14514
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14515
 
14516
        ok = 1 ;
14517
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14518
 
14519
        config_read(addr_offset, 4'hF, read_data) ;
14520
        if (read_data[8] !== 0)
14521
        begin
14522
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14523
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14524
            ok = 0 ;
14525
        end
14526
        else
14527
            test_ok ;
14528
 
14529
        if ( ok !== 1 )
14530
        begin
14531
            config_write(addr_offset, read_data, 4'hF, ok) ;
14532
            if ( !ok )
14533
            begin
14534
                test_fail("PCI Error Control and Status register could not be written") ;
14535
                disable main ;
14536
            end
14537
        end
14538
 
14539
        test_name = "DISABLE IMAGE" ;
14540 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14541 15 mihad
        if ( ok !== 1 )
14542
        begin
14543
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14544
            test_fail("PCI Address Mask register could not be written") ;
14545
            disable main;
14546
        end
14547
 
14548
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14549
 
14550
    end
14551
end // main
14552
endtask // test_wb_error_rd
14553
 
14554
task test_target_abort ;
14555
    input [2:0]  image_num ;
14556
    reg   [11:0] pci_ctrl_offset ;
14557
    reg   [11:0] ctrl_offset ;
14558
    reg   [11:0] ba_offset ;
14559
    reg   [11:0] am_offset ;
14560
    reg   [11:0] ta_offset ;
14561
    reg   [31:0] pci_address ;
14562
    reg   [3:0]  byte_enables ;
14563
    reg          ok ;
14564 35 mihad
    reg          error_monitor_done ;
14565 15 mihad
begin:main
14566
    pci_ctrl_offset = 12'h4 ;
14567
    if (image_num === 0)
14568
    begin
14569
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14570
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14571
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14572
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14573
    end
14574
    else if (image_num === 1)
14575
    begin
14576
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14577
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14578
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14579
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14580
    end
14581
    else if (image_num === 2)
14582
    begin
14583
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14584
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14585
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14586
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14587
    end
14588
    else if (image_num === 3)
14589
    begin
14590
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14591
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14592
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14593
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14594
    end
14595
    else if (image_num === 4)
14596
    begin
14597
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14598
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14599
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14600
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14601
    end
14602
    else if (image_num === 5)
14603
    begin
14604
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14605
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14606
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14607
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14608
    end
14609
 
14610
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14611
 
14612
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14613
    if ( ok !== 1 )
14614
    begin
14615
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14616
        test_fail("PCI Base Address register could not be written") ;
14617
        disable main ;
14618
    end
14619
 
14620
    // Set Address Mask of IMAGE
14621
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14622
    if ( ok !== 1 )
14623
    begin
14624
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14625
        test_fail("PCI Address Mask register could not be written") ;
14626
        disable main ;
14627
    end
14628
 
14629
    // Set Translation Address of IMAGE
14630
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14631
    if ( ok !== 1 )
14632
    begin
14633
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14634
        test_fail("PCI Translation Address Register could not be written") ;
14635
        disable main ;
14636
    end
14637
 
14638
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14639
    if ( ok !== 1 )
14640
    begin
14641
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14642
        test_fail("PCI Image Control register could not be written") ;
14643
        disable main ;
14644
    end
14645
 
14646
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14647
 
14648
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14649
 
14650
    pci_address  = Target_Base_Addr_R[image_num] ;
14651
    byte_enables = 4'b0001 ;
14652
 
14653
    fork
14654
    begin
14655
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14656
        do_pause ( 1 ) ;
14657
    end
14658
    begin:monitor_error_event1
14659 35 mihad
        error_monitor_done = 0 ;
14660 15 mihad
        @(error_event_int) ;
14661
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14662
        ok = 0 ;
14663 35 mihad
        error_monitor_done = 1 ;
14664 15 mihad
    end
14665
    begin
14666
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14667
        @(posedge pci_clock) ;
14668 35 mihad
        #1 ;
14669
        if ( !error_monitor_done )
14670
            disable monitor_error_event1 ;
14671 15 mihad
    end
14672
    join
14673
 
14674
    if ( ok )
14675
        test_ok ;
14676
 
14677
    ok = 1 ;
14678
 
14679
    fork
14680
    begin
14681
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14682
        do_pause ( 1 ) ;
14683
    end
14684
    begin:monitor_error_event2
14685 35 mihad
        error_monitor_done = 0 ;
14686 15 mihad
        @(error_event_int) ;
14687
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14688
        ok = 0 ;
14689 35 mihad
        error_monitor_done = 1 ;
14690 15 mihad
    end
14691
    begin
14692
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14693
        @(posedge pci_clock) ;
14694 35 mihad
        #1 ;
14695
        if ( !error_monitor_done )
14696
            disable monitor_error_event2 ;
14697 15 mihad
    end
14698
    join
14699
 
14700
    if ( ok )
14701
        test_ok ;
14702
 
14703
    ok = 1 ;
14704
 
14705
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14706
    byte_enables = 4'b0011 ;
14707
 
14708
    fork
14709
    begin
14710
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14711
        do_pause ( 1 ) ;
14712
    end
14713
    begin:monitor_error_event3
14714 35 mihad
        error_monitor_done = 0 ;
14715 15 mihad
        @(error_event_int) ;
14716
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14717
        ok = 0 ;
14718 35 mihad
        error_monitor_done = 1 ;
14719 15 mihad
    end
14720
    begin
14721
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14722
        @(posedge pci_clock) ;
14723 35 mihad
        if ( !error_monitor_done )
14724
            disable monitor_error_event3 ;
14725 15 mihad
    end
14726
    join
14727
 
14728
    if ( ok )
14729
        test_ok ;
14730
 
14731
    ok = 1 ;
14732
 
14733
    byte_enables = 4'b0000 ;
14734
 
14735
    fork
14736
    begin
14737
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14738
        do_pause ( 1 ) ;
14739
    end
14740
    begin:monitor_error_event4
14741 35 mihad
        error_monitor_done = 0 ;
14742 15 mihad
        @(error_event_int) ;
14743
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14744
        ok = 0 ;
14745 35 mihad
        error_monitor_done = 1 ;
14746 15 mihad
    end
14747
    begin
14748
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14749
        @(posedge pci_clock) ;
14750 35 mihad
        #1 ;
14751
        if ( !error_monitor_done )
14752
            disable monitor_error_event4 ;
14753 15 mihad
    end
14754
    join
14755
 
14756
    if ( ok )
14757
        test_ok ;
14758
 
14759
    ok = 1 ;
14760
 
14761
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
14762
    byte_enables = 4'b0111 ;
14763
 
14764
    fork
14765
    begin
14766
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14767
        do_pause ( 1 ) ;
14768
    end
14769
    begin:monitor_error_event5
14770 35 mihad
        error_monitor_done = 0 ;
14771 15 mihad
        @(error_event_int) ;
14772
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14773
        ok = 0 ;
14774 35 mihad
        error_monitor_done = 1 ;
14775 15 mihad
    end
14776
    begin
14777
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14778
        @(posedge pci_clock) ;
14779 35 mihad
        #1 ;
14780
        if ( !error_monitor_done )
14781
            disable monitor_error_event5 ;
14782 15 mihad
    end
14783
    join
14784
 
14785
    if ( ok )
14786
        test_ok ;
14787
 
14788
    ok = 1 ;
14789
 
14790
    byte_enables = 4'b0010 ;
14791
 
14792
    fork
14793
    begin
14794
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14795
        do_pause ( 1 ) ;
14796
    end
14797
    begin:monitor_error_event6
14798 35 mihad
        error_monitor_done = 0 ;
14799 15 mihad
        @(error_event_int) ;
14800
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14801
        ok = 0 ;
14802 35 mihad
        error_monitor_done = 1 ;
14803 15 mihad
    end
14804
    begin
14805
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14806
        @(posedge pci_clock) ;
14807 35 mihad
        #1 ;
14808
        if ( !error_monitor_done )
14809
            disable monitor_error_event6 ;
14810 15 mihad
    end
14811
    join
14812
 
14813
    if ( ok )
14814
        test_ok ;
14815
 
14816
    ok = 1 ;
14817
    byte_enables = 4'b0001 ;
14818
 
14819
    fork
14820
    begin
14821
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14822
        do_pause ( 1 ) ;
14823
    end
14824
    begin:monitor_error_event7
14825 35 mihad
        error_monitor_done = 0 ;
14826 15 mihad
        @(error_event_int) ;
14827
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14828
        ok = 0 ;
14829 35 mihad
        error_monitor_done = 1 ;
14830 15 mihad
    end
14831
    begin
14832
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14833
        @(posedge pci_clock) ;
14834 35 mihad
        #1 ;
14835
        if ( !error_monitor_done )
14836
            disable monitor_error_event7 ;
14837 15 mihad
    end
14838
    join
14839
 
14840
    if ( ok )
14841
        test_ok ;
14842
 
14843
    ok = 1 ;
14844
    byte_enables = 4'b0000 ;
14845
 
14846
    fork
14847
    begin
14848
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14849
        do_pause ( 1 ) ;
14850
    end
14851
    begin:monitor_error_event8
14852 35 mihad
        error_monitor_done = 0 ;
14853 15 mihad
        @(error_event_int) ;
14854
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14855
        ok = 0 ;
14856 35 mihad
        error_monitor_done = 1 ;
14857 15 mihad
    end
14858
    begin
14859
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14860
        @(posedge pci_clock) ;
14861 35 mihad
        #1 ;
14862
        if ( !error_monitor_done )
14863
            disable monitor_error_event8 ;
14864 15 mihad
    end
14865
    join
14866
 
14867
    if ( ok )
14868
        test_ok ;
14869
 
14870
    ok = 1 ;
14871
 
14872
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
14873
    byte_enables = 4'b0110 ;
14874
 
14875
    fork
14876
    begin
14877
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
14878
        do_pause ( 1 ) ;
14879
    end
14880
    begin:monitor_error_event9
14881 35 mihad
        error_monitor_done = 0 ;
14882 15 mihad
        @(error_event_int) ;
14883
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14884
        ok = 0 ;
14885 35 mihad
        error_monitor_done = 1 ;
14886 15 mihad
    end
14887
    begin
14888
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14889
        @(posedge pci_clock) ;
14890 35 mihad
        #1 ;
14891
        if ( !error_monitor_done )
14892
            disable monitor_error_event9 ;
14893 15 mihad
    end
14894
    join
14895
 
14896
    if ( ok )
14897
        test_ok ;
14898
 
14899
    ok = 1 ;
14900
    fork
14901
    begin
14902
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
14903
        do_pause ( 1 ) ;
14904
    end
14905
    begin:monitor_error_event10
14906 35 mihad
        error_monitor_done = 0 ;
14907 15 mihad
        @(error_event_int) ;
14908
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14909
        ok = 0 ;
14910 35 mihad
        error_monitor_done = 1 ;
14911 15 mihad
    end
14912
    begin
14913
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14914
        @(posedge pci_clock) ;
14915 35 mihad
 
14916
        #1 ;
14917
        if ( !error_monitor_done )
14918
            disable monitor_error_event10 ;
14919 15 mihad
    end
14920
    join
14921
 
14922
    if ( ok )
14923
        test_ok ;
14924
 
14925
    ok = 1 ;
14926
 
14927
    byte_enables = 4'b0001 ;
14928
 
14929
    fork
14930
    begin
14931
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14932
        do_pause ( 1 ) ;
14933
    end
14934
    begin:monitor_error_event11
14935 35 mihad
        error_monitor_done = 0 ;
14936 15 mihad
        @(error_event_int) ;
14937
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14938
        ok = 0 ;
14939 35 mihad
        error_monitor_done = 1 ;
14940 15 mihad
    end
14941
    begin
14942
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14943
        @(posedge pci_clock) ;
14944 35 mihad
        #1 ;
14945
        if ( !error_monitor_done )
14946
            disable monitor_error_event11 ;
14947 15 mihad
    end
14948
    join
14949
 
14950
    if ( ok )
14951
        test_ok ;
14952
 
14953
    ok = 1 ;
14954
 
14955
    byte_enables = 4'b0101 ;
14956
 
14957
    fork
14958
    begin
14959
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14960
        do_pause ( 1 ) ;
14961
    end
14962
    begin:monitor_error_event12
14963 35 mihad
        error_monitor_done = 0 ;
14964 15 mihad
        @(error_event_int) ;
14965
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14966
        ok = 0 ;
14967 35 mihad
        error_monitor_done = 1 ;
14968 15 mihad
    end
14969
    begin
14970
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14971
        @(posedge pci_clock) ;
14972 35 mihad
        #1 ;
14973
        if ( !error_monitor_done )
14974
            disable monitor_error_event12 ;
14975 15 mihad
    end
14976
    join
14977
 
14978
    if ( ok )
14979
        test_ok ;
14980
 
14981
    ok = 1 ;
14982
 
14983
    byte_enables = 4'b0011 ;
14984
 
14985
    fork
14986
    begin
14987
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14988
        do_pause ( 1 ) ;
14989
    end
14990
    begin:monitor_error_event13
14991 35 mihad
        error_monitor_done = 0 ;
14992 15 mihad
        @(error_event_int) ;
14993
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14994
        ok = 0 ;
14995 35 mihad
        error_monitor_done = 1 ;
14996 15 mihad
    end
14997
    begin
14998
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14999
        @(posedge pci_clock) ;
15000 35 mihad
        #1 ;
15001
        if ( !error_monitor_done )
15002
            disable monitor_error_event13 ;
15003 15 mihad
    end
15004
    join
15005
 
15006
    if ( ok )
15007
        test_ok ;
15008
 
15009
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15010
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15011
    ok = 1 ;
15012
    if ( pci_address[27] !== 1 )
15013
    begin
15014
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15015
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15016
        ok = 0 ;
15017
    end
15018
    if ( pci_address[28] !== 0 )
15019
    begin
15020
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15021
        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") ;
15022
        ok = 0 ;
15023
    end
15024
    if ( pci_address[29] !== 0 )
15025
    begin
15026
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15027
        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") ;
15028
        ok = 0 ;
15029
    end
15030
 
15031
    // clear statuses
15032
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15033
    if ( !ok )
15034
    begin
15035
        test_fail("write to PCI Device Status register failed") ;
15036
        $display("Couldn't write PCI Device Status register") ;
15037
        disable main ;
15038
    end
15039
 
15040
    if ( ok )
15041
        test_ok ;
15042
 
15043
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15044
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15045
    if ( pci_address[8] !== 0 )
15046
    begin
15047
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15048
    end
15049
    else
15050
        test_ok ;
15051
 
15052
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15053
 
15054
    test_name = "DISABLE IMAGE" ;
15055
 
15056 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15057 15 mihad
    if ( ok !== 1 )
15058
    begin
15059
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15060
        test_fail("PCI Address Mask register could not be written") ;
15061
        disable main ;
15062
    end
15063
end
15064
endtask // test_target_abort
15065
 
15066
task test_target_io_wr_rd ;
15067
    input [2:0]  image_num ;
15068
    input        translate_address ;
15069
    input [11:0] img_ctrl_offset ;
15070
    reg   [31:0] expect_address ;
15071
    reg   [31:0] pci_address ;
15072
    reg          translation ;
15073
    reg   [31:0] read_data ;
15074
    reg   [3:0]  byte_enables ;
15075
    reg          ok ;
15076
    reg          pci_ok ;
15077
    reg          wb_ok ;
15078
    integer      i ;
15079 35 mihad
    reg          error_monitor_done ;
15080 15 mihad
begin:main
15081
    `ifdef ADDR_TRAN_IMPL
15082
        translation = translate_address ;
15083
    `else
15084
        translation = 0 ;
15085
    `endif
15086
 
15087
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15088
 
15089
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15090
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15091
    if ( translation )
15092
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15093
    else
15094
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15095
 
15096
    if ( !ok )
15097
    begin
15098
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15099
        test_fail("PCI Image Control register could not be written") ;
15100
    end
15101
 
15102
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15103
    pci_address  = Target_Base_Addr_R[image_num] ;
15104
    byte_enables = 4'b0000 ;
15105
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15106
 
15107
    fork
15108
    begin
15109
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15110
        do_pause ( 1 ) ;
15111
    end
15112
    begin
15113
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15114
        if ( wb_ok !== 1 )
15115
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15116
 
15117 35 mihad
        #1 ;
15118
        if ( !error_monitor_done )
15119
            disable monitor_pci_error_1 ;
15120 15 mihad
    end
15121
    begin:monitor_pci_error_1
15122 35 mihad
        error_monitor_done = 0 ;
15123 15 mihad
        pci_ok = 1 ;
15124
        @(error_event_int) ;
15125
        pci_ok = 0 ;
15126
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15127 35 mihad
        error_monitor_done = 1 ;
15128 15 mihad
    end
15129
    join
15130
 
15131
    byte_enables = 4'b1111 ;
15132
    for ( i = 0 ; i < 4 ; i = i + 1 )
15133
    begin:loop_1
15134
        byte_enables[i] = 0 ;
15135
        if ( i > 0 )
15136
            byte_enables[i - 1] = 1 ;
15137
        fork
15138
        begin
15139
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15140
            do_pause ( 1 ) ;
15141
        end
15142
        begin
15143
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15144
            if ( wb_ok !== 1 )
15145
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15146
 
15147 35 mihad
            #1 ;
15148
            if ( !error_monitor_done )
15149
                disable monitor_pci_error_2 ;
15150 15 mihad
        end
15151
        begin:monitor_pci_error_2
15152 35 mihad
            error_monitor_done = 0 ;
15153 15 mihad
            pci_ok = 1 ;
15154
            @(error_event_int) ;
15155
            pci_ok = 0 ;
15156
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15157 35 mihad
            error_monitor_done = 1 ;
15158 15 mihad
        end
15159
        join
15160
 
15161
        if ( !pci_ok || !wb_ok )
15162
            disable loop_1 ;
15163
 
15164
        pci_address = pci_address + 1 ;
15165
        expect_address = expect_address + 1 ;
15166
    end
15167
 
15168
    if ( pci_ok && wb_ok )
15169
        test_ok ;
15170
 
15171
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15172
    pci_address  = Target_Base_Addr_R[image_num] ;
15173
    byte_enables = 4'b1100 ;
15174
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15175
 
15176
    master1_check_received_data = 1 ;
15177
    fork
15178
    begin
15179
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15180
        do_pause( 1 ) ;
15181
    end
15182
    begin
15183
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15184
        if ( wb_ok !== 1 )
15185
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15186
 
15187
        do_pause ( 2 ) ;
15188
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15189
        do_pause ( 16 ) ;
15190
 
15191 35 mihad
        #1 ;
15192
        if ( !error_monitor_done )
15193
            disable monitor_pci_error_3 ;
15194 15 mihad
    end
15195
    begin:monitor_pci_error_3
15196 35 mihad
        error_monitor_done = 0 ;
15197 15 mihad
        pci_ok = 1 ;
15198
        @(error_event_int) ;
15199
        pci_ok = 0 ;
15200
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15201 35 mihad
        error_monitor_done = 1 ;
15202 15 mihad
    end
15203
    join
15204
 
15205
    if ( !pci_ok || !wb_ok )
15206
    begin
15207
        disable main ;
15208
    end
15209
 
15210
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15211
    byte_enables = 4'b0011 ;
15212
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15213
 
15214
    master1_check_received_data = 1 ;
15215
    fork
15216
    begin
15217
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15218
        do_pause( 1 ) ;
15219
    end
15220
    begin
15221
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15222
        if ( wb_ok !== 1 )
15223
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15224
 
15225
        do_pause ( 2 ) ;
15226
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15227
        do_pause ( 16 ) ;
15228
 
15229 35 mihad
        #1 ;
15230
        if ( !error_monitor_done )
15231
            disable monitor_pci_error_4 ;
15232 15 mihad
    end
15233
    begin:monitor_pci_error_4
15234 35 mihad
        error_monitor_done = 0 ;
15235 15 mihad
        pci_ok = 1 ;
15236
        @(error_event_int) ;
15237
        pci_ok = 0 ;
15238
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15239 35 mihad
        error_monitor_done = 1 ;
15240 15 mihad
    end
15241
    join
15242
 
15243
    if ( !pci_ok || !wb_ok )
15244
    begin
15245
        disable main ;
15246
    end
15247
 
15248
    pci_address  = Target_Base_Addr_R[image_num] ;
15249
    byte_enables = 4'b0000 ;
15250
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15251
 
15252
    master1_check_received_data = 1 ;
15253
    fork
15254
    begin
15255
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15256
        do_pause( 1 ) ;
15257
    end
15258
    begin
15259
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15260
        if ( wb_ok !== 1 )
15261
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15262
 
15263
        do_pause ( 2 ) ;
15264
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15265
        do_pause ( 16 ) ;
15266
 
15267 35 mihad
        #1 ;
15268
        if ( !error_monitor_done )
15269
            disable monitor_pci_error_5 ;
15270 15 mihad
    end
15271
    begin:monitor_pci_error_5
15272 35 mihad
        error_monitor_done = 0 ;
15273 15 mihad
        pci_ok = 1 ;
15274
        @(error_event_int) ;
15275
        pci_ok = 0 ;
15276
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15277 35 mihad
        error_monitor_done = 1 ;
15278 15 mihad
    end
15279
    join
15280
 
15281
    if ( pci_ok && wb_ok )
15282
        test_ok ;
15283
end
15284
endtask // test_target_io_wr_rd
15285
 
15286
task test_target_io_err_wr ;
15287
    input [2:0]  image_num ;
15288
    input        translate_address ;
15289
    input [11:0] img_ctrl_offset ;
15290
    input        enable_error_report ;
15291
    input        enable_error_interrupt ;
15292
 
15293
    reg   [31:0] expect_address ;
15294
    reg   [31:0] pci_address ;
15295
    reg          translation ;
15296
    reg   [31:0] read_data ;
15297
    reg   [3:0]  byte_enables ;
15298
    reg          ok ;
15299
    reg          pci_ok ;
15300
    reg          wb_ok ;
15301
    integer      i ;
15302
    reg   [11:0] offset ;
15303 35 mihad
    reg          error_monitor_done ;
15304 15 mihad
begin:main
15305
    `ifdef ADDR_TRAN_IMPL
15306
        translation = translate_address ;
15307
    `else
15308
        translation = 0 ;
15309
    `endif
15310
 
15311
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15312
 
15313
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15314
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15315
    if ( translation )
15316
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15317
    else
15318
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15319
 
15320
    if ( !ok )
15321
    begin
15322
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15323
        test_fail("PCI Image Control register could not be written") ;
15324
    end
15325
 
15326
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15327
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15328
    if ( enable_error_report )
15329
    begin
15330
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15331
        if ( !ok )
15332
        begin
15333
            test_fail("PCI Error Control and Status register could not be written") ;
15334
            disable main ;
15335
        end
15336
    end
15337
    else
15338
    begin
15339
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15340
        if ( !ok )
15341
        begin
15342
            test_fail("PCI Error Control and Status register could not be written") ;
15343
            disable main ;
15344
        end
15345
    end
15346
 
15347
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15348
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15349
    if ( enable_error_interrupt )
15350
    begin
15351
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15352
        if ( !ok )
15353
        begin
15354
            test_fail("Interrupt Control register could not be written") ;
15355
            disable main ;
15356
        end
15357
    end
15358
    else
15359
    begin
15360
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15361
        if ( !ok )
15362
        begin
15363
            test_fail("Interrupt Control register could not be written") ;
15364
            disable main ;
15365
        end
15366
    end
15367
 
15368
    pci_address  = Target_Base_Addr_R[image_num] ;
15369
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15370
 
15371
    byte_enables = 4'b1111 ;
15372
 
15373
    for ( i = 0 ; i < 4 ; i = i + 1 )
15374
    begin:loop_1
15375
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15376
        byte_enables[i] = 0 ;
15377
        if ( i > 0 )
15378
            byte_enables[i - 1] = 1 ;
15379
 
15380
        fork
15381
        begin
15382
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15383
            do_pause ( 1 ) ;
15384
        end
15385
        begin
15386
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15387
            if ( wb_ok !== 1 )
15388
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15389
 
15390 35 mihad
            #1 ;
15391
            if ( !error_monitor_done )
15392
                disable monitor_pci_error_2 ;
15393 15 mihad
        end
15394
        begin:monitor_pci_error_2
15395 35 mihad
            error_monitor_done = 0 ;
15396 15 mihad
            pci_ok = 1 ;
15397
            @(error_event_int) ;
15398
            pci_ok = 0 ;
15399
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15400 35 mihad
            error_monitor_done = 1 ;
15401 15 mihad
        end
15402
        join
15403
 
15404
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15405
        `ifdef HOST
15406
 
15407
            repeat ( 4 )
15408
                @( posedge wb_clock ) ;
15409
 
15410
            if ( enable_error_interrupt && enable_error_report )
15411
            begin
15412
                if ( INT_O !== 1 )
15413
                begin
15414
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15415
                end
15416
            end
15417
            else
15418
            begin
15419
                if ( INT_O !== 0 )
15420
                begin
15421
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15422
                end
15423
            end
15424
        `else
15425
            repeat ( 4 )
15426
                @( posedge pci_clock ) ;
15427
 
15428
            if ( enable_error_interrupt && enable_error_report )
15429
            begin
15430
                if ( INTA !== 0 )
15431
                begin
15432
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15433
                end
15434
            end
15435
            else
15436
            begin
15437
                if ( INTA !== 1 )
15438
                begin
15439
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15440
                end
15441
            end
15442
        `endif
15443
 
15444
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15445
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15446
        config_read( offset, 4'hF, read_data ) ;
15447
        ok = 1 ;
15448
        if ( enable_error_report )
15449
        begin
15450
            if ( read_data[8] !== 1 )
15451
            begin
15452
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15453
                ok = 0 ;
15454
            end
15455
 
15456
            if ( read_data[9] !== 0 )
15457
            begin
15458
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15459
                ok = 0 ;
15460
            end
15461
 
15462
            if ( read_data[31:28] !== byte_enables )
15463
            begin
15464
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15465
                ok = 0 ;
15466
            end
15467
 
15468
            if ( read_data[27:24] !== `BC_IO_WRITE )
15469
            begin
15470
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15471
                ok = 0 ;
15472
            end
15473
 
15474
            if ( ok )
15475
                test_ok ;
15476
 
15477
            test_name = "CLEAR ERROR STATUS" ;
15478
            config_write( offset, read_data, 4'hF, ok ) ;
15479
            if ( !ok )
15480
                test_fail("PCI Error Control and Status register could not be written") ;
15481
 
15482
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15483
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15484
            config_read ( offset, 4'hf, read_data ) ;
15485
 
15486
            if ( read_data !== expect_address )
15487
            begin
15488
                test_fail("value in Erroneous Address register was incorrect") ;
15489
                ok = 0 ;
15490
            end
15491
 
15492
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15493
            config_read ( offset, 4'hf, read_data ) ;
15494
 
15495
            if ( read_data !== 32'hAAAA_AAAA )
15496
            begin
15497
                test_fail("value in Erroneous Data register was incorrect") ;
15498
                ok = 0 ;
15499
            end
15500
 
15501
            if ( ok )
15502
                test_ok ;
15503
 
15504
        end
15505
        else
15506
        begin
15507
            if ( read_data[8] !== 0 )
15508
            begin
15509
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15510
                ok = 0 ;
15511
            end
15512
            else
15513
                test_ok ;
15514
        end
15515
 
15516
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15517
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15518
        ok = 1 ;
15519
 
15520
        config_read ( offset, 4'hF, read_data ) ;
15521
        if ( enable_error_report && enable_error_interrupt )
15522
        begin
15523
            if ( read_data[2] !== 1 )
15524
            begin
15525
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15526
                ok = 0 ;
15527
            end
15528
 
15529
            test_name = "CLEARING INTERRUPT STATUS" ;
15530
            config_write( offset, read_data, 4'hF, ok ) ;
15531
            if ( !ok )
15532
                test_fail("Interrupt Status register could not be written") ;
15533
        end
15534
        else
15535
        begin
15536
            if ( read_data[2] !== 0 )
15537
            begin
15538
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15539
                ok = 0 ;
15540
            end
15541
        end
15542
 
15543
        if ( ok )
15544
            test_ok ;
15545
 
15546
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15547
        `ifdef HOST
15548
 
15549
            repeat ( 4 )
15550
                @( posedge wb_clock ) ;
15551
 
15552
            if ( INT_O !== 0 )
15553
            begin
15554
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15555
            end
15556
            else
15557
                test_ok ;
15558
 
15559
        `else
15560
            repeat ( 4 )
15561
                @( posedge pci_clock ) ;
15562
 
15563
            if ( INTA !== 1 )
15564
            begin
15565
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15566
            end
15567
            else
15568
                test_ok ;
15569
 
15570
        `endif
15571
 
15572
        pci_address = pci_address + 1 ;
15573
        expect_address = expect_address + 1 ;
15574
    end
15575
 
15576
end
15577
endtask // test_target_io_err_wr
15578
 
15579
task test_pci_image ;
15580
    input [2:0]  image_num ;
15581
    reg   [11:0] pci_ctrl_offset ;
15582
    reg   [11:0] ctrl_offset ;
15583
    reg   [11:0] ba_offset ;
15584
    reg   [11:0] am_offset ;
15585
    reg   [11:0] ta_offset ;
15586
    reg   [7:0]  cache_lsize ;
15587
    reg          ok ;
15588
    reg          test_io ;
15589
    reg          test_mem ;
15590
begin
15591
    pci_ctrl_offset = 12'h4 ;
15592
    if (image_num === 0)
15593
    begin
15594
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15595
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15596
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15597
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15598
    end
15599
    else if (image_num === 1)
15600
    begin
15601
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15602
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15603
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15604
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15605
    end
15606
    else if (image_num === 2)
15607
    begin
15608
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15609
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15610
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15611
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15612
    end
15613
    else if (image_num === 3)
15614
    begin
15615
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15616
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15617
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15618
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15619
    end
15620
    else if (image_num === 4)
15621
    begin
15622
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15623
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15624
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15625
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15626
    end
15627
    else if (image_num === 5)
15628
    begin
15629
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15630
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15631
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15632
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15633
    end
15634
 
15635
    `ifdef HOST
15636
        test_io  = 1 ;
15637
        test_mem = 1 ;
15638
    `else
15639
        if (image_num == 1)
15640
            test_io = `PCI_BA1_MEM_IO ;
15641
        else if ( image_num == 2 )
15642
            test_io = `PCI_BA2_MEM_IO ;
15643
        else if ( image_num == 3 )
15644
            test_io = `PCI_BA3_MEM_IO ;
15645
        else if ( image_num == 4 )
15646
            test_io = `PCI_BA4_MEM_IO ;
15647
        else if ( image_num == 5 )
15648
            test_io = `PCI_BA5_MEM_IO ;
15649
 
15650
        test_mem = !test_io ;
15651
    `endif
15652
 
15653
    $display(" ");
15654
    $display("########################################################################") ;
15655
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15656
    test_name = "PCI IMAGE SETTINGS" ;
15657
 
15658
    // Set Base Address of IMAGE
15659
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15660
    if ( ok !== 1 )
15661
    begin
15662
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15663
        test_fail("PCI Base Address register could not be written") ;
15664
    end
15665
 
15666
    // Set Address Mask of IMAGE
15667
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15668
    if ( ok !== 1 )
15669
    begin
15670
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15671
        test_fail("PCI Address Mask register could not be written") ;
15672
    end
15673
 
15674
    // Set Translation Address of IMAGE
15675
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15676
    if ( ok !== 1 )
15677
    begin
15678
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15679
        test_fail("PCI Translation Address register could not be written") ;
15680
    end
15681
 
15682
// Following are defines for byte enable signals !
15683
//      Byte Masks
15684
//      `Test_Byte_0                            (4'b1110)
15685
//      `Test_Byte_1                            (4'b1101)
15686
//      `Test_Byte_2                            (4'b1011)
15687
//      `Test_Byte_3                            (4'b0111)
15688
//      `Test_Half_0                            (4'b1100)
15689
//      `Test_Half_1                            (4'b0011)
15690
//      `Test_All_Bytes                         (4'b0000)
15691
 
15692
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15693
    // Set Cache Line Size
15694
    cache_lsize = 8'h4 ;
15695
 
15696
    $display(" ");
15697
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15698
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15699
    if ( ok !== 1 )
15700
    begin
15701
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15702
        test_fail("PCI Device Control and Status register could not be written") ;
15703
    end
15704
 
15705
    if (test_mem)
15706
    begin
15707
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15708
        // Task test_normal_wr_rd has the following parameters:
15709
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15710
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15711
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15712
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15713
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15714
 
15715
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15716
        // Set Cache Line Size
15717
        cache_lsize = 8'h4 ;
15718
 
15719
        $display(" ");
15720
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15721
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15722
        if ( ok !== 1 )
15723
        begin
15724
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15725
            test_fail("Cache Line Size register could not be written" ) ;
15726
        end
15727
 
15728
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15729
        // Task test_normal_wr_rd has the following parameters:
15730
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15731
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15732
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15733
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
15734
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
15735
 
15736
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15737
        // Set Cache Line Size
15738
        cache_lsize = 8'h8 ;
15739
 
15740
        $display(" ");
15741
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15742
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15743
        if ( ok !== 1 )
15744
        begin
15745
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15746
            test_fail("Cache Line Size register could not be written" ) ;
15747
        end
15748
 
15749
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
15750
        // Task test_normal_wr_rd has the following parameters:
15751
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15752
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15753
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15754
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
15755
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15756
 
15757
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15758
        // Set Cache Line Size
15759
        cache_lsize = 8'h4 ;
15760
 
15761
        $display(" ");
15762
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15763
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15764
        if ( ok !== 1 )
15765
        begin
15766
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15767
            test_fail("Cache Line Size register could not be written" ) ;
15768
        end
15769
 
15770
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
15771
        // Task test_normal_wr_rd has the following parameters:
15772
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15773
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15774
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15775
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
15776
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15777
 
15778
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15779
        $display(" ");
15780
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
15781
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15782
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15783
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
15784
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
15785
 
15786
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15787
        $display(" ");
15788
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
15789
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15790
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15791
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
15792
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
15793
 
15794
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15795
        $display(" ");
15796
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
15797
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15798
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15799
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
15800
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
15801
 
15802
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15803
        $display(" ");
15804
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
15805
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15806
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15807
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
15808
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
15809
    end
15810
 
15811
    if ( test_io )
15812
    begin
15813
        test_name = "PCI IMAGE SETTINGS" ;
15814
 
15815
        // Set Base Address of IMAGE
15816
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
15817
        if ( ok !== 1 )
15818
        begin
15819
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15820
            test_fail("PCI Base Address register could not be written") ;
15821
        end
15822
 
15823
        // Set Address Mask of IMAGE
15824
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15825
        if ( ok !== 1 )
15826
        begin
15827
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15828
            test_fail("PCI Address Mask register could not be written") ;
15829
        end
15830
 
15831
        // Set Translation Address of IMAGE
15832
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15833
        if ( ok !== 1 )
15834
        begin
15835
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15836
            test_fail("PCI Translation Address register could not be written") ;
15837
        end
15838
 
15839
        // Set Cache Line Size
15840
        cache_lsize = 8'h4 ;
15841
 
15842
        $display(" ");
15843
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15844
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15845
        if ( ok !== 1 )
15846
        begin
15847
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15848
            test_fail("Cache Line Size register could not be written" ) ;
15849
        end
15850
 
15851
        test_target_io_wr_rd
15852
        (
15853
            image_num,    // image number
15854
            0,            // test with address translation
15855
            ctrl_offset   // image control register offset
15856
        ) ;
15857
 
15858
        test_target_io_wr_rd
15859
        (
15860
            image_num,    // image number
15861
            1,            // test with address translation
15862
            ctrl_offset   // image control register offset
15863
        ) ;
15864
 
15865
        test_target_io_err_wr
15866
        (
15867
            image_num,      // image number
15868
            0,              // address translation on/off
15869
            ctrl_offset,    // image control register offset
15870
            0,              // enable error reporting
15871
 
15872
        ) ;
15873
 
15874
        test_target_io_err_wr
15875
        (
15876
            image_num,      // image number
15877
            1,              // address translation on/off
15878
            ctrl_offset,    // image control register offset
15879
            0,              // enable error reporting
15880
            1               // enable error interrupts
15881
        ) ;
15882
 
15883
        test_target_io_err_wr
15884
        (
15885
            image_num,      // image number
15886
            0,              // address translation on/off
15887
            ctrl_offset,    // image control register offset
15888
            1,              // enable error reporting
15889
 
15890
        ) ;
15891
 
15892
        test_target_io_err_wr
15893
        (
15894
            image_num,      // image number
15895
            1,              // address translation on/off
15896
            ctrl_offset,    // image control register offset
15897
            1,              // enable error reporting
15898
            1               // enable error interrupts
15899
        ) ;
15900
    end
15901
 
15902
    // Test master abort with NON supported commands
15903
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
15904
 
15905
    // disable the image
15906 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15907 15 mihad
end
15908
endtask //test_pci_image
15909
 
15910
task target_fast_back_to_back ;
15911
    reg   [11:0] pci_ctrl_offset ;
15912
    reg   [11:0] ctrl_offset ;
15913
    reg   [11:0] ba_offset ;
15914
    reg   [11:0] am_offset ;
15915
    reg   [11:0] ta_offset ;
15916
    reg   [11:0] cls_offset ;
15917
    reg          do_mem_fb2b ;
15918
    reg          do_io_fb2b ;
15919
    reg          ok ;
15920
begin:main
15921
 
15922
    if ( target_mem_image !== -1 )
15923
    begin
15924
        do_mem_fb2b = 1 ;
15925
 
15926
        if (target_mem_image === 1)
15927
        begin
15928
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15929
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15930
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15931
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15932
        end
15933
        else if (target_mem_image === 2)
15934
        begin
15935
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15936
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15937
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15938
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15939
        end
15940
        else if (target_mem_image === 3)
15941
        begin
15942
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15943
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15944
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15945
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15946
        end
15947
        else if (target_mem_image === 4)
15948
        begin
15949
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15950
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15951
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15952
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15953
        end
15954
        else if (target_mem_image === 5)
15955
        begin
15956
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15957
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15958
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15959
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15960
        end
15961
    end
15962
    else
15963
        do_mem_fb2b = 0 ;
15964
 
15965
    pci_ctrl_offset = 12'h4 ;
15966
    cls_offset      = 12'h00C ;
15967
 
15968
    if ( do_mem_fb2b )
15969
    begin
15970
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
15971
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
15972
        if ( ok !== 1 )
15973
        begin
15974
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
15975
            test_fail("PCI Base Address register could not be written") ;
15976
            disable main ;
15977
        end
15978
 
15979
        // Set Address Mask of IMAGE
15980
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
15981
        if ( ok !== 1 )
15982
        begin
15983
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15984
            test_fail("PCI Address Mask register could not be written") ;
15985
            disable main ;
15986
        end
15987
 
15988
        // Set Translation Address of IMAGE
15989
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
15990
        if ( ok !== 1 )
15991
        begin
15992
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
15993
            test_fail("PCI Translation Address Register could not be written") ;
15994
            disable main ;
15995
        end
15996
 
15997
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
15998
        if ( ok !== 1 )
15999
        begin
16000
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16001
            test_fail("PCI Image Control register could not be written") ;
16002
            disable main ;
16003
        end
16004
 
16005
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16006
        if ( ok !== 1 )
16007
        begin
16008
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16009
            test_fail("Cache Line Size register could not be written") ;
16010
            disable main ;
16011
        end
16012
 
16013
        // enable master 1 fast_b2b
16014 45 mihad
        configuration_cycle_write(0,                        // bus number
16015
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16016
                                  0,                        // function number
16017
                                  1,                        // register number
16018
                                  0,                        // type of configuration cycle
16019
                                  4'b1111,                  // byte enables
16020
                                  32'hFFFF_FFFF             // data
16021 15 mihad
                                 ) ;
16022
 
16023
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16024
 
16025
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16026
        fork
16027
        begin
16028
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16029
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16030
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16031
                  0, `Test_One_Zero_Target_WS,
16032
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16033
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16034
 
16035
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16036
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16037
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16038
                  0, `Test_One_Zero_Target_WS,
16039
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16040
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16041
            do_pause(5) ;
16042
 
16043
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16044
        end
16045
        begin:wb_monitor1
16046
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16047
            if ( ok !== 1 )
16048
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16049
 
16050
            disable monitor_error_event1 ;
16051
        end
16052
        begin:monitor_error_event1
16053
            @(error_event_int) ;
16054
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16055
            ok = 0 ;
16056
            disable wb_monitor1 ;
16057
        end
16058
        join
16059
 
16060
        if ( ok )
16061
            test_ok ;
16062
 
16063
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16064
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16065
        fork
16066
        begin
16067
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16068
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16069
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16070
                  0, `Test_One_Zero_Target_WS,
16071
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16072
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16073
 
16074
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16075
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16076
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16077
                  0, `Test_One_Zero_Target_WS,
16078
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16079
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16080
            do_pause(5) ;
16081
 
16082
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16083
 
16084
        end
16085
        begin:wb_monitor2
16086
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16087
            if ( ok !== 1 )
16088
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16089
            else
16090
            begin
16091
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16092
                if ( ok !== 1 )
16093
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16094
            end
16095
 
16096
            disable monitor_error_event2 ;
16097
        end
16098
        begin:monitor_error_event2
16099
            @(error_event_int) ;
16100
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16101
            ok = 0 ;
16102
            disable wb_monitor2 ;
16103
        end
16104
        join
16105
 
16106
        if ( ok )
16107
            test_ok ;
16108
 
16109
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16110
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16111
        fork
16112
        begin
16113
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16114
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16115
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16116
                  0, `Test_One_Zero_Target_WS,
16117
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16118
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16119
 
16120
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16121
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16122
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16123
                  0, `Test_One_Zero_Target_WS,
16124
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16125
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16126
            do_pause(5) ;
16127
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16128
 
16129
        end
16130
        begin:wb_monitor3
16131
            fork
16132
            begin
16133
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16134
                if ( ok !== 1 )
16135
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16136
            end
16137
            begin
16138
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16139
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16140
                if ( ok !== 1 )
16141
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16142
            end
16143
            join
16144
 
16145
            if ( ok )
16146
            begin
16147
                fork
16148
                begin
16149
                    do_pause(3) ;
16150
 
16151
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16152
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16153
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16154
                        0, `Test_One_Zero_Target_WS,
16155
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16156
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16157
 
16158
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16159
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16160
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16161
                            0, `Test_One_Zero_Target_WS,
16162
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16163
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16164
 
16165
                    do_pause(1) ;
16166
                end
16167
                begin
16168
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16169
                    if ( ok !== 1 )
16170
                    begin
16171
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16172
                        disable monitor_error_event3 ;
16173
                    end
16174
                    else
16175
                    begin
16176
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16177
                        if ( ok !== 1 )
16178
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16179
                    end
16180
                end
16181 26 mihad
                begin
16182
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16183
                        if ( ok !== 1 )
16184
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16185
                end
16186 15 mihad
                join
16187
            end
16188
            disable monitor_error_event3 ;
16189
        end
16190
        begin:monitor_error_event3
16191
            @(error_event_int) ;
16192
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16193
            ok = 0 ;
16194
            disable wb_monitor3 ;
16195
        end
16196
        join
16197
 
16198
        if ( ok )
16199
            test_ok ;
16200
 
16201
        test_name = "DISABLING MEM IMAGE" ;
16202 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16203 15 mihad
        if ( ok !== 1 )
16204
        begin
16205
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16206
            test_fail("PCI Address Mask register could not be written") ;
16207
            disable main ;
16208
        end
16209
    end
16210
 
16211
    if ( target_io_image !== -1 )
16212
    begin
16213
        do_io_fb2b = 1 ;
16214
 
16215
        if (target_io_image === 1)
16216
        begin
16217
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16218
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16219
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16220
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16221
        end
16222
        else if (target_io_image === 2)
16223
        begin
16224
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16225
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16226
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16227
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16228
        end
16229
        else if (target_io_image === 3)
16230
        begin
16231
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16232
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16233
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16234
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16235
        end
16236
        else if (target_io_image === 4)
16237
        begin
16238
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16239
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16240
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16241
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16242
        end
16243
        else if (target_io_image === 5)
16244
        begin
16245
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16246
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16247
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16248
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16249
        end
16250
    end
16251
    else
16252
        do_io_fb2b = 0 ;
16253
 
16254
    if ( do_io_fb2b )
16255
    begin
16256
 
16257
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16258
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16259
        if ( ok !== 1 )
16260
        begin
16261
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16262
            test_fail("PCI Base Address register could not be written") ;
16263
            disable main ;
16264
        end
16265
 
16266
        // Set Address Mask of IMAGE
16267
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16268
        if ( ok !== 1 )
16269
        begin
16270
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16271
            test_fail("PCI Address Mask register could not be written") ;
16272
            disable main ;
16273
        end
16274
 
16275
        // Set Translation Address of IMAGE
16276
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16277
        if ( ok !== 1 )
16278
        begin
16279
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16280
            test_fail("PCI Translation Address Register could not be written") ;
16281
            disable main ;
16282
        end
16283
 
16284
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16285
        if ( ok !== 1 )
16286
        begin
16287
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16288
            test_fail("PCI Image Control register could not be written") ;
16289
            disable main ;
16290
        end
16291
 
16292
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16293
        if ( ok !== 1 )
16294
        begin
16295
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16296
            test_fail("Cache Line Size register could not be written") ;
16297
            disable main ;
16298
        end
16299
 
16300
        // enable master 1 fast_b2b
16301 45 mihad
        configuration_cycle_write(0,                        // bus number
16302
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16303
                                  0,                        // function number
16304
                                  1,                        // register number
16305
                                  0,                        // type of configuration cycle
16306
                                  4'b1111,                  // byte enables
16307
                                  32'hFFFF_FFFF             // data
16308 15 mihad
                                 ) ;
16309
 
16310
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16311
 
16312
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16313
        fork
16314
        begin
16315
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16316
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16317
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16318
                  0, `Test_One_Zero_Target_WS,
16319
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16320
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16321
 
16322
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16323
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16324
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16325
                  0, `Test_One_Zero_Target_WS,
16326
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16327
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16328
            do_pause(5) ;
16329
 
16330
        end
16331
        begin:wb_monitor4
16332
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16333
            if ( ok !== 1 )
16334
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16335
 
16336
            if ( ok )
16337
            begin
16338
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16339
                if ( ok !== 1 )
16340
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16341
            end
16342
 
16343
            disable monitor_error_event4 ;
16344
        end
16345
        begin:monitor_error_event4
16346
            @(error_event_int) ;
16347
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16348
            ok = 0 ;
16349
            disable wb_monitor4 ;
16350
        end
16351
        join
16352
 
16353
        if ( ok )
16354
            test_ok ;
16355
 
16356
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16357
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16358
        fork
16359
        begin
16360
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16361
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16362
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16363
                  0, `Test_One_Zero_Target_WS,
16364
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16365
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16366
 
16367
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16368
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16369
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16370
                  0, `Test_One_Zero_Target_WS,
16371
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16372
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16373
            do_pause(5) ;
16374
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16375
        end
16376
        begin:wb_monitor5
16377
            fork
16378
            begin
16379
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16380
                if ( ok !== 1 )
16381
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16382
            end
16383
            begin
16384
                wb_transaction_stop( 1 ) ;
16385
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16386
                if ( ok !== 1 )
16387
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16388
            end
16389
            join
16390
 
16391
            if ( ok )
16392
            begin
16393
                fork
16394
                begin
16395
                    do_pause(3) ;
16396
 
16397
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16398
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16399
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16400
                            0, `Test_One_Zero_Target_WS,
16401
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16402
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16403
 
16404
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16405
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16406
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16407
                            0, `Test_One_Zero_Target_WS,
16408
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16409
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16410
 
16411
                    do_pause(1) ;
16412
                end
16413
                begin
16414
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16415
                    if ( ok !== 1 )
16416
                    begin
16417
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16418
                        disable monitor_error_event5 ;
16419
                    end
16420
                    else
16421
                    begin
16422
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16423
                        if ( ok !== 1 )
16424
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16425
                    end
16426
                end
16427
                join
16428
            end
16429
            disable monitor_error_event5 ;
16430
        end
16431
        begin:monitor_error_event5
16432
            @(error_event_int) ;
16433
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16434
            ok = 0 ;
16435
            disable wb_monitor5 ;
16436
        end
16437
        join
16438
 
16439
        if ( ok )
16440
            test_ok ;
16441
 
16442
        test_name = "DISABLING IO IMAGE" ;
16443 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16444 15 mihad
        if ( ok !== 1 )
16445
        begin
16446
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16447
            test_fail("PCI Address Mask register could not be written") ;
16448
            disable main ;
16449
        end
16450
    end
16451
 
16452
end
16453
endtask //target_fast_back_to_back
16454
 
16455
task target_disconnects ;
16456
    reg   [11:0] pci_ctrl_offset ;
16457
    reg   [11:0] ctrl_offset ;
16458
    reg   [11:0] ba_offset ;
16459
    reg   [11:0] am_offset ;
16460
    reg   [11:0] ta_offset ;
16461
    reg   [11:0] cls_offset ;
16462
    reg          pci_ok ;
16463
    reg          wb_ok ;
16464
    reg          ok ;
16465
    reg   [31:0] pci_address ;
16466
    reg   [31:0] data ;
16467
    reg   [3:0]  byte_enables ;
16468
    reg   [9:0]  expect_length ;
16469
 
16470
    reg          do_mem_disconnects ;
16471
    reg          do_io_disconnects ;
16472 35 mihad
    reg          error_monitor_done ;
16473 15 mihad
begin:main
16474
    if ( target_mem_image !== -1 )
16475
    begin
16476
        do_mem_disconnects = 1 ;
16477
 
16478
        if (target_mem_image === 1)
16479
        begin
16480
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16481
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16482
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16483
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16484
        end
16485
        else if (target_mem_image === 2)
16486
        begin
16487
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16488
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16489
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16490
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16491
        end
16492
        else if (target_mem_image === 3)
16493
        begin
16494
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16495
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16496
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16497
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16498
        end
16499
        else if (target_mem_image === 4)
16500
        begin
16501
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16502
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16503
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16504
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16505
        end
16506
        else if (target_mem_image === 5)
16507
        begin
16508
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16509
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16510
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16511
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16512
        end
16513
    end
16514
    else
16515
        do_mem_disconnects = 0 ;
16516
 
16517
    pci_ctrl_offset = 12'h4 ;
16518
    cls_offset = 12'h00C ;
16519
 
16520
    master1_check_received_data = 0 ;
16521
    master2_check_received_data = 0 ;
16522
 
16523
    `ifdef HOST
16524
        `ifdef NO_CNF_IMAGE
16525
        `else
16526
            `define TEST_BURST_CONFIG_READ
16527
        `endif
16528
    `else
16529
        `define TEST_BURST_CONFIG_READ
16530
        `define TEST_BURST_CONFIG_WRITE
16531
    `endif
16532
 
16533
    `ifdef TEST_BURST_CONFIG_WRITE
16534
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16535
 
16536
        data = 32'h0000_08_08 ;
16537
 
16538 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16539 15 mihad
        byte_enables = 4'b0000 ;
16540
 
16541
        fork
16542
        begin
16543
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16544
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16545
                    byte_enables,
16546
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16547
                    8'h0_0, `Test_One_Zero_Target_WS,
16548
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16549
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16550
 
16551
            data = 32'h0000_04_04 ;
16552
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16553
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16554
                    byte_enables,
16555
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16556
                    8'h0_0, `Test_One_Zero_Target_WS,
16557
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16558
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16559
            do_pause( 1 ) ;
16560
            while ( FRAME !== 1 || IRDY !== 1 )
16561
                @(posedge pci_clock) ;
16562
 
16563 35 mihad
            #1 ;
16564
            if ( !error_monitor_done )
16565
                disable monitor_error_event1 ;
16566 15 mihad
        end
16567
        begin:monitor_error_event1
16568 35 mihad
            error_monitor_done = 0 ;
16569 15 mihad
            ok = 1 ;
16570
            @(error_event_int) ;
16571
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16572
            ok = 0 ;
16573 35 mihad
            error_monitor_done = 1 ;
16574 15 mihad
        end
16575
        join
16576
 
16577
        config_read(pci_address, 4'hF, data) ;
16578
        if ( data [15:0] !== 16'h04_04 )
16579
        begin
16580
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16581
        end
16582
        else if ( ok )
16583
            test_ok ;
16584
 
16585 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16586
 
16587
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16588 15 mihad
        data         = 32'h0000_0808 ;
16589
        byte_enables = 4'h0 ;
16590
        fork
16591
        begin
16592
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16593
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16594
                    byte_enables,
16595
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16596
                    8'h0_0, `Test_One_Zero_Target_WS,
16597
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16598
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16599
 
16600
            data = 32'h0000_04_04 ;
16601
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16602
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16603
                    byte_enables,
16604
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16605
                    8'h0_0, `Test_One_Zero_Target_WS,
16606
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16607
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16608
 
16609
            do_pause( 1 ) ;
16610
            while ( FRAME !== 1 || IRDY !== 1 )
16611
                @(posedge pci_clock) ;
16612
 
16613 35 mihad
            #1 ;
16614
            if ( !error_monitor_done )
16615
                disable monitor_error_event2 ;
16616 15 mihad
        end
16617
        begin:monitor_error_event2
16618 35 mihad
            error_monitor_done = 0 ;
16619 15 mihad
            ok = 1 ;
16620
            @(error_event_int) ;
16621
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16622
            ok = 0 ;
16623 35 mihad
            error_monitor_done = 1 ;
16624 15 mihad
        end
16625
        join
16626
 
16627
        config_read(pci_address, 4'hF, data) ;
16628
        if ( data [15:0] !== 16'h04_04 )
16629
        begin
16630
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16631
        end
16632
        else if ( ok )
16633
            test_ok ;
16634
    `endif
16635
 
16636
    `ifdef TEST_BURST_CONFIG_READ
16637
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16638
 
16639
        data = 32'h0000_04_04 ;
16640
 
16641 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16642 15 mihad
        byte_enables = 4'b0000 ;
16643
 
16644
        fork
16645
        begin
16646
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16647
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16648
                    byte_enables,
16649
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16650
                    8'h0_0, `Test_One_Zero_Target_WS,
16651
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16652
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16653
            do_pause( 1 ) ;
16654
 
16655
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16656
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16657
                    byte_enables,
16658
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16659
                    8'h0_0, `Test_One_Zero_Target_WS,
16660
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16661
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16662
            do_pause( 1 ) ;
16663
 
16664
            while ( FRAME !== 1 || IRDY !== 1 )
16665
                @(posedge pci_clock) ;
16666
 
16667 35 mihad
            if ( !error_monitor_done )
16668
                disable monitor_error_event3 ;
16669 15 mihad
        end
16670
        begin:monitor_error_event3
16671 35 mihad
            error_monitor_done = 0 ;
16672 15 mihad
            ok = 1 ;
16673
            @(error_event_int) ;
16674
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16675
            ok = 0 ;
16676 35 mihad
            error_monitor_done = 1 ;
16677 15 mihad
        end
16678
        join
16679
 
16680
        if ( ok )
16681
            test_ok ;
16682
 
16683 45 mihad
 
16684
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16685
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16686 15 mihad
        fork
16687
        begin
16688
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16689
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16690
                    byte_enables,
16691
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16692
                    8'h0_0, `Test_One_Zero_Target_WS,
16693
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16694
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16695
            do_pause( 1 ) ;
16696
 
16697
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16698
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16699
                    byte_enables,
16700
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16701
                    8'h0_0, `Test_One_Zero_Target_WS,
16702
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16703
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16704
            do_pause( 1 ) ;
16705
 
16706
            while ( FRAME !== 1 || IRDY !== 1 )
16707
                @(posedge pci_clock) ;
16708
 
16709 35 mihad
            #1 ;
16710
            if ( !error_monitor_done )
16711
                disable monitor_error_event4 ;
16712 15 mihad
        end
16713
        begin:monitor_error_event4
16714 35 mihad
            error_monitor_done = 0 ;
16715 15 mihad
            ok = 1 ;
16716
            @(error_event_int) ;
16717
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16718
            ok = 0 ;
16719 35 mihad
            error_monitor_done = 1 ;
16720 15 mihad
        end
16721
        join
16722
 
16723
        if ( ok )
16724
            test_ok ;
16725
    `endif
16726
 
16727
    `ifdef TEST_BURST_CONFIG_READ
16728
        `undef TEST_BURST_CONFIG_READ
16729
    `endif
16730
 
16731
    `ifdef TEST_BURST_CONFIG_WRITE
16732
        `undef TEST_BURST_CONFIG_WRITE
16733
    `endif
16734
 
16735
    master1_check_received_data = 1 ;
16736
    master2_check_received_data = 1 ;
16737
 
16738
    if ( do_mem_disconnects )
16739
    begin
16740
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
16741
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16742
        if ( ok !== 1 )
16743
        begin
16744
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16745
            test_fail("PCI Base Address register could not be written") ;
16746
            disable main ;
16747
        end
16748
 
16749
        // Set Address Mask of IMAGE
16750
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16751
        if ( ok !== 1 )
16752
        begin
16753
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16754
            test_fail("PCI Address Mask register could not be written") ;
16755
            disable main ;
16756
        end
16757
 
16758
        // Set Translation Address of IMAGE
16759
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16760
        if ( ok !== 1 )
16761
        begin
16762
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16763
            test_fail("PCI Translation Address Register could not be written") ;
16764
            disable main ;
16765
        end
16766
 
16767
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16768
        if ( ok !== 1 )
16769
        begin
16770
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16771
            test_fail("PCI Image Control register could not be written") ;
16772
            disable main ;
16773
        end
16774
 
16775
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
16776
        if ( ok !== 1 )
16777
        begin
16778
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16779
            test_fail("Cache Line Size register could not be written") ;
16780
            disable main ;
16781
        end
16782
 
16783
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16784
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16785
        data = 32'hAAAA_AAAA ;
16786
        byte_enables = 4'h0 ;
16787
        expect_length = `PCIW_DEPTH - 2 ;
16788
 
16789
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16790
        fork
16791
        begin
16792
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
16793
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16794
                        byte_enables,
16795
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
16796
                        8'h0_0, `Test_One_Zero_Target_WS,
16797
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16798
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16799
            do_pause( 3 ) ;
16800
 
16801
            while ( FRAME !== 1 || IRDY !== 1 )
16802
                @(posedge pci_clock) ;
16803
 
16804 35 mihad
            #1 ;
16805
            if ( !error_monitor_done )
16806
                disable monitor_error_event5 ;
16807 15 mihad
        end
16808
        begin:monitor_error_event5
16809 35 mihad
            error_monitor_done = 0 ;
16810 15 mihad
            pci_ok = 1 ;
16811
            @(error_event_int) ;
16812
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
16813
            pci_ok = 0 ;
16814 35 mihad
            error_monitor_done = 1 ;
16815 15 mihad
        end
16816
        begin
16817
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
16818
            if ( wb_ok !== 1 )
16819
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16820
        end
16821
        join
16822
 
16823
        if ( wb_ok && pci_ok )
16824
            test_ok ;
16825
 
16826
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16827
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16828
        data = 32'hAAAA_AAAA ;
16829
        byte_enables = 4'h0 ;
16830
        expect_length = `PCIW_DEPTH - 2 ;
16831
 
16832
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16833
        fork
16834
        begin
16835
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
16836
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16837
                        byte_enables,
16838
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
16839
                        8'h0_0, `Test_One_Zero_Target_WS,
16840
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16841
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16842
            do_pause( 3 ) ;
16843
 
16844
            while ( FRAME !== 1 || IRDY !== 1 )
16845
                @(posedge pci_clock) ;
16846
 
16847 35 mihad
            #1 ;
16848
            if ( !error_monitor_done )
16849
                disable monitor_error_event6 ;
16850 15 mihad
        end
16851
        begin:monitor_error_event6
16852 35 mihad
            error_monitor_done = 0 ;
16853 15 mihad
            pci_ok = 1 ;
16854
            @(error_event_int) ;
16855
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
16856
            pci_ok = 0 ;
16857 35 mihad
            error_monitor_done = 1 ;
16858 15 mihad
        end
16859
        begin
16860
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
16861
            if ( wb_ok !== 1 )
16862
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16863
        end
16864
        join
16865
 
16866
        if ( wb_ok && pci_ok )
16867
            test_ok ;
16868
 
16869
        master1_check_received_data = 1 ;
16870
//        master2_check_received_data = 0 ;
16871
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
16872
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16873
        data = 32'hAAAA_AAAA ;
16874
        byte_enables = 4'h0 ;
16875
        expect_length = 4 ;
16876
 
16877
        fork
16878
        begin
16879
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16880
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
16881
                        byte_enables,
16882
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16883
                        8'h0_0, `Test_One_Zero_Target_WS,
16884
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16885
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16886
            do_pause( 1 ) ;
16887
 
16888
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
16889
            if ( wb_ok !== 1 )
16890
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16891
 
16892
            do_pause(2) ;
16893
 
16894
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16895
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
16896
                        byte_enables,
16897
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16898
                        8'h0_0, `Test_One_Zero_Target_WS,
16899
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16900
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
16901
            do_pause( 3 ) ;
16902
 
16903
            while ( FRAME !== 1 || IRDY !== 1 )
16904
                @(posedge pci_clock) ;
16905
 
16906 35 mihad
            #1 ;
16907
            if ( !error_monitor_done )
16908
                disable monitor_error_event7 ;
16909 15 mihad
        end
16910
        begin:monitor_error_event7
16911 35 mihad
            error_monitor_done = 0 ;
16912 15 mihad
            pci_ok = 1 ;
16913
            @(error_event_int) ;
16914
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
16915
            pci_ok = 0 ;
16916 35 mihad
            error_monitor_done = 1 ;
16917 15 mihad
        end
16918
        join
16919
 
16920
        if ( wb_ok && pci_ok )
16921
            test_ok ;
16922
 
16923
        master1_check_received_data = 1 ;
16924
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
16925
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16926
        data = 32'hAAAA_AAAA ;
16927
        byte_enables = 4'h0 ;
16928
        expect_length = 4 ;
16929
 
16930
        fork
16931
        begin
16932
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16933
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
16934
                        byte_enables,
16935
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16936
                        8'h0_0, `Test_One_Zero_Target_WS,
16937
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16938
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16939
            do_pause( 1 ) ;
16940
 
16941
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
16942
            if ( wb_ok !== 1 )
16943
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16944
 
16945
            do_pause(2) ;
16946
 
16947
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16948
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
16949
                        byte_enables,
16950
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16951
                        8'h0_0, `Test_One_Zero_Target_WS,
16952
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16953
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
16954
            do_pause( 3 ) ;
16955
 
16956
            while ( FRAME !== 1 || IRDY !== 1 )
16957
                @(posedge pci_clock) ;
16958
 
16959 35 mihad
            #1 ;
16960
            if ( !error_monitor_done )
16961
                disable monitor_error_event8 ;
16962 15 mihad
        end
16963
        begin:monitor_error_event8
16964 35 mihad
            error_monitor_done = 0 ;
16965 15 mihad
            pci_ok = 1 ;
16966
            @(error_event_int) ;
16967
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
16968
            pci_ok = 0 ;
16969 35 mihad
            error_monitor_done = 1 ;
16970 15 mihad
        end
16971
        join
16972
 
16973
        if ( wb_ok && pci_ok )
16974
            test_ok ;
16975
 
16976
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
16977
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
16978
        data = 32'hDEAF_BEAF ;
16979
        byte_enables = 4'h0 ;
16980
        expect_length = 1 ;
16981
 
16982
        fork
16983
        begin
16984
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
16985
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16986
                        byte_enables,
16987
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16988
                        8'h0_0, `Test_One_Zero_Target_WS,
16989
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16990
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16991
            do_pause( 3 ) ;
16992
 
16993
            while ( FRAME !== 1 || IRDY !== 1 )
16994
                @(posedge pci_clock) ;
16995
 
16996 35 mihad
            #1 ;
16997
            if ( !error_monitor_done )
16998
                disable monitor_error_event9 ;
16999 15 mihad
        end
17000
        begin:monitor_error_event9
17001 35 mihad
            error_monitor_done = 0 ;
17002 15 mihad
            pci_ok = 1 ;
17003
            @(error_event_int) ;
17004
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17005
            pci_ok = 0 ;
17006 35 mihad
            error_monitor_done = 1 ;
17007 15 mihad
        end
17008
        begin
17009
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17010
            if ( wb_ok !== 1 )
17011
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17012
        end
17013
        join
17014
 
17015
        if ( wb_ok && pci_ok )
17016
            test_ok ;
17017
 
17018
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17019
        data = 32'hDEAD_BEAF ;
17020
        byte_enables = 4'h0 ;
17021
        expect_length = 1 ;
17022
 
17023
        fork
17024
        begin
17025
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17026
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17027
                        byte_enables,
17028
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17029
                        8'h0_0, `Test_One_Zero_Target_WS,
17030
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17031
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17032
            do_pause( 3 ) ;
17033
 
17034
            while ( FRAME !== 1 || IRDY !== 1 )
17035
                @(posedge pci_clock) ;
17036
 
17037 35 mihad
            #1 ;
17038
            if ( !error_monitor_done )
17039
                disable monitor_error_event10 ;
17040 15 mihad
        end
17041
        begin:monitor_error_event10
17042 35 mihad
            error_monitor_done = 0 ;
17043 15 mihad
            pci_ok = 1 ;
17044
            @(error_event_int) ;
17045
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17046
            pci_ok = 0 ;
17047 35 mihad
            error_monitor_done = 1 ;
17048 15 mihad
        end
17049
        begin
17050
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17051
            if ( wb_ok !== 1 )
17052
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17053
        end
17054
        join
17055
 
17056
        if ( wb_ok && pci_ok )
17057
            test_ok ;
17058
 
17059
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17060
        data = 32'hAAAA_AAAA ;
17061
        byte_enables = 4'h0 ;
17062
        expect_length = 1 ;
17063
 
17064
        fork
17065
        begin
17066
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17067
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17068
                        byte_enables,
17069
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17070
                        8'h0_0, `Test_One_Zero_Target_WS,
17071
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17072
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17073
            do_pause( 3 ) ;
17074
 
17075
            while ( FRAME !== 1 || IRDY !== 1 )
17076
                @(posedge pci_clock) ;
17077
 
17078 35 mihad
            #1 ;
17079
            if ( !error_monitor_done )
17080
                disable monitor_error_event11 ;
17081 15 mihad
        end
17082
        begin:monitor_error_event11
17083 35 mihad
            error_monitor_done = 0 ;
17084 15 mihad
            pci_ok = 1 ;
17085
            @(error_event_int) ;
17086
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17087
            pci_ok = 0 ;
17088 35 mihad
            error_monitor_done = 1 ;
17089 15 mihad
        end
17090
        begin
17091
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17092
            if ( wb_ok !== 1 )
17093
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17094
        end
17095
        join
17096
 
17097
        if ( wb_ok && pci_ok )
17098
            test_ok ;
17099
 
17100
        master1_check_received_data = 1 ;
17101
 
17102
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17103
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17104
        data = 32'hDEAF_BEAF ;
17105
        byte_enables = 4'h0 ;
17106
        expect_length = 1 ;
17107
 
17108
        fork
17109
        begin
17110
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17111
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17112
                        byte_enables,
17113
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17114
                        8'h0_0, `Test_One_Zero_Target_WS,
17115
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17116
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17117
            do_pause( 1 ) ;
17118
 
17119
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17120
            if ( wb_ok !== 1 )
17121
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17122
 
17123
            do_pause(3) ;
17124
 
17125
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17126
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17127
                        byte_enables,
17128
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17129
                        8'h0_0, `Test_One_Zero_Target_WS,
17130
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17131
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17132
            do_pause( 3 ) ;
17133
 
17134
            while ( FRAME !== 1 || IRDY !== 1 )
17135
                @(posedge pci_clock) ;
17136
 
17137 35 mihad
            #1 ;
17138
            if ( !error_monitor_done )
17139
                disable monitor_error_event12 ;
17140 15 mihad
        end
17141
        begin:monitor_error_event12
17142 35 mihad
            error_monitor_done = 0 ;
17143 15 mihad
            pci_ok = 1 ;
17144
            @(error_event_int) ;
17145
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17146
            pci_ok = 0 ;
17147 35 mihad
            error_monitor_done = 1 ;
17148 15 mihad
        end
17149
        join
17150
 
17151
        if ( wb_ok && pci_ok )
17152
            test_ok ;
17153
 
17154
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17155
        data = 32'hDEAD_BEAF ;
17156
        byte_enables = 4'h0 ;
17157
        expect_length = 1 ;
17158
 
17159
        fork
17160
        begin
17161
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17162
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17163
                        byte_enables,
17164
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17165
                        8'h0_0, `Test_One_Zero_Target_WS,
17166
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17167
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17168
            do_pause( 1 ) ;
17169
 
17170
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17171
            if ( wb_ok !== 1 )
17172
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17173
 
17174
            do_pause(3) ;
17175
 
17176
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17177
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17178
                        byte_enables,
17179
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17180
                        8'h0_0, `Test_One_Zero_Target_WS,
17181
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17182
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17183
            do_pause( 3 ) ;
17184
 
17185
            while ( FRAME !== 1 || IRDY !== 1 )
17186
                @(posedge pci_clock) ;
17187
 
17188 35 mihad
            #1 ;
17189
            if ( !error_monitor_done )
17190
                disable monitor_error_event13 ;
17191 15 mihad
        end
17192
        begin:monitor_error_event13
17193 35 mihad
            error_monitor_done = 0 ;
17194 15 mihad
            pci_ok = 1 ;
17195
            @(error_event_int) ;
17196
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17197
            pci_ok = 0 ;
17198 35 mihad
            error_monitor_done = 1 ;
17199 15 mihad
        end
17200
        join
17201
 
17202
        if ( wb_ok && pci_ok )
17203
            test_ok ;
17204
 
17205
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17206
        data = 32'hAAAA_AAAA ;
17207
        byte_enables = 4'h0 ;
17208
        expect_length = 1 ;
17209
 
17210
        fork
17211
        begin
17212
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17213
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17214
                        byte_enables,
17215
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17216
                        8'h0_0, `Test_One_Zero_Target_WS,
17217
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17218
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17219
            do_pause( 1 ) ;
17220
 
17221
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17222
            if ( wb_ok !== 1 )
17223
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17224
 
17225
            do_pause(3) ;
17226
 
17227
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17228
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17229
                        byte_enables,
17230
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17231
                        8'h0_0, `Test_One_Zero_Target_WS,
17232
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17233
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17234
            do_pause( 3 ) ;
17235
 
17236
            while ( FRAME !== 1 || IRDY !== 1 )
17237
                @(posedge pci_clock) ;
17238
 
17239 35 mihad
            #1 ;
17240
            if ( !error_monitor_done )
17241
                disable monitor_error_event14 ;
17242 15 mihad
        end
17243
        begin:monitor_error_event14
17244 35 mihad
            error_monitor_done = 0 ;
17245 15 mihad
            pci_ok = 1 ;
17246
            @(error_event_int) ;
17247
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17248
            pci_ok = 0 ;
17249 35 mihad
            error_monitor_done = 1 ;
17250 15 mihad
        end
17251
        join
17252
 
17253
        if ( wb_ok && pci_ok )
17254
            test_ok ;
17255
 
17256
        // disable the image
17257
        test_name = "DISABLING MEMORY IMAGE" ;
17258 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17259 15 mihad
        if ( ok !== 1 )
17260
        begin
17261
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17262
            test_fail("PCI Address Mask register could not be written") ;
17263
            disable main ;
17264
        end
17265
    end
17266
//*
17267
    if ( target_io_image !== -1 )
17268
    begin
17269
        do_io_disconnects = 1 ;
17270
 
17271
        if (target_io_image === 1)
17272
        begin
17273
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17274
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17275
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17276
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17277
        end
17278
        else if (target_io_image === 2)
17279
        begin
17280
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17281
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17282
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17283
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17284
        end
17285
        else if (target_io_image === 3)
17286
        begin
17287
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17288
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17289
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17290
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17291
        end
17292
        else if (target_io_image === 4)
17293
        begin
17294
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17295
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17296
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17297
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17298
        end
17299
        else if (target_io_image === 5)
17300
        begin
17301
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17302
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17303
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17304
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17305
        end
17306
    end
17307
    else
17308
        do_io_disconnects = 0 ;
17309
 
17310
    if ( do_io_disconnects )
17311
    begin
17312
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17313
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17314
        if ( ok !== 1 )
17315
        begin
17316
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17317
            test_fail("PCI Base Address register could not be written") ;
17318
            disable main ;
17319
        end
17320
 
17321
        // Set Address Mask of IMAGE
17322
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17323
        if ( ok !== 1 )
17324
        begin
17325
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17326
            test_fail("PCI Address Mask register could not be written") ;
17327
            disable main ;
17328
        end
17329
 
17330
        // Set Translation Address of IMAGE
17331
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17332
        if ( ok !== 1 )
17333
        begin
17334
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17335
            test_fail("PCI Translation Address Register could not be written") ;
17336
            disable main ;
17337
        end
17338
 
17339
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17340
        if ( ok !== 1 )
17341
        begin
17342
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17343
            test_fail("PCI Image Control register could not be written") ;
17344
            disable main ;
17345
        end
17346
 
17347
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17348
        if ( ok !== 1 )
17349
        begin
17350
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17351
            test_fail("Cache Line Size register could not be written") ;
17352
            disable main ;
17353
        end
17354
 
17355
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17356
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17357
        data = 32'h5555_5555 ;
17358
        byte_enables = 4'h0 ;
17359
        expect_length = 1 ;
17360
 
17361
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17362
 
17363
        fork
17364
        begin
17365
            PCIU_IO_WRITE
17366
            (
17367
                `Test_Master_1,             // which master
17368
                pci_address,                // to what address
17369
                data,                       // data
17370
                byte_enables,               // byte enable
17371
                expect_length + 1,          // length to request
17372
                `Test_Target_Retry_On       // expected target termination
17373
            ) ;
17374
 
17375
            do_pause( 3 ) ;
17376
 
17377
            while ( FRAME !== 1 || IRDY !== 1 )
17378
                @(posedge pci_clock) ;
17379
 
17380 35 mihad
            #1 ;
17381
            if ( !error_monitor_done )
17382
                disable monitor_error_event15 ;
17383 15 mihad
        end
17384
        begin:monitor_error_event15
17385 35 mihad
            error_monitor_done = 0 ;
17386 15 mihad
            pci_ok = 1 ;
17387
            @(error_event_int) ;
17388
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17389
            pci_ok = 0 ;
17390 35 mihad
            error_monitor_done = 1 ;
17391 15 mihad
        end
17392
        begin
17393
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17394
            if ( wb_ok !== 1 )
17395
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17396
        end
17397
        join
17398
 
17399
        if ( wb_ok && pci_ok )
17400
            test_ok ;
17401
 
17402
        data = 32'hAAAA_AAAA ;
17403
        fork
17404
        begin
17405
            PCIU_IO_WRITE
17406
            (
17407
                `Test_Master_1,             // which master
17408
                pci_address,                // to what address
17409
                data,                       // data
17410
                byte_enables,               // byte enable
17411
                expect_length + 2,          // length to request
17412
                `Test_Target_Retry_Before   // expected target termination
17413
            ) ;
17414
 
17415
            do_pause( 3 ) ;
17416
 
17417
            while ( FRAME !== 1 || IRDY !== 1 )
17418
                @(posedge pci_clock) ;
17419
 
17420 35 mihad
            #1 ;
17421
            if ( !error_monitor_done )
17422
                disable monitor_error_event16 ;
17423 15 mihad
        end
17424
        begin:monitor_error_event16
17425 35 mihad
            error_monitor_done = 0 ;
17426 15 mihad
            pci_ok = 1 ;
17427
            @(error_event_int) ;
17428
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17429
            pci_ok = 0 ;
17430 35 mihad
            error_monitor_done = 1 ;
17431 15 mihad
        end
17432
        begin
17433
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17434
            if ( wb_ok !== 1 )
17435
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17436
        end
17437
        join
17438
 
17439
        if ( wb_ok && pci_ok )
17440
            test_ok ;
17441
 
17442
        master2_check_received_data = 1 ;
17443
 
17444
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17445
 
17446
        fork
17447
        begin
17448
 
17449
             PCIU_IO_READ
17450
             (
17451
                `Test_Master_2,
17452
                pci_address[PCI_BUS_DATA_RANGE:0],
17453
                data,
17454
                byte_enables,
17455
                2,
17456
                `Test_Target_Retry_Before
17457
             );
17458
 
17459
            do_pause( 1 ) ;
17460
 
17461
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17462
            if ( wb_ok !== 1 )
17463
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17464
 
17465
            do_pause(3) ;
17466
 
17467
            PCIU_IO_READ
17468
             (
17469
                `Test_Master_2,
17470
                pci_address[PCI_BUS_DATA_RANGE:0],
17471
                data,
17472
                byte_enables,
17473
                expect_length + 1,
17474
                `Test_Target_Retry_On
17475
             );
17476
 
17477
            do_pause( 3 ) ;
17478
 
17479
            while ( FRAME !== 1 || IRDY !== 1 )
17480
                @(posedge pci_clock) ;
17481
 
17482 35 mihad
            #1 ;
17483
            if ( !error_monitor_done )
17484
                disable monitor_error_event17 ;
17485 15 mihad
        end
17486
        begin:monitor_error_event17
17487 35 mihad
            error_monitor_done = 0 ;
17488 15 mihad
            pci_ok = 1 ;
17489
            @(error_event_int) ;
17490
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17491
            pci_ok = 0 ;
17492 35 mihad
            error_monitor_done = 1 ;
17493 15 mihad
        end
17494
        join
17495
 
17496
        if ( wb_ok && pci_ok )
17497
            test_ok ;
17498
 
17499
        fork
17500
        begin
17501
 
17502
             PCIU_IO_READ
17503
             (
17504
                `Test_Master_2,
17505
                pci_address[PCI_BUS_DATA_RANGE:0],
17506
                data,
17507
                byte_enables,
17508
                2,
17509
                `Test_Target_Retry_Before
17510
             );
17511
 
17512
            do_pause( 1 ) ;
17513
 
17514
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17515
            if ( wb_ok !== 1 )
17516
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17517
 
17518
            do_pause(3) ;
17519
 
17520
            PCIU_IO_READ
17521
             (
17522
                `Test_Master_2,
17523
                pci_address[PCI_BUS_DATA_RANGE:0],
17524
                data,
17525
                byte_enables,
17526
                expect_length + 2,
17527
                `Test_Target_Retry_Before
17528
             );
17529
 
17530
            do_pause( 3 ) ;
17531
 
17532
            while ( FRAME !== 1 || IRDY !== 1 )
17533
                @(posedge pci_clock) ;
17534
 
17535 35 mihad
            #1 ;
17536
            if ( !error_monitor_done )
17537
                disable monitor_error_event18 ;
17538 15 mihad
        end
17539
        begin:monitor_error_event18
17540 35 mihad
            error_monitor_done = 0 ;
17541 15 mihad
            pci_ok = 1 ;
17542
            @(error_event_int) ;
17543
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17544
            pci_ok = 0 ;
17545 35 mihad
            error_monitor_done = 1 ;
17546 15 mihad
        end
17547
        join
17548
 
17549
        if ( wb_ok && pci_ok )
17550
            test_ok ;
17551
 
17552
        test_name = "DISABLING IO IMAGE" ;
17553 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17554 15 mihad
        if ( ok !== 1 )
17555
        begin
17556
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17557
            test_fail("PCI Address Mask register could not be written") ;
17558
            disable main ;
17559
        end
17560
    end
17561
//*/
17562
end
17563
endtask // target_disconnects
17564
 
17565
task target_unsupported_cmds ;
17566
        input [31:0] Address;
17567
        input [2:0]  image_num ;
17568
    reg          ok ;
17569
begin:main
17570
 
17571
    $display("  ") ;
17572
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17573
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17574 45 mihad
 
17575
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17576
    configuration_cycle_write
17577
    (
17578
        0,                        // bus number
17579
        `TAR1_IDSEL_INDEX - 11,   // device number
17580
        0,                        // function number
17581
        1,                        // register number
17582
        0,                        // type of configuration cycle
17583
        4'b0001,                  // byte enables
17584
        32'h0000_0044             // data
17585
    ) ;
17586
 
17587
    configuration_cycle_write
17588
    (
17589
        0,                        // bus number
17590
        `TAR2_IDSEL_INDEX - 11,   // device number
17591
        0,                        // function number
17592
        1,                        // register number
17593
        0,                        // type of configuration cycle
17594
        4'b0001,                  // byte enables
17595
        32'h0000_0044             // data
17596
    ) ;
17597
 
17598 15 mihad
    ipci_unsupported_commands_master.master_reference
17599
    (
17600
        Address,                // first part of address in dual address cycle
17601
        Address,                // second part of address in dual address cycle
17602
        `BC_IACK,                       // dual address cycle command
17603
        `BC_IACK,               // normal command
17604
        4'h0,               // byte enables
17605
        32'h1234_5678,      // data
17606
        1'b0,               // make address parity error on first phase of dual address
17607
        1'b0,               // make address parity error on second phase of dual address
17608
        ok                  // result of operation
17609
    ) ;
17610
    if ( ok )
17611
        test_ok ;
17612
    else
17613
    begin
17614
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17615
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17616
    end
17617
 
17618
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17619
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17620
    ipci_unsupported_commands_master.master_reference
17621
    (
17622
        Address,                // first part of address in dual address cycle
17623
        Address,                // second part of address in dual address cycle
17624
        `BC_SPECIAL,            // dual address cycle command
17625
        `BC_SPECIAL,            // normal command
17626
        4'h0,               // byte enables
17627
        32'h1234_5678,      // data
17628
        1'b0,               // make address parity error on first phase of dual address
17629
        1'b0,               // make address parity error on second phase of dual address
17630
        ok                  // result of operation
17631
    ) ;
17632
    if ( ok )
17633
        test_ok ;
17634
    else
17635
    begin
17636
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17637
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17638
    end
17639
 
17640
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17641
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17642
    ipci_unsupported_commands_master.master_reference
17643
    (
17644
        Address,                // first part of address in dual address cycle
17645
        Address,                // second part of address in dual address cycle
17646
        `BC_RESERVED0,          // dual address cycle command
17647
        `BC_RESERVED0,      // normal command
17648
        4'h0,               // byte enables
17649
        32'h1234_5678,      // data
17650
        1'b0,               // make address parity error on first phase of dual address
17651
        1'b0,               // make address parity error on second phase of dual address
17652
        ok                  // result of operation
17653
    ) ;
17654
    if ( ok )
17655
        test_ok ;
17656
    else
17657
    begin
17658
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17659
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17660
    end
17661
 
17662
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17663
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17664
    ipci_unsupported_commands_master.master_reference
17665
    (
17666
        Address,                // first part of address in dual address cycle
17667
        Address,                // second part of address in dual address cycle
17668
        `BC_RESERVED1,          // dual address cycle command
17669
        `BC_RESERVED1,      // normal command
17670
        4'h0,               // byte enables
17671
        32'h1234_5678,      // data
17672
        1'b0,               // make address parity error on first phase of dual address
17673
        1'b0,               // make address parity error on second phase of dual address
17674
        ok                  // result of operation
17675
    ) ;
17676
    if ( ok )
17677
        test_ok ;
17678
    else
17679
    begin
17680
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17681
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17682
    end
17683
 
17684
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17685
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17686
    ipci_unsupported_commands_master.master_reference
17687
    (
17688
        Address,                // first part of address in dual address cycle
17689
        Address,                // second part of address in dual address cycle
17690
        `BC_RESERVED2,          // dual address cycle command
17691
        `BC_RESERVED2,      // normal command
17692
        4'h0,               // byte enables
17693
        32'h1234_5678,      // data
17694
        1'b0,               // make address parity error on first phase of dual address
17695
        1'b0,               // make address parity error on second phase of dual address
17696
        ok                  // result of operation
17697
    ) ;
17698
    if ( ok )
17699
        test_ok ;
17700
    else
17701
    begin
17702
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17703
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17704
    end
17705
 
17706
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17707
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17708
    ipci_unsupported_commands_master.master_reference
17709
    (
17710
        Address,                // first part of address in dual address cycle
17711
        Address,                // second part of address in dual address cycle
17712
        `BC_RESERVED3,          // dual address cycle command
17713
        `BC_RESERVED3,      // normal command
17714
        4'h0,               // byte enables
17715
        32'h1234_5678,      // data
17716
        1'b0,               // make address parity error on first phase of dual address
17717
        1'b0,               // make address parity error on second phase of dual address
17718
        ok                  // result of operation
17719
    ) ;
17720
    if ( ok )
17721
        test_ok ;
17722
    else
17723
    begin
17724
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17725
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17726
    end
17727
 
17728
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17729
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17730
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17731
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17732
    ipci_unsupported_commands_master.master_reference
17733
    (
17734
        Address,                // first part of address in dual address cycle
17735
        Address,                // second part of address in dual address cycle
17736
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
17737
        `BC_MEM_WRITE,      // normal command
17738
        4'h0,               // byte enables;
17739
        32'h1234_5678,      // data
17740
        1'b0,               // make address parity error on first phase of dual address
17741
        1'b0,               // make address parity error on second phase of dual address
17742
        ok                  // result of operation
17743
    ) ;
17744
    if ( ok )
17745
        test_ok ;
17746
    else
17747
    begin
17748
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17749
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
17750
    end
17751
 
17752 45 mihad
    // enable pci blue behavioral targets 1 and 2
17753
    configuration_cycle_write
17754
    (
17755
        0,                        // bus number
17756
        `TAR1_IDSEL_INDEX - 11,   // device number
17757
        0,                        // function number
17758
        1,                        // register number
17759
        0,                        // type of configuration cycle
17760
        4'b0001,                  // byte enables
17761
        32'h0000_0047             // data
17762
    ) ;
17763
 
17764
    configuration_cycle_write
17765
    (
17766
        0,                        // bus number
17767
        `TAR2_IDSEL_INDEX - 11,   // device number
17768
        0,                        // function number
17769
        1,                        // register number
17770
        0,                        // type of configuration cycle
17771
        4'b0001,                  // byte enables
17772
        32'h0000_0047             // data
17773
    ) ;
17774 15 mihad
end
17775
endtask // target_unsupported_cmds
17776
 
17777
task target_completion_expiration ;
17778
    reg   [11:0] pci_ctrl_offset ;
17779
    reg   [11:0] pci_ba_offset ;
17780
    reg   [11:0] pci_am_offset ;
17781
    reg   [11:0] pci_device_ctrl_offset ;
17782
    reg   [11:0] pci_err_cs_offset ;
17783
    reg   [11:0] icr_offset ;
17784
    reg   [11:0] isr_offset ;
17785
    reg   [11:0] lat_tim_cls_offset ;
17786
 
17787
    reg [31:0] temp_val1 ;
17788
    reg [31:0] temp_val2 ;
17789
    reg        ok   ;
17790 33 mihad
    reg        ok_wb ;
17791
    reg        ok_pci ;
17792 15 mihad
 
17793
    reg [31:0] pci_image_base ;
17794
    integer i ;
17795 33 mihad
    integer clocks_after_completion ;
17796
    reg     error_monitor_done ;
17797
    reg     test_mem ;
17798 15 mihad
 
17799
begin:main
17800
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17801
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
17802
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
17803
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
17804
 
17805
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
17806
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
17807
    lat_tim_cls_offset = 12'hC ;
17808
    pci_device_ctrl_offset    = 12'h4 ;
17809
 
17810 33 mihad
    `ifdef HOST
17811
        test_mem = 1'b1 ;
17812
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
17813
    `else
17814
        test_mem = !`PCI_BA1_MEM_IO ;
17815
        pci_image_base = Target_Base_Addr_R[1] ;
17816
    `endif
17817 15 mihad
 
17818
    // enable master & target operation
17819
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
17820
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
17821
    if ( ok !== 1 )
17822
    begin
17823
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
17824
        test_fail("write to PCI Device Control register failed") ;
17825
        disable main ;
17826
    end
17827
 
17828
    // prepare image control register
17829 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
17830 15 mihad
    if ( ok !== 1 )
17831
    begin
17832
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
17833
        test_fail("write to PCI Image Control register failed") ;
17834
        disable main ;
17835
    end
17836
 
17837
    // prepare base address register
17838
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
17839
    if ( ok !== 1 )
17840
    begin
17841
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
17842
        test_fail("write to PCI Base Address register failed") ;
17843
        disable main ;
17844
    end
17845
 
17846
    // write address mask register
17847
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
17848
    if ( ok !== 1 )
17849
    begin
17850
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
17851
        test_fail("write to PCI Address Mask register failed") ;
17852
        disable main ;
17853
    end
17854
 
17855
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
17856
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
17857
    if ( ok !== 1 )
17858
    begin
17859
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
17860
        test_fail("write to PCI Error Control and Status register failed") ;
17861
        disable main ;
17862
    end
17863
 
17864 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
17865 15 mihad
    if ( ok !== 1 )
17866
    begin
17867
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
17868
        test_fail("write to Interrupt Control register failed") ;
17869
        disable main ;
17870
    end
17871
 
17872
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
17873
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
17874
    if ( ok !== 1 )
17875
    begin
17876
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
17877
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
17878
        disable main ;
17879
    end
17880
 
17881
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
17882
 
17883
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17884 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
17885
    master1_check_received_data = 0 ;
17886 15 mihad
 
17887 33 mihad
    ok_pci = 1 ;
17888
    // start a delayed read request
17889
    fork
17890
    begin
17891
        if ( test_mem )
17892
 
17893
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
17894
                          pci_image_base, 32'h1234_5678,
17895
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
17896
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
17897
        else
17898
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
17899
 
17900
        do_pause( 1 ) ;
17901
    end
17902
    begin:error_monitor1
17903 35 mihad
        error_monitor_done = 0 ;
17904 33 mihad
        @(error_event_int) ;
17905
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
17906
        ok_pci = 0 ;
17907 35 mihad
        error_monitor_done = 1 ;
17908 33 mihad
    end
17909
    begin
17910
        if ( test_mem )
17911
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
17912
        else
17913
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
17914 15 mihad
 
17915 33 mihad
        if ( ok_wb !== 1 )
17916
        begin
17917
            test_fail("Bridge failed to process Target Memory read correctly") ;
17918
            disable main ;
17919
        end
17920
 
17921 35 mihad
        #1 ;
17922
        if ( !error_monitor_done )
17923 33 mihad
            disable error_monitor1 ;
17924
    end
17925
    join
17926
 
17927
    clocks_after_completion = 0 ;
17928
    // now do another - different transaction
17929
    fork
17930
    begin
17931
        if ( test_mem )
17932
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
17933
                          pci_image_base + 4, 32'h1234_5678,
17934
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
17935
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
17936
        else
17937
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
17938
 
17939
        while ( clocks_after_completion < 32'h0000_FFF0 )
17940
        begin
17941
            @(posedge pci_clock) ;
17942
            clocks_after_completion = clocks_after_completion + 1 ;
17943
        end
17944
 
17945
        do_pause('hFF) ;
17946
 
17947
        if ( test_mem )
17948
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
17949
                          pci_image_base + 4, 32'h1234_5678,
17950
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
17951
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
17952
        else
17953
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
17954
 
17955
        do_pause( 1 ) ;
17956
    end
17957
    begin:error_monitor2
17958 35 mihad
        error_monitor_done = 0 ;
17959 33 mihad
        @(error_event_int) ;
17960
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
17961
        ok_pci = 0 ;
17962 35 mihad
        error_monitor_done = 1 ;
17963 33 mihad
    end
17964
    begin
17965
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
17966
        repeat( 'hFF )
17967
            @(posedge pci_clock) ;
17968
 
17969
        if ( test_mem )
17970
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
17971
        else
17972
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
17973
 
17974
        if ( ok_wb !== 1 )
17975
        begin
17976
            test_fail("Bridge failed to process Target Memory read correctly") ;
17977
            disable main ;
17978
        end
17979
 
17980
        repeat(4)
17981
            @(posedge pci_clock) ;
17982
 
17983
        fork
17984
        begin
17985
            if ( test_mem )
17986
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
17987
                              pci_image_base + 4, 32'h1234_5678,
17988
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
17989
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
17990
            else
17991
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
17992
 
17993
            do_pause(1) ;
17994
        end
17995
        begin
17996
           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 ) ;
17997 35 mihad
           #1 ;
17998
           if ( !error_monitor_done )
17999 33 mihad
               disable error_monitor2 ;
18000
        end
18001
        join
18002
    end
18003
    join
18004
 
18005
    if ( ok && ok_pci && ok_wb )
18006
        test_ok ;
18007
 
18008
    if ( ok !== 1 )
18009
    begin
18010
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18011
        test_fail("write to PCI Address Mask register failed") ;
18012
        disable main ;
18013
    end
18014
 
18015
    // check statuses after this situation - none should be set
18016
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18017
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18018
    if ( ok !== 1 )
18019
    begin
18020
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18021
        test_fail("read from pci device status register failed") ;
18022
        disable main ;
18023
    end
18024
 
18025
    if ( temp_val1[31] )
18026
    begin
18027
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18028
        test_fail("detected parity error bit was set for no reason") ;
18029
    end
18030
 
18031
    if ( temp_val1[30] )
18032
    begin
18033
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18034
        test_fail("signaled system error bit was set for no reason") ;
18035
    end
18036
 
18037
    if ( temp_val1[29] )
18038
    begin
18039
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18040
        test_fail("received master abort bit was set for no reason") ;
18041
    end
18042
 
18043
    if ( temp_val1[28] )
18044
    begin
18045
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18046
        test_fail("received target abort bit was set for no reason") ;
18047
    end
18048
 
18049
    if ( temp_val1[27] )
18050
    begin
18051
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18052
        test_fail("signaled target abort bit was set for no reason") ;
18053
    end
18054
 
18055
    if ( temp_val1[24] )
18056
    begin
18057
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18058
        test_fail("Master Data parity error bit was set for no reason") ;
18059
    end
18060
 
18061
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18062
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18063
    if ( temp_val1[8] !== 0 )
18064
    begin
18065
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18066
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18067
    end
18068
    // test target retry counter expiration
18069
    // set wb slave to retry response
18070
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18071
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18072
    ok_pci = 1 ;
18073
 
18074
    fork
18075
    begin
18076
        if ( test_mem == 1 )
18077
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18078
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18079
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18080
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18081
        else
18082
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18083
 
18084
        do_pause(1) ;
18085
 
18086
        // do another write with same address and different data
18087
        if ( test_mem == 1 )
18088
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18089
                        pci_image_base, 32'h8765_4321, 4'h0,
18090
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18091
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18092
        else
18093
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18094
 
18095
        do_pause(1) ;
18096
    end
18097
    begin
18098
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18099
        begin
18100
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18101
            if ( ok_wb !== 1 )
18102
            begin
18103
                $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) ;
18104
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18105
                disable main ;
18106
            end
18107
        end
18108
 
18109
        // set WB slave to normal completion
18110
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18111
 
18112
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18113
        if ( ok_wb !== 1 )
18114
        begin
18115
            $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) ;
18116
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18117
            disable main ;
18118
        end
18119
 
18120 35 mihad
        #1 ;
18121
        if ( !error_monitor_done )
18122 33 mihad
            disable error_monitor3 ;
18123
    end
18124
    begin:error_monitor3
18125 35 mihad
        error_monitor_done = 0 ;
18126 33 mihad
        @(error_event_int) ;
18127
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18128
        ok_pci = 0 ;
18129 35 mihad
        error_monitor_done = 1 ;
18130 33 mihad
    end
18131
    join
18132
 
18133
    if ( ok_wb && ok_pci )
18134
    begin
18135
        test_ok ;
18136
    end
18137
 
18138
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18139
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18140
    if ( temp_val1[8] !== 1'b1 )
18141
    begin
18142
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18143
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18144
    end
18145
 
18146
    if ( temp_val1[9] !== 1 )
18147
    begin
18148
        $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) ;
18149
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18150
    end
18151
 
18152
    if ( temp_val1[10] !== 1 )
18153
    begin
18154
        $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) ;
18155
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18156
    end
18157
 
18158
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18159
    begin
18160
        $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) ;
18161
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18162
    end
18163
 
18164
    if ( temp_val1[31:28] !== 4'hA )
18165
    begin
18166
        $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) ;
18167
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18168
    end
18169
 
18170
    // clear error status register
18171
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18172
 
18173
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18174
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18175
    if ( temp_val1 !== pci_image_base )
18176
    begin
18177
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18178
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18179
    end
18180
 
18181
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18182
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18183
    if ( temp_val1 !== 32'hDEAD_BEAF )
18184
    begin
18185
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18186
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18187
    end
18188
 
18189
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18190
    ok_pci = 1 ;
18191
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18192
 
18193
    i = 0 ;
18194
    fork
18195
    begin
18196
        if ( test_mem )
18197
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18198
                          pci_image_base + 4, 32'h1234_5678,
18199
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18200
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18201
        else
18202
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18203
 
18204
        do_pause( 1 ) ;
18205
 
18206
    end
18207
    begin
18208
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18209
        begin
18210
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18211
            if ( ok_wb !== 1 )
18212
            begin
18213
                $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) ;
18214
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18215
                disable main ;
18216
            end
18217
        end
18218
 
18219
        // set WB slave to normal completion
18220
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18221
 
18222
        fork
18223
        begin
18224
            repeat(4)
18225
                @(posedge pci_clock) ;
18226
 
18227
            if ( test_mem )
18228
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18229
                              pci_image_base, 32'h8765_4321,
18230
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18231
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18232
            else
18233
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18234
 
18235
            do_pause(1) ;
18236
        end
18237
        begin
18238
 
18239
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18240
            if ( ok_wb !== 1 )
18241
            begin
18242
                $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) ;
18243
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18244
                disable main ;
18245
            end
18246
        end
18247
        join
18248
 
18249
        repeat( 4 )
18250
            @(posedge pci_clock) ;
18251
 
18252
        if ( test_mem )
18253
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18254
                          pci_image_base, 32'h8765_4321,
18255
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18256
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18257
        else
18258
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18259
 
18260
        do_pause(1) ;
18261
 
18262 35 mihad
        #1 ;
18263
        if ( !error_monitor_done )
18264 33 mihad
            disable error_monitor4 ;
18265
    end
18266
    begin:error_monitor4
18267 35 mihad
        error_monitor_done = 0 ;
18268 33 mihad
        @(error_event_int) ;
18269
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18270
        ok_pci = 0 ;
18271 35 mihad
        error_monitor_done = 1 ;
18272 33 mihad
    end
18273
    join
18274
 
18275
    if ( ok_wb && ok_pci )
18276
        test_ok ;
18277
 
18278
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18279
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18280
    if ( temp_val1[8] !== 1'b0 )
18281
    begin
18282
        $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) ;
18283
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18284
    end
18285
 
18286
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18287 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18288
    $fdisplay(pciu_mon_log_file_desc,
18289
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18290 33 mihad
    ok_pci = 1 ;
18291
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18292
 
18293
    fork
18294
    begin
18295
        if ( test_mem )
18296
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18297
                          pci_image_base + 4, 32'h1234_5678,
18298
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18299
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18300
        else
18301
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18302
 
18303
        do_pause( 1 ) ;
18304
 
18305
    end
18306
    begin
18307
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18308
        if ( ok_wb !== 1 )
18309
        begin
18310
            $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) ;
18311
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18312
            disable main ;
18313
        end
18314
 
18315
        repeat(4)
18316
            @(posedge pci_clock) ;
18317
 
18318
        fork
18319
        begin
18320
 
18321
            if ( test_mem )
18322
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18323
                              pci_image_base + 4, 32'h8765_4321,
18324
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18325
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18326
            else
18327
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18328
 
18329
            do_pause(1) ;
18330
 
18331
        end
18332
        begin
18333
 
18334
            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 ) ;
18335
            if ( ok !== 1 )
18336
            begin
18337
                $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) ;
18338
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18339
                disable main ;
18340
            end
18341
        end
18342
        join
18343
 
18344 35 mihad
        #1 ;
18345
        if ( !error_monitor_done )
18346 33 mihad
            disable error_monitor5 ;
18347
    end
18348
    begin:error_monitor5
18349 35 mihad
        error_monitor_done = 0 ;
18350 33 mihad
        @(error_event_int) ;
18351
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18352
        ok_pci = 0 ;
18353 35 mihad
        error_monitor_done = 1 ;
18354 33 mihad
    end
18355
    join
18356
 
18357
    if ( ok_wb && ok_pci )
18358
        test_ok ;
18359
 
18360
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18361
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18362
    if ( temp_val1[8] !== 1'b0 )
18363
    begin
18364
        $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) ;
18365
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18366
    end
18367
 
18368
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18369
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18370
    if ( temp_val1[25] !== 1'b1 )
18371
    begin
18372
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18373
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18374
    end
18375
 
18376
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18377
 
18378
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18379
    ok_pci = 1 ;
18380
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18381
 
18382
    fork
18383
    begin
18384
        if ( test_mem == 1 )
18385
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18386
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18387
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18388
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18389
        else
18390
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18391
 
18392
        do_pause(1) ;
18393
 
18394
        // do another write with same address and different data
18395
        if ( test_mem == 1 )
18396
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18397
                        pci_image_base, 32'h8765_6789, 4'h0,
18398
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18399
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18400
        else
18401
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18402
 
18403
        do_pause(1) ;
18404
    end
18405
    begin
18406
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18407
        if ( ok_wb !== 1 )
18408
        begin
18409
            $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) ;
18410
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18411
            disable main ;
18412
        end
18413
 
18414
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18415
 
18416
        if ( test_mem )
18417
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18418
        else
18419
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18420
 
18421
        if ( ok_wb !== 1 )
18422
        begin
18423
            $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) ;
18424
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18425
            disable main ;
18426
        end
18427
 
18428 35 mihad
        #1 ;
18429
        if ( !error_monitor_done )
18430 33 mihad
            disable error_monitor6 ;
18431
    end
18432
    begin:error_monitor6
18433 35 mihad
        error_monitor_done = 0 ;
18434 33 mihad
        @(error_event_int) ;
18435
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18436
        ok_pci = 0 ;
18437 35 mihad
        error_monitor_done = 1 ;
18438 33 mihad
    end
18439
    join
18440
 
18441
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18442
    $fdisplay(pciu_mon_log_file_desc,
18443
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18444
 
18445
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18446
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18447
    if ( temp_val1[8] !== 1'b1 )
18448
    begin
18449
        $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) ;
18450
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18451
    end
18452
 
18453
    if ( temp_val1[9] !== 0 )
18454
    begin
18455
        $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) ;
18456
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18457
    end
18458
 
18459
    if ( temp_val1[10] !== 1 )
18460
    begin
18461
        $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) ;
18462
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18463
    end
18464
 
18465
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18466
    begin
18467
        $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) ;
18468
        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") ;
18469
    end
18470
 
18471
    if ( temp_val1[31:28] !== 4'h0 )
18472
    begin
18473
        $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) ;
18474
        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") ;
18475
    end
18476
 
18477
    // clear error status register
18478
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18479
 
18480
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18481
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18482
    if ( temp_val1 !== pci_image_base )
18483
    begin
18484
        $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) ;
18485
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18486
    end
18487
 
18488
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18489
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18490
    if ( temp_val1 !== 32'hBEAF_DEAD )
18491
    begin
18492
        $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) ;
18493
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18494
    end
18495
 
18496
    // disable current image - write address mask register
18497 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18498 15 mihad
end
18499
endtask // target_completion_expired
18500
 
18501
task config_write ;
18502
    input [11:0] offset ;
18503
    input [31:0] data ;
18504
    input [3:0]  byte_enable ;
18505
    output       ok ;
18506
    `ifdef HOST
18507
    reg   `WRITE_STIM_TYPE   write_data ;
18508
    reg   `WB_TRANSFER_FLAGS write_flags ;
18509
    reg   `WRITE_RETURN_TYPE write_status ;
18510
    `else
18511
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18512
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18513
    `endif
18514
    reg in_use ;
18515
    reg [31:0] temp_var ;
18516
begin
18517
    if ( in_use === 1 )
18518
    begin
18519
        $display("config_read task re-entered! Time %t ", $time) ;
18520
        ok = 0 ;
18521
        #20 $stop ;
18522
    end
18523
    else
18524
    begin
18525
        ok = 1 ;
18526
        in_use = 1 ;
18527
    end
18528
    `ifdef HOST
18529
    write_flags                    = 0 ;
18530
    write_flags`INIT_WAITS         = tb_init_waits ;
18531
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18532
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18533
 
18534
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18535
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18536
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18537
    write_data`WRITE_SEL                         = byte_enable ;
18538
    write_data`WRITE_TAG_STIM                    = 0 ;
18539
    write_data`WRITE_DATA                        = data ;
18540
 
18541
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18542
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18543
    begin
18544
        $display("Write to configuration space failed! Time %t ", $time) ;
18545
        ok = 0 ;
18546
    end
18547
 
18548
    @(posedge wb_clock) ;
18549
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18550
    // here we just wait for two guest cycles for conf space bits to synchronize
18551
    repeat( 2 )
18552
        @(posedge pci_clock) ;
18553
 
18554
    `else // GUEST
18555
    byte_enables_l = ~byte_enable ;
18556
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18557
 
18558
    fork
18559
    begin
18560
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18561
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
18562
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
18563
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18564
              8'h0_0, `Test_One_Zero_Target_WS,
18565
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
18566
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18567
    do_pause( 1 ) ;
18568
    end
18569
    begin
18570
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
18571
        @(posedge pci_clock) ;
18572
    end
18573
    join
18574
 
18575
     repeat( 2 )
18576
         @(posedge wb_clock) ;
18577
 
18578
    `endif
18579
    in_use = 0 ;
18580
end
18581
endtask // config_write
18582
 
18583
task config_read ;
18584
    input [11:0] offset ;
18585
    input [3:0]  byte_enable ;
18586
    output [31:0] data ;
18587
 
18588
    reg `READ_STIM_TYPE    read_data ;
18589
    reg `WB_TRANSFER_FLAGS read_flags ;
18590
    reg `READ_RETURN_TYPE  read_status ;
18591
 
18592
    reg [31:0] pci_address ;
18593
    reg [3:0] byte_enables_l ;
18594
 
18595
    reg master_check_data_prev ;
18596
    reg in_use ;
18597
    reg [31:0] temp_var ;
18598
begin:main
18599
    if ( in_use === 1 )
18600
    begin
18601
        $display("config_read task re-entered! Time %t ", $time) ;
18602
        data = 32'hxxxx_xxxx ;
18603
        disable main ;
18604
    end
18605
 
18606
    in_use = 1 ;
18607
 
18608
`ifdef HOST
18609 26 mihad
    repeat(4)
18610
        @(posedge pci_clock) ;
18611
    repeat(4)
18612
        @(posedge wb_clock) ;
18613 15 mihad
    read_flags                    = 0 ;
18614
    read_flags`INIT_WAITS         = tb_init_waits ;
18615
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18616
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18617
 
18618
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18619
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18620
 
18621
    read_data`READ_ADDRESS  = temp_var + offset ;
18622
    read_data`READ_SEL      = byte_enable ;
18623
    read_data`READ_TAG_STIM = 0 ;
18624
 
18625
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
18626
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18627
    begin
18628
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
18629
        #20 $stop ;
18630
    end
18631
    data = read_status`READ_DATA ;
18632
`else
18633
  `ifdef GUEST
18634 26 mihad
    repeat(4)
18635
        @(posedge wb_clock) ;
18636
    repeat(4)
18637
        @(posedge pci_clock) ;
18638 15 mihad
    master_check_data_prev = master2_check_received_data ;
18639
    master2_check_received_data = 0 ;
18640
 
18641
    byte_enables_l = ~byte_enable ;
18642
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18643
 
18644
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18645
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
18646
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
18647
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18648
             8'h4_0, `Test_One_Zero_Target_WS,
18649
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
18650
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18651
    do_pause( 1 ) ;
18652
 
18653
    @(master2_received_data_valid) ;
18654
    data = master2_received_data ;
18655
 
18656
    master2_check_received_data = master_check_data_prev ;
18657
  `endif
18658
`endif
18659
    in_use = 0 ;
18660
end
18661
endtask //config_read
18662
 
18663
task test_fail ;
18664
    input [7999:0] failure_reason ;
18665
    reg   [8007:0] display_failure ;
18666
    reg   [799:0] display_test ;
18667
begin
18668
    tests_failed = tests_failed + 1 ;
18669
 
18670
    display_failure = {failure_reason, "!"} ;
18671
    while ( display_failure[7999:7992] == 0 )
18672
        display_failure = display_failure << 8 ;
18673
 
18674
    display_test = test_name ;
18675
    while ( display_test[799:792] == 0 )
18676
       display_test = display_test << 8 ;
18677
 
18678
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18679
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
18680
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
18681
    $fdisplay( tb_log_file, " *FAILED* because") ;
18682
    $fdisplay( tb_log_file, " %s", display_failure ) ;
18683
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18684
    $fdisplay( tb_log_file, " " ) ;
18685
 
18686
    `ifdef STOP_ON_FAILURE
18687
    #20 $stop ;
18688
    `endif
18689
end
18690
endtask // test_fail
18691
 
18692
task test_ok ;
18693
    reg [799:0] display_test ;
18694
begin
18695
   tests_successfull = tests_successfull + 1 ;
18696
 
18697
   display_test = test_name ;
18698
   while ( display_test[799:792] == 0 )
18699
       display_test = display_test << 8 ;
18700
 
18701
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18702
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
18703
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
18704
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
18705
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18706
   $fdisplay( tb_log_file, " " ) ;
18707
end
18708
endtask // test_ok
18709
 
18710
task test_summary;
18711
begin
18712
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
18713
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
18714
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
18715
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
18716
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
18717
    $fclose(tb_log_file) ;
18718
end
18719
endtask
18720
 
18721
endmodule

powered by: WebSVN 2.1.0

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