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

Subversion Repositories pci

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

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 51 mihad
`ifdef HOST
7
    `ifdef NO_CNF_IMAGE
8
    `else
9
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
10
    `endif
11
`else
12
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
13
`endif
14
 
15 15 mihad
module SYSTEM ;
16
 
17
`include "pci_blue_constants.vh"
18
`include "pci_blue_options.vh"
19
 
20
integer tests_successfull ;
21
integer tests_failed ;
22
integer tb_log_file ;
23
reg [799:0] test_name ;
24
 
25
reg pci_clock ;
26
reg wb_clock ;
27
reg reset ;
28
 
29
wire [4:0] arb_grant_out ;
30
 
31
wire [31:0] AD ;
32
wire [3:0]  CBE ;
33
pullup(INTA) ;
34
pullup(MAS0_REQ) ;
35
pullup(MAS1_REQ) ;
36
pullup(MAS2_REQ) ;
37
pullup(MAS3_REQ) ;
38
 
39
wire MAS0_GNT = ~arb_grant_out[0];
40
wire MAS1_GNT = ~arb_grant_out[1] ;
41
wire MAS2_GNT = ~arb_grant_out[2] ;
42
wire MAS3_GNT = ~arb_grant_out[3] ;
43
 
44
pullup(FRAME) ;
45
pullup(IRDY) ;
46 45 mihad
 
47
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
48
 
49 15 mihad
pullup(DEVSEL) ;
50
pullup(TRDY) ;
51
pullup(STOP) ;
52
wire   PAR ;
53
pullup(PERR) ;
54
pullup(SERR) ;
55
wire [3:0] MAS1_IDSEL ;
56
 
57
pullup lockpu ( LOCK ) ;
58
 
59
wire        RST_O ;
60
wire        INT_O ;
61
reg         INT_I ;
62
wire [31:0] ADR_I ;
63
wire [31:0] SDAT_I ;
64
wire [31:0] SDAT_O ;
65
wire [3:0]  SEL_I ;
66
wire        CYC_I ;
67
wire        STB_I ;
68
wire        WE_I ;
69
wire        CAB_I ;
70
wire        ACK_O ;
71
wire        RTY_O ;
72
wire        ERR_O ;
73
 
74
wire [31:0] ADR_O ;
75
wire [31:0] MDAT_I ;
76
wire [31:0] MDAT_O ;
77
wire [3:0]  SEL_O ;
78
wire        CYC_O ;
79
wire        STB_O ;
80
wire        WE_O ;
81
wire        CAB_O ;
82
wire        ACK_I ;
83
wire        RTY_I ;
84
wire        ERR_I ;
85
 
86 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
87
 
88
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
89
 
90 15 mihad
wire        reset_wb ; // reset to Wb devices
91
 
92
`ifdef GUEST
93
    wire    RST = ~reset ;
94
    assign  reset_wb = RST_O ;
95
`else
96
    pullup(RST) ;
97
    assign  reset_wb = reset ;
98
`endif
99
 
100
`define PCI_BRIDGE_INSTANCE bridge32_top
101
 
102
TOP `PCI_BRIDGE_INSTANCE
103
(
104
    .CLK    ( pci_clock),
105
    .AD     ( AD ),
106
    .CBE    ( CBE ),
107
    .RST    ( RST ),
108
    .INTA   ( INTA ),
109
    .REQ    ( MAS0_REQ ),
110
    .GNT    ( MAS0_GNT ),
111
    .FRAME  ( FRAME ),
112
    .IRDY   ( IRDY ),
113
    .IDSEL  ( TAR0_IDSEL),
114
    .DEVSEL ( DEVSEL ),
115
    .TRDY   ( TRDY ),
116
    .STOP   ( STOP ),
117
    .PAR    ( PAR ),
118
    .PERR   ( PERR ),
119
    .SERR   ( SERR ),
120
 
121
    .CLK_I  ( wb_clock ),
122
    .RST_I  ( reset ),
123
    .RST_O  ( RST_O ),
124
    .INT_I  ( INT_I ),
125
    .INT_O  ( INT_O ),
126
 
127
    // WISHBONE slave interface
128
    .ADR_I  ( ADR_I ),
129
    .SDAT_I ( SDAT_I ),
130
    .SDAT_O ( SDAT_O ),
131
    .SEL_I  ( SEL_I ),
132
    .CYC_I  ( CYC_I ),
133
    .STB_I  ( STB_I ),
134
    .WE_I   ( WE_I ),
135
    .CAB_I  ( CAB_I),
136
    .ACK_O  ( ACK_O ),
137
    .RTY_O  ( RTY_O ),
138
    .ERR_O  ( ERR_O ),
139
 
140
    // WISHBONE master interface
141
    .ADR_O  ( ADR_O ),
142
    .MDAT_I ( MDAT_I ),
143
    .MDAT_O ( MDAT_O ),
144
    .SEL_O  ( SEL_O ),
145
    .CYC_O  ( CYC_O ),
146
    .STB_O  ( STB_O ),
147
    .WE_O   ( WE_O ),
148
    .CAB_O  ( CAB_O ),
149
    .ACK_I  ( ACK_I ),
150
    .RTY_I  ( RTY_I ),
151
    .ERR_I  ( ERR_I )
152
) ;
153
 
154
WB_MASTER_BEHAVIORAL wishbone_master
155
(
156
    .CLK_I(wb_clock),
157
    .RST_I(reset_wb),
158
    .TAG_I(4'b0000),
159
    .TAG_O(),
160
    .ACK_I(ACK_O),
161
    .ADR_O(ADR_I),
162
    .CYC_O(CYC_I),
163
    .DAT_I(SDAT_O),
164
    .DAT_O(SDAT_I),
165
    .ERR_I(ERR_O),
166
    .RTY_I(RTY_O),
167
    .SEL_O(SEL_I),
168
    .STB_O(STB_I),
169
    .WE_O (WE_I),
170
    .CAB_O(CAB_I)
171
);
172
 
173
WB_SLAVE_BEHAVIORAL wishbone_slave
174
(
175
    .CLK_I              (wb_clock),
176
    .RST_I              (reset_wb),
177
    .ACK_O              (ACK_I),
178
    .ADR_I              (ADR_O),
179
    .CYC_I              (CYC_O),
180
    .DAT_O              (MDAT_I),
181
    .DAT_I              (MDAT_O),
182
    .ERR_O              (ERR_I),
183
    .RTY_O              (RTY_I),
184
    .SEL_I              (SEL_O),
185
    .STB_I              (STB_O),
186
    .WE_I               (WE_O),
187
    .CAB_I              (CAB_O)
188
);
189
 
190
integer wbu_mon_log_file_desc ;
191
integer pciu_mon_log_file_desc ;
192
WB_BUS_MON wbu_wb_mon(
193
                    .CLK_I(wb_clock),
194
                    .RST_I(reset_wb),
195
                    .ACK_I(ACK_O),
196
                    .ADDR_O(ADR_I),
197
                    .CYC_O(CYC_I),
198
                    .DAT_I(SDAT_O),
199
                    .DAT_O(SDAT_I),
200
                    .ERR_I(ERR_O),
201
                    .RTY_I(RTY_O),
202
                    .SEL_O(SEL_I),
203
                    .STB_O(STB_I),
204
                    .WE_O (WE_I),
205
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
206
                    .TAG_O(),
207
                    .CAB_O(CAB_I),
208
                    .log_file_desc ( wbu_mon_log_file_desc )
209
                  ) ;
210
 
211
WB_BUS_MON pciu_wb_mon(
212
                    .CLK_I(wb_clock),
213
                    .RST_I(reset_wb),
214
                    .ACK_I(ACK_I),
215
                    .ADDR_O(ADR_O),
216
                    .CYC_O(CYC_O),
217
                    .DAT_I(MDAT_I),
218
                    .DAT_O(MDAT_O),
219
                    .ERR_I(ERR_I),
220
                    .RTY_I(RTY_I),
221
                    .SEL_O(SEL_O),
222
                    .STB_O(STB_O),
223
                    .WE_O (WE_O),
224
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
225
                    .TAG_O(),
226
                    .CAB_O(CAB_O),
227
                    .log_file_desc( pciu_mon_log_file_desc )
228
                  ) ;
229
 
230
// some aditional signals are needed here because of the arbiter
231
reg [3:0] pci_ext_req_prev ;
232
always@(posedge pci_clock)
233
begin
234
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
235
end
236
reg pci_frame_prev ;
237
always@(posedge pci_clock)
238
begin
239
    pci_frame_prev <= FRAME ;
240
end
241
reg pci_irdy_prev ;
242
always@(posedge pci_clock)
243
begin
244
    pci_irdy_prev <= IRDY ;
245
end
246
 
247
pci_blue_arbiter pci_arbiter
248
(
249
  .pci_int_req_direct(1'b0),
250
  .pci_ext_req_prev(pci_ext_req_prev),
251
  .pci_int_gnt_direct_out(arb_grant_out[4]),
252
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
253
  .pci_frame_prev(~pci_frame_prev),
254
  .pci_irdy_prev(~pci_irdy_prev),
255
  .pci_irdy_now(~IRDY),
256
  .arbitration_enable(1'b1),
257
  .pci_clk(pci_clock),
258
  .pci_reset_comb(~RST)
259
);
260
 
261
reg [31:0] target_message ;
262
 
263
// define output enable signals for monitor inputs
264
// real output enable signals
265
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
266
`ifdef ACTIVE_LOW_OE
267
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
268
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
269
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
270
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
271
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
272
                        !devsel_t_s_oe,
273
                        !ad_oe,
274
                        !cbe_oe,
275
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
276
                        ;
277
`else
278
`ifdef ACTIVE_HIGH_OE
279
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
280
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
281
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
282
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
283
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
284
                        devsel_t_s_oe,
285
                        ad_oe,
286
                        cbe_oe,
287
                        `PCI_BRIDGE_INSTANCE.PERR_en}
288
                        ;
289
`endif
290
`endif
291
/*wire [5:0] oe_sigs_0 = {1'b0,
292
                        1'b0,
293
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
294
                        pci_target32.ad_enable,
295
                        1'b0,
296
                        pci_target32.err_enable | pci_target32.r_err_enable
297
                       } ;
298
*/
299
 
300
wire [5:0] oe_sigs_2 ;
301
wire [5:0] oe_sigs_1 ;
302
 
303
// signals which are used by test modules to know what to do
304
triand  test_accepted_l_int, error_event_int;
305
pullup  (test_accepted_l_int), (error_event_int);
306
 
307
wire    pci_reset_comb  = ~RST;
308
wire    pci_ext_clk     = pci_clock;
309
 
310
integer pci_mon_log_file_desc ;
311
pci_bus_monitor monitor32
312
(
313
    .pci_ext_ad                 (AD),
314
    .pci_ext_cbe_l              (CBE),
315
    .pci_ext_par                (PAR),
316
    .pci_ext_frame_l            (FRAME),
317
    .pci_ext_irdy_l             (IRDY),
318
    .pci_ext_devsel_l           (DEVSEL),
319
    .pci_ext_trdy_l             (TRDY),
320
    .pci_ext_stop_l             (STOP),
321
    .pci_ext_perr_l             (PERR),
322
    .pci_ext_serr_l             (SERR),
323
    .pci_real_req_l             (MAS0_REQ),
324
    .pci_real_gnt_l             (MAS0_GNT),
325
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
326
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
327
    .test_error_event           (error_event_int),
328
    .test_observe_r_oe_sigs     (r_oe_sigs),
329
    .test_observe_0_oe_sigs     (6'h00),
330
    .test_observe_1_oe_sigs     (oe_sigs_1),
331
    .test_observe_2_oe_sigs     (oe_sigs_2),
332
    .test_observe_3_oe_sigs     (6'h00),
333
    .pci_ext_reset_l            (RST),
334
    .pci_ext_clk                (pci_clock),
335
    .log_file_desc              (pci_mon_log_file_desc)
336
) ;
337
 
338
reg [2:0]  test_master_number ;
339
reg [31:0] test_address ;
340
reg [3:0]  test_command ;
341
reg [31:0] test_data ;
342
reg [3:0]  test_byte_enables_l ;
343
reg [9:0]  test_size ;
344
reg        test_make_addr_par_error ;
345
reg        test_make_data_par_error ;
346
reg [3:0]  test_master_initial_wait_states ;
347
reg [3:0]  test_master_subsequent_wait_states ;
348
reg [3:0]  test_target_initial_wait_states ;
349
reg [3:0]  test_target_subsequent_wait_states ;
350
reg [1:0]  test_target_devsel_speed ;
351
reg        test_fast_back_to_back ;
352
reg [2:0]  test_target_termination ;
353
reg        test_expect_master_abort ;
354
reg        test_start ;
355
reg [25:0] test_target_response ;
356
 
357
wire [31:0] master2_received_data ;
358
wire        master2_received_data_valid ;
359
reg         master2_check_received_data ;
360
pci_behaviorial_device pci_behaviorial_device2
361
(
362
    .pci_ext_ad(AD),
363
    .pci_ext_cbe_l(CBE),
364
    .pci_ext_par(PAR),
365
    .pci_ext_frame_l(FRAME),
366
    .pci_ext_irdy_l(IRDY),
367
    .pci_ext_devsel_l(DEVSEL),
368
    .pci_ext_trdy_l(TRDY),
369
    .pci_ext_stop_l(STOP),
370
    .pci_ext_perr_l(PERR),
371
    .pci_ext_serr_l(SERR),
372
    .pci_ext_idsel(TAR2_IDSEL),
373
    .pci_ext_inta_l(INTA),
374
    .pci_ext_req_l(MAS2_REQ),
375
    .pci_ext_gnt_l(MAS2_GNT),
376
    .pci_ext_reset_l(RST),
377
    .pci_ext_clk(pci_clock),
378
 
379
// Signals used by the test bench instead of using "." notation
380
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
381
    .test_master_number                 (test_master_number[2:0]),
382
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
383
    .test_command                       (test_command[3:0]),
384
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
385
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
386
    .test_size                          (test_size),
387
    .test_make_addr_par_error           (test_make_addr_par_error),
388
    .test_make_data_par_error           (test_make_data_par_error),
389
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
390
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
391
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
392
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
393
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
394
    .test_fast_back_to_back             (test_fast_back_to_back),
395
    .test_target_termination            (test_target_termination[2:0]),
396
    .test_expect_master_abort           (test_expect_master_abort),
397
    .test_start                         (test_start),
398
    .test_accepted_l                    (test_accepted_l_int),
399
    .test_error_event                   (error_event_int),
400
    .test_device_id                     (`Test_Master_2),
401
    .test_target_response               (test_target_response),
402
 
403
    .master_received_data               (master2_received_data),
404
    .master_received_data_valid         (master2_received_data_valid),
405
    .master_check_received_data         (master2_check_received_data)
406
);
407
 
408
wire [31:0] master1_received_data ;
409
wire        master1_received_data_valid ;
410
reg         master1_check_received_data ;
411
pci_behaviorial_device pci_behaviorial_device1
412
(
413
    .pci_ext_ad(AD),
414
    .pci_ext_cbe_l(CBE),
415
    .pci_ext_par(PAR),
416
    .pci_ext_frame_l(FRAME),
417
    .pci_ext_irdy_l(IRDY),
418
    .pci_ext_devsel_l(DEVSEL),
419
    .pci_ext_trdy_l(TRDY),
420
    .pci_ext_stop_l(STOP),
421
    .pci_ext_perr_l(PERR),
422
    .pci_ext_serr_l(SERR),
423
    .pci_ext_idsel(TAR1_IDSEL),
424
    .pci_ext_inta_l(INTA),
425
    .pci_ext_req_l(MAS1_REQ),
426
    .pci_ext_gnt_l(MAS1_GNT),
427
    .pci_ext_reset_l(RST),
428
    .pci_ext_clk(pci_clock),
429
 
430
// Signals used by the test bench instead of using "." notation
431
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
432
    .test_master_number                 (test_master_number[2:0]),
433
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
434
    .test_command                       (test_command[3:0]),
435
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
436
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
437
    .test_size                          (test_size),
438
    .test_make_addr_par_error           (test_make_addr_par_error),
439
    .test_make_data_par_error           (test_make_data_par_error),
440
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
441
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
442
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
443
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
444
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
445
    .test_fast_back_to_back             (test_fast_back_to_back),
446
    .test_target_termination            (test_target_termination[2:0]),
447
    .test_expect_master_abort           (test_expect_master_abort),
448
    .test_start                         (test_start),
449
    .test_accepted_l                    (test_accepted_l_int),
450
    .test_error_event                   (error_event_int),
451
    .test_device_id                     (`Test_Master_1),
452
    .test_target_response               (test_target_response),
453
 
454
    .master_received_data               (master1_received_data),
455
    .master_received_data_valid         (master1_received_data_valid),
456
    .master_check_received_data         (master1_check_received_data)
457
);
458
 
459
pci_unsupported_commands_master ipci_unsupported_commands_master
460
(
461
    .CLK    ( pci_clock),
462
    .AD     ( AD ),
463
    .CBE    ( CBE ),
464
    .RST    ( RST ),
465
    .REQ    ( MAS3_REQ ),
466
    .GNT    ( MAS3_GNT ),
467
    .FRAME  ( FRAME ),
468
    .IRDY   ( IRDY ),
469
    .DEVSEL ( DEVSEL ),
470
    .TRDY   ( TRDY ),
471
    .STOP   ( STOP ),
472
    .PAR    ( PAR )
473
) ;
474
 
475 45 mihad
`ifdef HOST
476
 
477
reg     [1:0]   conf_cyc_type1_target_response ;
478
reg     [31:0]  conf_cyc_type1_target_data ;
479
reg     [7:0]   conf_cyc_type1_target_bus_num ;
480
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
481
 
482
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
483
(
484
    .CLK              ( pci_clock),
485
    .AD               ( AD ),
486
    .CBE              ( CBE ),
487
    .RST              ( RST ),
488
    .FRAME            ( FRAME ),
489
    .IRDY             ( IRDY ),
490
    .DEVSEL           ( DEVSEL ),
491
    .TRDY             ( TRDY ),
492
    .STOP             ( STOP ),
493
    .PAR              ( PAR ),
494
 
495
    .response         ( conf_cyc_type1_target_response ),
496
    .data_out         ( conf_cyc_type1_target_data ),
497
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
498
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
499
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
500
    .bus_number       ( conf_cyc_type1_target_bus_num )
501
);
502
`endif
503
 
504 15 mihad
// pci clock generator
505
always
506
`ifdef PCI33
507
    #15 pci_clock = ~pci_clock ;
508
`else
509
`ifdef PCI66
510
    #7.5 pci_clock = ~pci_clock ;
511
`endif
512
`endif
513
 
514
// WISHBONE clock generation
515
always
516
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
517
 
518
// Make test name visible when the Master starts working on it
519
reg     [79:0] present_test_name;
520
reg     [79:0] next_test_name;
521
wire    test_accepted = ~test_accepted_l_int;
522
always @(posedge test_accepted)
523
begin
524
    present_test_name <= next_test_name;
525
end
526
 
527
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
528
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
529
 
530
// basic configuration parameters for both behavioral devices
531
parameter [2:0] Master_ID_A                           = `Test_Master_1;
532
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
533
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
534
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
535
 
536
parameter [2:0] Master_ID_B                           = `Test_Master_2;
537
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
538
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
539
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
540
 
541
// basic configuration parameters for REAL device
542
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
543
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
544
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
545
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
546
 
547
// reg  [2:0]   ack_err_rty_termination ;
548
// reg          wait_cycles ;
549
// reg  [7:0]   num_of_retries ;
550
 
551
//reg [19:0] pci_config_base ;
552
reg [7:0] system_burst_size ;
553
reg [7:0] bridge_latency ;
554
integer   target_mem_image ;
555
integer   target_io_image ;
556
 
557
initial
558
begin
559
    next_test_name[79:0] <= "Nowhere___";
560
    reset = 1'b1 ;
561
    pci_clock = 1'b0 ;
562
    wb_clock  = 1'b1 ;
563
    target_message = 32'h0000_0000 ;
564
//  num_of_retries = 8'h01 ;
565
//  ack_err_rty_termination = 3'b100 ;
566
//  wait_cycles = 1'b0 ;
567
 
568
    // system paameters
569
    system_burst_size = 16 ;
570
    bridge_latency    = 8 ;
571
 
572
    // set initial values for controling the behavioral PCI master
573
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
574
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
575
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
576
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
577
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
578
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
579
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
580
 
581
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
582
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
583
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
584
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
585
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
586
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
587
 
588
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
589
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
590
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
591
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
592
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
593
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
594
 
595
    test_master_number = `Test_Master_2 ;
596
    test_address = 32'h0000_0000 ;
597
    test_command = `BC_RESERVED0 ;
598
    test_data = 32'h0000_0000 ;
599
    test_byte_enables_l   = 4'hF ;
600
    test_size = 0 ;
601
    test_make_addr_par_error = 0 ;
602
    test_make_data_par_error = 0;
603
    test_master_initial_wait_states = 0 ;
604
    test_master_subsequent_wait_states = 0 ;
605
    test_target_initial_wait_states = 0 ;
606
    test_target_subsequent_wait_states = 0;
607
    test_target_devsel_speed = `Test_Devsel_Fast ;
608
    test_fast_back_to_back = 0 ;
609
    test_target_termination = `Test_Target_Normal_Completion ;
610
    test_expect_master_abort = 0 ;
611
    test_start = 0 ;
612
    test_target_response = 0 ;
613
 
614
    master1_check_received_data = 0 ;
615
    master2_check_received_data = 0 ;
616
 
617 45 mihad
    `ifdef HOST
618
        conf_cyc_type1_target_response = 0 ;
619
        conf_cyc_type1_target_data = 0 ;
620
        conf_cyc_type1_target_bus_num = 255 ;
621
    `endif
622 15 mihad
 
623
    // fill memory and IO data with random values
624
    fill_memory ;
625
 
626
    INT_I = 0 ;
627
 
628
    // extract from constants which target image can be used as IO and which as memory
629
    `ifdef HOST
630
        target_mem_image = 1 ;
631
        target_io_image  = 1 ;
632
    `else
633
        target_mem_image = -1 ;
634
        target_io_image     = -1 ;
635
        if ( `PCI_BA1_MEM_IO === 0 )
636
            target_mem_image = 1 ;
637
        else
638
            target_io_image = 1 ;
639
 
640
        if ( target_mem_image === -1 )
641
        begin
642
            `ifdef PCI_IMAGE2
643
                if ( `PCI_BA2_MEM_IO === 0 )
644
                    target_mem_image = 2 ;
645
                else if ( target_io_image === -1 )
646
                    target_io_image = 2 ;
647
            `endif
648
        end
649
 
650
        if ( target_mem_image === -1 )
651
        begin
652
            `ifdef PCI_IMAGE3
653
                if ( `PCI_BA3_MEM_IO === 0 )
654
                    target_mem_image = 3 ;
655
                else if ( target_io_image === -1 )
656
                    target_io_image = 3 ;
657
            `endif
658
        end
659
 
660
        if ( target_mem_image === -1 )
661
        begin
662
            `ifdef PCI_IMAGE4
663
                if ( `PCI_BA4_MEM_IO === 0 )
664
                    target_mem_image = 4 ;
665
                else if ( target_io_image === -1 )
666
                    target_io_image = 4 ;
667
            `endif
668
        end
669
 
670
        if ( target_mem_image === -1 )
671
        begin
672
            `ifdef PCI_IMAGE5
673
                if ( `PCI_BA5_MEM_IO === 0 )
674
                    target_mem_image = 5 ;
675
                else if ( target_io_image === -1 )
676
                    target_io_image = 5 ;
677
            `endif
678
        end
679
    `endif
680
 
681
    tests_successfull = 0 ;
682
    tests_failed = 0 ;
683
 
684
    tb_log_file = $fopen("../log/pci_tb.log") ;
685
 
686
    if ( tb_log_file < 2 )
687
    begin
688
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
689
        $finish ;
690
    end
691
 
692
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
693
    $fdisplay( tb_log_file,"" ) ;
694
 
695
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
696
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
697
 
698
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
699
    begin
700
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
701
        $finish ;
702
    end
703
 
704
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
705
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
706
 
707
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
708
    if ( pci_mon_log_file_desc < 2 )
709
    begin
710
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
711
        $finish ;
712
    end
713
 
714
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
715
 
716
    run_tests ;
717
end
718
 
719
task fill_memory ;
720
    integer temp_index ;
721
begin
722
    // fill write memories with random data
723
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
724
    begin
725
        wmem_data[temp_index[9:0]] = $random ;
726 26 mihad
        # 1;
727 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
728 26 mihad
        # 1;
729 15 mihad
    end
730
    // fill WB slave behavioral MEMORY
731
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
732
    begin
733
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
734
        # 1;
735
    end
736
end
737
endtask // fill_memory
738
 
739
reg [2:0] tb_init_waits ;
740
reg [2:0] tb_subseq_waits ;
741
reg [2:0] tb_target_decode_speed ;
742
 
743
task run_tests ;
744
begin
745
    // first - reset logic
746
    do_reset ;
747 45 mihad
    test_initial_conf_values ;
748
 
749 15 mihad
    next_test_name[79:0] <= "Initing...";
750
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
751
 
752
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
753
    begin
754
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
755
        begin
756
 
757
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
758
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
759
 
760
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
761
            begin
762
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
763
 
764
                `ifdef HOST
765
                    configure_bridge_target ;
766
                    find_pci_devices ;
767 45 mihad
                    test_configuration_cycle_target_abort ;
768
                    test_configuration_cycle_type1_generation ;
769 15 mihad
                `endif
770
 
771
                @(posedge pci_clock) ;
772
                configure_target(1) ;
773
                @(posedge pci_clock) ;
774
                configure_target(2) ;
775
 
776
                `ifdef GUEST
777
                    configure_bridge_target ;
778
                `endif
779
 
780
               next_test_name[79:0] <= "WB_SLAVE..";
781
 
782
                $display("Testing WISHBONE slave images' features!") ;
783
                test_wb_image(1) ;
784
 
785
                `ifdef WB_IMAGE2
786
                    test_wb_image(2) ;
787
                `else
788
                    $display(" WB IMAGE 2 not implemented! ") ;
789
                `endif
790
 
791
                `ifdef WB_IMAGE3
792
                    test_wb_image(3) ;
793
                `else
794
                    $display(" WB IMAGE 3 not implemented! ") ;
795
                `endif
796
 
797
                `ifdef WB_IMAGE4
798
                    test_wb_image(4) ;
799
                `else
800
                    $display(" WB IMAGE 4 not implemented! ") ;
801
                `endif
802
 
803
                `ifdef WB_IMAGE5
804
                    test_wb_image(5) ;
805
                `else
806
                    $display(" WB IMAGE 5 not implemented! ") ;
807
                `endif
808
 
809
                wb_slave_errors ;
810
                wb_to_pci_error_handling ;
811
 
812
                parity_checking ;
813
 
814
                wb_to_pci_transactions ;
815
 
816
                `ifdef HOST
817
                iack_cycle ;
818
                `endif
819
 
820
            end
821
            $display(" ") ;
822
            $display("WB slave images' tests finished!") ;
823
 
824
            $display("########################################################################") ;
825
            $display("########################################################################") ;
826
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
827
            $display("########################################################################") ;
828
            $display("########################################################################") ;
829
 
830
            $display("Testing PCI target images' features!") ;
831
            configure_bridge_target_base_addresses ;
832
 
833 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
834
                test_conf_cycle_type1_reference ;
835
            `endif
836
 
837 15 mihad
            `ifdef HOST
838
             `ifdef NO_CNF_IMAGE
839
              `ifdef PCI_IMAGE0
840
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
841
            test_pci_image(0) ;
842
              `else
843
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
844
              `endif
845
             `else
846
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
847
             `endif
848
            `endif
849
 
850
            $display("PCI image 1 is ALWAYS implemented!") ;
851
            test_pci_image(1) ;
852
 
853
            `ifdef PCI_IMAGE2
854
            $display("PCI image 2 is implemented!") ;
855
            test_pci_image(2) ;
856
            `else
857
            $display("PCI image 2 is NOT implemented!") ;
858
            `endif
859
 
860
            `ifdef PCI_IMAGE3
861
            $display("PCI image 3 is implemented!") ;
862
            test_pci_image(3) ;
863
            `else
864
            $display("PCI image 3 is NOT implemented!") ;
865
            `endif
866
 
867
            `ifdef PCI_IMAGE4
868
            $display("PCI image 4 is implemented!") ;
869
            test_pci_image(4) ;
870
            `else
871
            $display("PCI image 4 is NOT implemented!") ;
872
            `endif
873
 
874
            `ifdef PCI_IMAGE5
875
            $display("PCI image 5 is implemented!") ;
876
            test_pci_image(5) ;
877
            `else
878
            $display("PCI image 5 is NOT implemented!") ;
879
            `endif
880
 
881
            test_wb_error_rd ;
882
 
883
            target_fast_back_to_back ;
884
            target_disconnects ;
885
 
886
            if ( target_io_image !== -1 )
887
                test_target_abort( target_io_image ) ;
888
            $display(" ") ;
889
            $display("PCI target images' tests finished!") ;
890
 
891
            transaction_ordering ;
892 33 mihad
 
893
            target_completion_expiration ;
894 15 mihad
            $display(" ") ;
895
            $display("PCI transaction ordering tests finished!") ;
896
        end
897
    end
898
 
899
    test_summary ;
900
 
901
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
902
    $stop ;
903
end
904
endtask // run_tests
905
 
906
task do_reset;
907
begin
908
    next_test_name[79:0] <= "Reset.....";
909
 
910
    reset = 1'b1 ;
911
    #100 ;
912
    `ifdef HOST
913
        @(posedge wb_clock) ;
914
    `else
915
    `ifdef GUEST
916
        @(posedge pci_clock) ;
917
    `endif
918
    `endif
919
 
920
    reset <= 1'b0 ;
921
 
922 45 mihad
    `ifdef HOST
923
        @(posedge wb_clock) ;
924
    `else
925
    `ifdef GUEST
926
        @(posedge pci_clock) ;
927
    `endif
928
    `endif
929
 
930 15 mihad
end
931
endtask
932
 
933
/*############################################################################
934
WB SLAVE UNIT tasks
935
===================
936
############################################################################*/
937
 
938
task configure_target ;
939 45 mihad
    input [1:0]  beh_dev_num ;
940 15 mihad
    reg   [31:0] base_address1 ;
941
    reg   [31:0] base_address2 ;
942
    reg   [2:0]  Master_ID;
943
    reg   [31:0] Target_Config_Addr;
944 45 mihad
    reg   [4:0]  device_num ;
945 15 mihad
begin
946 45 mihad
    if (beh_dev_num === 1)
947 15 mihad
    begin
948
        base_address1       = `BEH_TAR1_MEM_START ;
949
        base_address2       = `BEH_TAR1_IO_START  ;
950
        Master_ID           = `Test_Master_2 ;
951
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
952 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
953 15 mihad
    end
954
    else
955 45 mihad
    if (beh_dev_num === 2)
956 15 mihad
    begin
957
        base_address1       = `BEH_TAR2_MEM_START ;
958
        base_address2       = `BEH_TAR2_IO_START  ;
959
        Master_ID           = `Test_Master_1 ;
960
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
961 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
962 15 mihad
    end
963
 
964
    // write target's base addresses
965
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
966
    // type 0 cycle, byte enables, base address
967
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
968
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
969
 
970
    // enable target's response and master
971
    // enable parity errors, disable system error
972
 
973
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
974
 
975
end
976
endtask //configure_target
977
 
978
task test_wb_image ;
979
    input [2:0]  image_num ;
980
    reg   [11:0] ctrl_offset ;
981
    reg   [11:0] ba_offset ;
982
    reg   [11:0] am_offset ;
983
    reg   [11:0] ta_offset ;
984
    reg   [11:0] err_cs_offset ;
985
    reg `WRITE_STIM_TYPE write_data ;
986
    reg `READ_STIM_TYPE  read_data ;
987
    reg `READ_RETURN_TYPE read_status ;
988
 
989
    reg `WRITE_RETURN_TYPE write_status ;
990
    reg `WB_TRANSFER_FLAGS write_flags ;
991
    reg [31:0] temp_val ;
992
    reg        ok   ;
993
    reg [11:0] pci_ctrl_offset ;
994
    reg [31:0] image_base ;
995
    reg [31:0] target_address ;
996
    reg [31:0] translation_address ;
997
    integer    i ;
998
    integer    j ;
999
begin:main
1000
    pci_ctrl_offset = 12'h4 ;
1001
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1002
    // image 0 can only be configuration image - start with 1
1003
    if (image_num === 1)
1004
    begin
1005
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1006
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1007
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1008
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1009
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1010
    end
1011
    else if (image_num === 2)
1012
    begin
1013
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1014
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1015
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1016
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1017
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1018
    end
1019
    else if (image_num === 3)
1020
    begin
1021
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1022
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1023
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1024
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1025
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1026
    end
1027
    else if (image_num === 4)
1028
    begin
1029
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1030
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1031
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1032
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1033
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1034
    end
1035
    else if (image_num === 5)
1036
    begin
1037
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1038
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1039
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1040
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1041
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1042
    end
1043
    else
1044
    begin
1045
        test_name   = "WB IMAGES' FEATURES TEST" ;
1046
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1047
        disable main ;
1048
    end
1049
 
1050
    target_address  = `BEH_TAR1_MEM_START ;
1051
    image_base      = 0 ;
1052
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1053
 
1054
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1055
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1056
    write_flags                      = 0 ;
1057
    write_flags`INIT_WAITS           = tb_init_waits ;
1058
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1059
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1060
 
1061
    test_name = "WB IMAGE CONFIGURATION" ;
1062
    // enable master & target operation
1063
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1064
    if ( ok !== 1 )
1065
    begin
1066
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1067
        test_fail("write to PCI Device Control register didn't succeede");
1068
        disable main ;
1069
    end
1070
 
1071
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1072
    if ( ok !== 1 )
1073
    begin
1074
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1075
        test_fail("write to WB Error Control and Status register didn't succeede");
1076
        disable main ;
1077
    end
1078
 
1079
    // prepare image control register
1080
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1081
    if ( ok !== 1 )
1082
    begin
1083
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1084
        test_fail("write to WB Image Control register didn't succeede");
1085
        disable main ;
1086
    end
1087
 
1088
    // prepare base address register
1089
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1090
    if ( ok !== 1 )
1091
    begin
1092
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1093
        test_fail("write to WB Base Address register didn't succeede");
1094
        disable main ;
1095
    end
1096
 
1097
    // write address mask register
1098
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1099
    if ( ok !== 1 )
1100
    begin
1101
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1102
        test_fail("write to WB Address Mask register didn't succeede");
1103
        disable main ;
1104
    end
1105
 
1106
    fork
1107
    begin
1108
        write_data`WRITE_ADDRESS = target_address ;
1109
        write_data`WRITE_DATA    = wmem_data[0] ;
1110
        write_data`WRITE_SEL     = 4'hF ;
1111
 
1112
        // handle retries from now on
1113
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1114
 
1115
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1116
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1117
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1118
        begin
1119
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1120
            test_fail("WB Slave state machine failed to post single memory write");
1121
            disable main ;
1122
        end
1123
 
1124
        // read written data back
1125
        read_data`READ_ADDRESS  = target_address ;
1126
        read_data`READ_SEL      = 4'hF ;
1127
        read_data`READ_TAG_STIM = 0 ;
1128
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1129
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1130
        begin
1131
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1132
            test_fail("PCI bridge didn't process the read as expected");
1133
            disable main ;
1134
        end
1135
 
1136
        if (read_status`READ_DATA !== wmem_data[0])
1137
        begin
1138
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1139
            test_fail("PCI bridge returned unexpected Read Data");
1140
        end
1141
        else
1142
            test_ok ;
1143
    end
1144
    begin
1145
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1146
        if ( ok !== 1 )
1147
        begin
1148
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1149
        end
1150
        else
1151
            test_ok ;
1152
 
1153
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1154
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1155
        if ( ok !== 1 )
1156
        begin
1157
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1158
        end
1159
    end
1160
    join
1161
 
1162
    // if address translation is implemented - try it out
1163
    translation_address = image_base ;
1164
    `ifdef ADDR_TRAN_IMPL
1165
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1166
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1167
    if ( ok !== 1 )
1168
    begin
1169
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1170
        test_fail("write to WB Image Translation Address Register failed") ;
1171
        disable main ;
1172
    end
1173
 
1174
    target_address  = `BEH_TAR2_MEM_START ;
1175
    image_base      = 0 ;
1176
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1177
 
1178
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1179
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1180
 
1181
    write_flags                      = 0 ;
1182
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1183
 
1184
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1185
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1186
    if ( ok !== 1 )
1187
    begin
1188
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1189
        test_fail("write to WB Image Base Address Register failed") ;
1190
        disable main ;
1191
    end
1192
 
1193
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1194
    // enable address translation
1195
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1196
    if ( ok !== 1 )
1197
    begin
1198
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1199
        test_fail("write to WB Image Control Register failed") ;
1200
        disable main ;
1201
    end
1202
 
1203
    `endif
1204
 
1205
    fork
1206
    begin
1207
        write_data`WRITE_ADDRESS = target_address + 4 ;
1208
        write_data`WRITE_DATA    = wmem_data[1] ;
1209
        write_data`WRITE_SEL     = 4'hF ;
1210
 
1211
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1212
 
1213
        `ifdef ADDR_TRAN_IMPL
1214
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1215
        `else
1216
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1217
        `endif
1218
 
1219
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1220
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1221
        begin
1222
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1223
            test_fail("WB Slave state machine failed to post single memory write") ;
1224
            disable main ;
1225
        end
1226
 
1227
        // read written data back
1228
        read_data`READ_ADDRESS  = target_address + 4 ;
1229
        read_data`READ_SEL      = 4'hF ;
1230
        read_data`READ_TAG_STIM = 0 ;
1231
 
1232
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1233
 
1234
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1235
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1236
        begin
1237
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1238
            test_fail("PCI bridge failed to process single delayed memory read") ;
1239
            disable main ;
1240
        end
1241
 
1242
        if (read_status`READ_DATA !== wmem_data[1])
1243
        begin
1244
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1245
            test_fail("PCI bridge returned unexpected Read Data");
1246
        end
1247
        else
1248
            test_ok ;
1249
    end
1250
    begin
1251
        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 ) ;
1252
        if ( ok !== 1 )
1253
        begin
1254
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1255
        end
1256
        else
1257
            test_ok ;
1258
 
1259
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1260
        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 ) ;
1261
        if ( ok !== 1 )
1262
        begin
1263
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1264
        end
1265
    end
1266
    join
1267
 
1268
    // 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
1269
    // prepare write data
1270
    for ( i = 0 ; i < 6 ; i = i + 1 )
1271
    begin
1272
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1273
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1274
        write_data`WRITE_SEL     = 4'hF ;
1275
        wishbone_master.blk_write_data[i] = write_data ;
1276
    end
1277
 
1278
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1279
    write_flags`WB_TRANSFER_CAB    = 1 ;
1280
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1281
 
1282
    fork
1283
    begin
1284
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1285
        wishbone_master.wb_block_write(write_flags, write_status) ;
1286
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1287
        begin
1288
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1289
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1290
            disable main ;
1291
        end
1292
    end
1293
    begin
1294
        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 ) ;
1295
        if ( ok !== 1 )
1296
        begin
1297
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1298
        end
1299
        else
1300
            test_ok ;
1301
    end
1302
    join
1303
 
1304
    // set burst size and latency timer
1305
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1306
 
1307
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1308
    write_flags`WB_TRANSFER_CAB    = 1 ;
1309
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1310
 
1311
    // prepare read data
1312
    for ( i = 0 ; i < 4 ; i = i + 1 )
1313
    begin
1314
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1315
        read_data`READ_SEL     = 4'hF ;
1316
        wishbone_master.blk_read_data_in[i] = read_data ;
1317
    end
1318
 
1319
    fork
1320
    begin
1321
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1322
        wishbone_master.wb_block_read(write_flags, read_status) ;
1323
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1324
        begin
1325
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1326
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1327
            disable main ;
1328
        end
1329
 
1330
        // check data read from target
1331
        for ( i = 0 ; i < 4 ; i = i + 1 )
1332
        begin
1333
            read_status = wishbone_master.blk_read_data_out[i] ;
1334
            if (read_status`READ_DATA !== wmem_data[2 + i])
1335
            begin
1336
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1337
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1338
            end
1339
        end
1340
    end
1341
    begin
1342
        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 ) ;
1343
        if ( ok !== 1 )
1344
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1345
        else
1346
            test_ok ;
1347
 
1348
        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 ) ;
1349
        if ( ok !== 1 )
1350
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1351
        else
1352
            test_ok ;
1353
 
1354
        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 ) ;
1355
        if ( ok !== 1 )
1356
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1357
        else
1358
            test_ok ;
1359
 
1360
        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 ) ;
1361
        if ( ok !== 1 )
1362
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1363
        else
1364
            test_ok ;
1365
 
1366
    end
1367
    join
1368
 
1369
    // now repeat this same burst read with various image features enabled or disabled
1370
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1371
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1372
    if (ok !== 1)
1373
    begin
1374
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1375
        test_fail("write to WB Image control register failed") ;
1376
        disable main ;
1377
    end
1378
 
1379
    fork
1380
    begin
1381
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1382
        wishbone_master.wb_block_read(write_flags, read_status) ;
1383
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1384
        begin
1385
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1386
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1387
            disable main ;
1388
        end
1389
 
1390
        // check data read from target
1391
        for ( i = 0 ; i < 4 ; i = i + 1 )
1392
        begin
1393
            read_status = wishbone_master.blk_read_data_out[i] ;
1394
            if (read_status`READ_DATA !== wmem_data[2 + i])
1395
            begin
1396
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1397
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1398
            end
1399
            else
1400
                test_ok ;
1401
        end
1402
    end
1403
    begin
1404
        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 ) ;
1405
        if ( ok !== 1 )
1406
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1407
    end
1408
    join
1409
 
1410
    read_data`READ_ADDRESS  = target_address ;
1411
    read_data`READ_SEL      = 4'hF ;
1412
    read_data`READ_TAG_STIM = 0 ;
1413
 
1414
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1415
    fork
1416
    begin
1417
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1418
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1419
        begin
1420
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1421
            test_fail("delayed single memory read wasn't processed as expected") ;
1422
            disable main ;
1423
        end
1424
 
1425
        if (read_status`READ_DATA !== wmem_data[0])
1426
        begin
1427
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1428
            test_fail("delayed single memory read data value returned was not as expected") ;
1429
        end
1430
        else
1431
            test_ok ;
1432
    end
1433
    begin
1434
        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 ) ;
1435
        if ( ok !== 1 )
1436
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1437
    end
1438
    join
1439
 
1440
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1441
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1442
    if (ok !== 1)
1443
    begin
1444
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1445
        test_fail("write to WB Image control register failed") ;
1446
        disable main ;
1447
    end
1448
 
1449
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1450
    fork
1451
    begin
1452
        wishbone_master.wb_block_read(write_flags, read_status) ;
1453
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1454
        begin
1455
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1456
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1457
            disable main ;
1458
        end
1459
 
1460
        // check data read from target
1461
        for ( i = 0 ; i < 4 ; i = i + 1 )
1462
        begin
1463
            read_status = wishbone_master.blk_read_data_out[i] ;
1464
            if (read_status`READ_DATA !== wmem_data[2 + i])
1465
            begin
1466
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1467
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1468
            end
1469
            else
1470
                test_ok ;
1471
        end
1472
    end
1473
    begin
1474
        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 ) ;
1475
        if ( ok !== 1 )
1476
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1477
    end
1478
    join
1479
 
1480
    read_data`READ_ADDRESS  = target_address + 4 ;
1481
    read_data`READ_SEL      = 4'hF ;
1482
    read_data`READ_TAG_STIM = 0 ;
1483
 
1484
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1485
    fork
1486
    begin
1487
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1488
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1489
        begin
1490
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1491
            test_fail("delayed single memory read wasn't processed as expected") ;
1492
            disable main ;
1493
        end
1494
 
1495
        if (read_status`READ_DATA !== wmem_data[1])
1496
        begin
1497
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1498
            test_fail("delayed single memory read data value returned was not as expected") ;
1499
        end
1500
        else
1501
            test_ok ;
1502
    end
1503
    begin
1504
        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 ) ;
1505
        if ( ok !== 1 )
1506
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1507
    end
1508
    join
1509
 
1510
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1511
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1512
    if (ok !== 1)
1513
    begin
1514
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1515
        test_fail("write to WB Image control register failed") ;
1516
        disable main ;
1517
    end
1518
 
1519
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1520
    fork
1521
    begin
1522
        wishbone_master.wb_block_read(write_flags, read_status) ;
1523
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1524
        begin
1525
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1526
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1527
            disable main ;
1528
        end
1529
 
1530
        // check data read from target
1531
        for ( i = 0 ; i < 4 ; i = i + 1 )
1532
        begin
1533
            read_status = wishbone_master.blk_read_data_out[i] ;
1534
            if (read_status`READ_DATA !== wmem_data[2 + i])
1535
            begin
1536
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1537
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1538
            end
1539
            else
1540
                test_ok ;
1541
        end
1542
    end
1543
    begin
1544
        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 ) ;
1545
        if ( ok !== 1 )
1546
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1547
    end
1548
    join
1549
 
1550
    read_data`READ_ADDRESS  = target_address + 8 ;
1551
    read_data`READ_SEL      = 4'hF ;
1552
    read_data`READ_TAG_STIM = 0 ;
1553
 
1554
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1555
    fork
1556
    begin
1557
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1558
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1559
        begin
1560
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1561
            test_fail("delayed single memory read wasn't processed as expected") ;
1562
            disable main ;
1563
        end
1564
 
1565
        if (read_status`READ_DATA !== wmem_data[2])
1566
        begin
1567
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1568
            test_fail("delayed single memory read data value returned was not as expected") ;
1569
        end
1570
        else
1571
            test_ok ;
1572
    end
1573
    begin
1574
        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 ) ;
1575
        if ( ok !== 1 )
1576
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1577
    end
1578
    join
1579
 
1580
    // map image to IO space
1581
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1582
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1583
    if ( ok !== 1 )
1584
    begin
1585
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1586
        test_fail("write to WB Image Base Address register failed") ;
1587
        disable main ;
1588
    end
1589
 
1590
    write_data`WRITE_ADDRESS = target_address ;
1591
    write_data`WRITE_DATA    = wmem_data[11] ;
1592
    write_data`WRITE_SEL     = 4'hF ;
1593
 
1594
    // handle retries from now on
1595
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1596
 
1597
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1598
    fork
1599
    begin
1600
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1601
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1602
        begin
1603
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1604
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1605
            disable main ;
1606
        end
1607
    end
1608
    begin
1609
        // currently IO commands not supported in behavioral models - master abort
1610
        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 ) ;
1611
        if ( ok !== 1 )
1612
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1613
        else
1614
            test_ok ;
1615
    end
1616
    join
1617
 
1618
    read_data`READ_ADDRESS  = target_address ;
1619
    read_data`READ_SEL      = 4'hF ;
1620
    read_data`READ_TAG_STIM = 0 ;
1621
 
1622
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1623
 
1624
    // currently io commands are not supported by behavioral target - transfer should not be completed
1625
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1626
    fork
1627
    begin
1628
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1629
        if (read_status`CYC_ERR !== 1)
1630
        begin
1631
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1632
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1633
            disable main ;
1634
        end
1635
        else
1636
            test_ok ;
1637
    end
1638
    begin
1639
        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 ) ;
1640
        if ( ok !== 1 )
1641
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1642
    end
1643
    join
1644
 
1645
    // test byte addressing
1646
    read_data`READ_ADDRESS = target_address + 2 ;
1647
    read_data`READ_SEL     = 4'b1100 ;
1648
 
1649
    fork
1650
    begin
1651
        // currently io commands are not supported by behavioral target - transfer should not be completed
1652
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1653
        if (read_status`CYC_ERR !== 1)
1654
        begin
1655
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1656
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1657
            disable main ;
1658
        end
1659
        else test_ok ;
1660
    end
1661
    begin
1662
        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 ) ;
1663
        if ( ok !== 1 )
1664
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1665
    end
1666
    join
1667
 
1668
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1669
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1670
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1671
    if ( ok !== 1 )
1672
    begin
1673
        test_fail("WB Base address register could not be written") ;
1674
        disable main ;
1675
    end
1676
 
1677
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1678
    if ( ok !== 1 )
1679
    begin
1680
        test_fail("WB Address Mask register could not be written") ;
1681
        disable main ;
1682
    end
1683
 
1684
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1685
    if ( ok !== 1 )
1686
    begin
1687
        test_fail("WB Image Control register could not be written") ;
1688
        disable main ;
1689
    end
1690
 
1691
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1692
    write_data`WRITE_DATA    = wmem_data[11] ;
1693
    write_data`WRITE_SEL     = 4'b1000 ;
1694
 
1695
    // handle retries from now on
1696
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1697
 
1698
    fork
1699
    begin
1700
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1701
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1702
        begin
1703
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1704
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1705
            disable main ;
1706
        end
1707
    end
1708
    begin
1709
        // currently IO commands not supported in behavioral models - master abort
1710
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1711
        if ( ok !== 1 )
1712
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1713
        else
1714
            test_ok ;
1715
    end
1716
    join
1717
 
1718
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1719
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1720
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1721
 
1722
    fork
1723
    begin
1724
        // currently io commands are not supported by behavioral target - transfer should not be completed
1725
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1726
        if (read_status`CYC_ERR !== 1)
1727
        begin
1728
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1729
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1730
            disable main ;
1731
        end
1732
        else test_ok ;
1733
    end
1734
    begin
1735
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1736
        if ( ok !== 1 )
1737
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1738
    end
1739
    join
1740
 
1741
    test_name = "DISABLING WB IMAGE" ;
1742
 
1743
    // disable current image
1744
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1745
    if ( ok !== 1 )
1746
    begin
1747
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1748
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1749
        disable main ;
1750
    end
1751
 
1752
    // clear master abort status bit
1753
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1754
    if ( ok !== 1 )
1755
    begin
1756
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1757
        test_fail("write to PCI Device Status register not accepted as expected") ;
1758
        disable main ;
1759
    end
1760
 
1761
end //main
1762
endtask //test_wb_image
1763
 
1764
task wb_slave_errors ;
1765
    reg   [11:0] ctrl_offset ;
1766
    reg   [11:0] ba_offset ;
1767
    reg   [11:0] am_offset ;
1768
    reg   [11:0] ta_offset ;
1769
    reg `WRITE_STIM_TYPE write_data ;
1770
    reg `READ_STIM_TYPE  read_data ;
1771
    reg `READ_RETURN_TYPE read_status ;
1772
 
1773
    reg `WRITE_RETURN_TYPE write_status ;
1774
    reg `WB_TRANSFER_FLAGS write_flags ;
1775
    reg [31:0] temp_val1 ;
1776
    reg [31:0] temp_val2 ;
1777
    reg        ok   ;
1778
    reg [11:0] pci_ctrl_offset ;
1779
    reg [31:0] image_base ;
1780
    reg [31:0] target_address ;
1781
    integer    i ;
1782
    reg skip ;
1783
fork
1784
begin:main
1785
 
1786
    `ifdef GUEST
1787
        skip = 1 ;
1788
    `else
1789
        skip = 0 ;
1790
    `endif
1791
 
1792
    pci_ctrl_offset = 12'h4 ;
1793
 
1794
    // image 1 is used for error testing, since it is always implemented
1795
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1796
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1797
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1798
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1799
 
1800
    target_address  = `BEH_TAR1_MEM_START ;
1801
    image_base      = 0 ;
1802
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1803
 
1804
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1805
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1806
    write_flags                    = 0 ;
1807
    write_flags`INIT_WAITS         = tb_init_waits ;
1808
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1809
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1810
 
1811
    // enable master & target operation
1812
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1813
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1814
    if ( ok !== 1 )
1815
    begin
1816
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1817
        test_fail("PCI Device Control register couldn't be written") ;
1818
        disable no_transaction ;
1819
        disable main ;
1820
    end
1821
 
1822
    // prepare image control register
1823
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1824
    if ( ok !== 1 )
1825
    begin
1826
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1827
        test_fail("WB Image Control register couldn't be written") ;
1828
        disable no_transaction ;
1829
        disable main ;
1830
    end
1831
 
1832
    // prepare base address register
1833
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1834
    if ( ok !== 1 )
1835
    begin
1836
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1837
        test_fail("WB Base Address register couldn't be written") ;
1838
        disable no_transaction ;
1839
        disable main ;
1840
    end
1841
 
1842
    // write address mask register
1843
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1844
    if ( ok !== 1 )
1845
    begin
1846
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1847
        test_fail("WB Address Mask register couldn't be written") ;
1848
        disable no_transaction ;
1849
        disable main ;
1850
    end
1851
 
1852
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1853
 
1854
    skip = 0 ;
1855
 
1856
    // memory mapped image - access is erroneous when address is not alligned
1857
    write_data`WRITE_ADDRESS = target_address + 1 ;
1858
    write_data`WRITE_DATA    = wmem_data[0] ;
1859
    write_data`WRITE_SEL     = 4'hF ;
1860
 
1861
    // handle retries from now on
1862
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1863
 
1864
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1865
 
1866
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1867
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1868
    begin
1869
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1870
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1871
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1872
        disable no_transaction ;
1873
        disable main ;
1874
    end
1875
 
1876
    write_data`WRITE_ADDRESS = target_address + 2 ;
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
 
1887
    end
1888
 
1889
    write_data`WRITE_ADDRESS = target_address + 3 ;
1890
 
1891
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1892
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1893
    begin
1894
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1895
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1896
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1897
        disable no_transaction ;
1898
        disable main ;
1899
    end
1900
 
1901
    test_ok ;
1902
 
1903
    // perform same tests for read accesses
1904
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1905
 
1906
    read_data`READ_ADDRESS  = target_address + 2 ;
1907
    read_data`READ_SEL      = 4'hF ;
1908
    read_data`READ_TAG_STIM = 0 ;
1909
 
1910
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1911
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1912
    begin
1913
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1914
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1915
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1916
        disable no_transaction ;
1917
        disable main ;
1918
    end
1919
 
1920
    test_ok ;
1921
 
1922
    // prepare write data
1923
    for ( i = 0 ; i < 6 ; i = i + 1 )
1924
    begin
1925
        write_data`WRITE_DATA    = wmem_data[i] ;
1926
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1927
        write_data`WRITE_SEL     = 4'hF ;
1928
        wishbone_master.blk_write_data[i] = write_data ;
1929
    end
1930
 
1931
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1932
    write_flags`WB_TRANSFER_CAB    = 1 ;
1933
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1934
 
1935
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1936
    wishbone_master.wb_block_write(write_flags, write_status) ;
1937
 
1938
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1939
    begin
1940
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1941
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1942
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1943
        disable no_transaction ;
1944
        disable main ;
1945
    end
1946
 
1947
    // prepare read data
1948
    for ( i = 0 ; i < 6 ; i = i + 1 )
1949
    begin
1950
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
1951
        read_data`READ_SEL     = 4'hF ;
1952
        wishbone_master.blk_read_data_in[i] = read_data ;
1953
    end
1954
 
1955
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
1956
    wishbone_master.wb_block_read(write_flags, read_status) ;
1957
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1958
    begin
1959
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1960
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1961
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
1962
        disable no_transaction ;
1963
        disable main ;
1964
    end
1965
 
1966
    test_ok ;
1967
 
1968
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1969
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
1970
 
1971
    // map image to IO space
1972
    `ifdef GUEST
1973
        skip = 1 ;
1974
    `endif
1975
 
1976
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
1977
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1978
    if ( ok !== 1 )
1979
    begin
1980
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1981
        test_fail("WB Image Base Address register couldn't be written") ;
1982
        disable no_transaction ;
1983
        disable main ;
1984
    end
1985
 
1986
    skip = 0 ;
1987
 
1988
    write_data`WRITE_ADDRESS = target_address ;
1989
    write_data`WRITE_DATA    = wmem_data[0] ;
1990
    write_data`WRITE_SEL     = 4'b1010 ;
1991
 
1992
    // don't handle retries
1993
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1994
 
1995
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
1996
 
1997
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1998
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1999
    begin
2000
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2001
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2002
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2003
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2004
        disable no_transaction ;
2005
        disable main ;
2006
    end
2007
 
2008
    write_data`WRITE_ADDRESS = target_address + 1 ;
2009
    write_data`WRITE_SEL     = 4'b0011 ;
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_SEL     = 4'b1100 ;
2023
 
2024
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2025
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2026
    begin
2027
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2028
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2029
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2030
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2031
        disable no_transaction ;
2032
        disable main ;
2033
    end
2034
 
2035
    write_data`WRITE_ADDRESS = target_address + 2 ;
2036
    write_data`WRITE_SEL     = 4'b0101 ;
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_SEL     = 4'b1000 ;
2050
 
2051
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2052
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2053
    begin
2054
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2055
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2056
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2057
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2058
        disable no_transaction ;
2059
        disable main ;
2060
    end
2061
 
2062
    write_data`WRITE_ADDRESS = target_address + 3 ;
2063
    write_data`WRITE_SEL     = 4'b1010 ;
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
    write_data`WRITE_SEL     = 4'b0110 ;
2077
 
2078
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2079
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2080
    begin
2081
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2082
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2083
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2084
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2085
        disable no_transaction ;
2086
        disable main ;
2087
    end
2088
 
2089
    test_ok ;
2090
 
2091
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2092
 
2093
    read_data`READ_ADDRESS  = target_address + 3 ;
2094
    read_data`READ_SEL      = 4'hF ;
2095
    read_data`READ_TAG_STIM = 0 ;
2096
 
2097
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2098
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2099
    begin
2100
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2101
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2102
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2103
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2104
        disable no_transaction ;
2105
        disable main ;
2106
    end
2107
 
2108
    test_ok ;
2109
 
2110
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2111
    // prepare write data
2112
    for ( i = 0 ; i < 6 ; i = i + 1 )
2113
    begin
2114
        write_data`WRITE_DATA    = wmem_data[i] ;
2115
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2116
        write_data`WRITE_SEL     = 4'hF ;
2117
        wishbone_master.blk_write_data[i] = write_data ;
2118
    end
2119
 
2120
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2121
    write_flags`WB_TRANSFER_CAB    = 1 ;
2122
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2123
 
2124
    wishbone_master.wb_block_write(write_flags, write_status) ;
2125
 
2126
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2127
    begin
2128
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2129
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2130
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2131
        disable no_transaction ;
2132
        disable main ;
2133
    end
2134
 
2135
    test_ok ;
2136
 
2137
    test_name = "CAB I/O READ TO WB SLAVE" ;
2138
    // prepare read data
2139
    for ( i = 0 ; i < 6 ; i = i + 1 )
2140
    begin
2141
        read_data`READ_ADDRESS = target_address + 4*i ;
2142
        read_data`READ_SEL     = 4'hF ;
2143
        wishbone_master.blk_read_data_in[i] = read_data ;
2144
    end
2145
 
2146
    wishbone_master.wb_block_read(write_flags, read_status) ;
2147
 
2148
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2149
    begin
2150
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2151
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2152
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2153
        disable no_transaction ;
2154
        disable main ;
2155
    end
2156
 
2157
    test_ok ;
2158
 
2159
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2160
 
2161
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2162
 
2163
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2164
    write_data`WRITE_ADDRESS = target_address + 1 ;
2165
    write_data`WRITE_DATA    = wmem_data[0] ;
2166
    write_data`WRITE_SEL     = 4'hF ;
2167
 
2168
    // don't handle retries
2169
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2170
 
2171
    `ifdef HOST
2172
        `define DO_W_CONF_TEST
2173
        `define DO_R_CONF_TEST
2174
    `else
2175
        `ifdef WB_CNF_IMAGE
2176
             `define DO_R_CONF_TEST
2177
        `endif
2178
    `endif
2179
 
2180
    `ifdef DO_W_CONF_TEST
2181
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2182
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2183
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2184
    begin
2185
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2186
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2187
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2188
        disable no_transaction ;
2189
        disable main ;
2190
    end
2191
 
2192
    write_data`WRITE_ADDRESS = target_address + 2 ;
2193
 
2194
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2195
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2196
    begin
2197
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2198
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2199
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2200
        disable no_transaction ;
2201
        disable main ;
2202
    end
2203
 
2204
    write_data`WRITE_ADDRESS = target_address + 3 ;
2205
 
2206
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2207
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2208
    begin
2209
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2210
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2211
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2212
        disable no_transaction ;
2213
        disable main ;
2214
    end
2215
 
2216
    test_ok ;
2217
    `endif
2218
 
2219
    `ifdef DO_R_CONF_TEST
2220
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2221
    read_data`READ_ADDRESS  = target_address + 3 ;
2222
    read_data`READ_SEL      = 4'hF ;
2223
    read_data`READ_TAG_STIM = 0 ;
2224
 
2225
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2226
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2227
    begin
2228
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2229
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2230
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2231
        disable no_transaction ;
2232
        disable main ;
2233
    end
2234
 
2235
    test_ok ;
2236
    `endif
2237
 
2238
    `ifdef DO_W_CONF_TEST
2239
    // prepare write data
2240
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2241
    for ( i = 0 ; i < 6 ; i = i + 1 )
2242
    begin
2243
        write_data`WRITE_DATA    = wmem_data[i] ;
2244
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2245
        write_data`WRITE_SEL     = 4'hF ;
2246
        wishbone_master.blk_write_data[i] = write_data ;
2247
    end
2248
 
2249
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2250
    write_flags`WB_TRANSFER_CAB    = 1 ;
2251
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2252
 
2253
    wishbone_master.wb_block_write(write_flags, write_status) ;
2254
 
2255
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2256
    begin
2257
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2258
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2259
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2260
        disable no_transaction ;
2261
        disable main ;
2262
    end
2263
    test_ok ;
2264
    `endif
2265
 
2266
    `ifdef DO_R_CONF_TEST
2267
    // prepare read data
2268
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2269
    for ( i = 0 ; i < 6 ; i = i + 1 )
2270
    begin
2271
        read_data`READ_ADDRESS = target_address + 4*i ;
2272
        read_data`READ_SEL     = 4'hF ;
2273
        wishbone_master.blk_read_data_in[i] = read_data ;
2274
    end
2275
 
2276
    wishbone_master.wb_block_read(write_flags, read_status) ;
2277
 
2278
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2279
    begin
2280
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2281
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2282
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2283
        disable no_transaction ;
2284
        disable main ;
2285
    end
2286
    test_ok ;
2287
    `endif
2288
 
2289
    `ifdef GUEST
2290
        skip = 1 ;
2291
    `endif
2292
 
2293
    // disable image
2294
    test_name = "DISABLE IMAGE" ;
2295
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2296
    if ( ok !== 1 )
2297
    begin
2298
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2299
        test_fail("WB Address Mask register couldn't be written") ;
2300
        disable no_transaction ;
2301
        disable main ;
2302
    end
2303
 
2304
    skip = 0 ;
2305
 
2306
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2307
 
2308
    disable no_transaction ;
2309
end
2310
begin:no_transaction
2311
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2312
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2313
    forever
2314
    begin
2315
        @(posedge pci_clock) ;
2316
        if ( skip !== 1 )
2317
        begin
2318
            if ( FRAME !== 1 )
2319
            begin
2320
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2321
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2322
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2323
            end
2324
        end
2325
    end
2326
end
2327
join
2328
endtask //wb_slave_errors
2329
 
2330
task wb_to_pci_error_handling ;
2331
    reg   [11:0] ctrl_offset ;
2332
    reg   [11:0] ba_offset ;
2333
    reg   [11:0] am_offset ;
2334
    reg   [11:0] ta_offset ;
2335
    reg   [11:0] err_cs_offset ;
2336
    reg `WRITE_STIM_TYPE write_data ;
2337
    reg `READ_STIM_TYPE  read_data ;
2338
    reg `READ_RETURN_TYPE read_status ;
2339
 
2340
    reg `WRITE_RETURN_TYPE write_status ;
2341
    reg `WB_TRANSFER_FLAGS write_flags ;
2342
    reg [31:0] temp_val1 ;
2343
    reg [31:0] temp_val2 ;
2344
    reg        ok   ;
2345
    reg [11:0] pci_ctrl_offset ;
2346
    reg [31:0] image_base ;
2347
    reg [31:0] target_address ;
2348
    integer    num_of_trans ;
2349
    integer    current ;
2350
    integer    i ;
2351
begin:main
2352
 
2353
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2354
 
2355
    pci_ctrl_offset = 12'h4 ;
2356
 
2357
    // disable error interrupts and disable error reporting
2358
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2359
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2360
    if ( ok !== 1 )
2361
    begin
2362
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2363
        test_fail("PCI Device Control register couldn't be written") ;
2364
        disable main ;
2365
    end
2366
 
2367
    // image 1 is used for error testing, since it is always implemented
2368
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2369
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2370
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2371
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2372
 
2373
    // set master abort testing address to address that goes out of target's range
2374
    target_address  = `BEH_TAR1_MEM_START ;
2375
    image_base      = 0 ;
2376
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2377
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2378
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2379
 
2380
    write_flags                    = 0 ;
2381
    write_flags`INIT_WAITS         = tb_init_waits ;
2382
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2383
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2384
 
2385
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2386
 
2387
    // enable master & target operation
2388
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2389
    if ( ok !== 1 )
2390
    begin
2391
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2392
        test_fail("PCI Device Control register couldn't be written") ;
2393
        disable main ;
2394
    end
2395
 
2396
    // prepare image control register
2397
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2398
    if ( ok !== 1 )
2399
    begin
2400
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2401
        test_fail("WB Image Control register couldn't be written") ;
2402
        disable main ;
2403
    end
2404
 
2405
    // prepare base address register
2406
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2407
    if ( ok !== 1 )
2408
    begin
2409
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2410
        test_fail("WB Image Base Address register couldn't be written") ;
2411
        disable main ;
2412
    end
2413
 
2414
    // write address mask register
2415
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2416
    if ( ok !== 1 )
2417
    begin
2418
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2419
        test_fail("WB Image Address Mask register couldn't be written") ;
2420
        disable main ;
2421
    end
2422
 
2423
    // disable error reporting
2424
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2425
    if ( ~ok )
2426
    begin
2427
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2428
        test_fail("WB Error Control and Status register couldn't be written") ;
2429
        disable main ;
2430
    end
2431
 
2432
    // perform two writes - one to error address and one to OK address
2433
    // prepare write buffer
2434
 
2435
    write_data`WRITE_ADDRESS = target_address ;
2436
    write_data`WRITE_DATA    = wmem_data[100] ;
2437
    write_data`WRITE_SEL     = 4'hF ;
2438
 
2439
    wishbone_master.blk_write_data[0] = write_data ;
2440
 
2441
    write_flags`WB_TRANSFER_SIZE = 2 ;
2442
 
2443
    // don't handle retries
2444
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2445
    write_flags`WB_TRANSFER_CAB    = 0 ;
2446
 
2447
    $display("Introducing master abort error on single WB to PCI write!") ;
2448
 
2449
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2450
    // first disable target 1
2451
 
2452 45 mihad
    configuration_cycle_write(0,                        // bus number
2453
                              `TAR1_IDSEL_INDEX - 11,   // device number
2454
                              0,                        // function number
2455
                              1,                        // register number
2456
                              0,                        // type of configuration cycle
2457
                              4'b0001,                  // byte enables
2458
                              32'h0000_0000             // data
2459 15 mihad
                             ) ;
2460
 
2461
    fork
2462
    begin
2463
        // start no response monitor in parallel with writes
2464
        musnt_respond(ok) ;
2465
        if ( ok !== 1 )
2466
        begin
2467
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2468
            $display("Testbench is configured wrong!") ;
2469
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2470
        end
2471
        else
2472
            test_ok ;
2473
    end
2474
    begin
2475
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2476
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2477
       begin
2478
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2479
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2480
           test_fail("WB Slave state machine failed to post single memory write");
2481
           disable main ;
2482
       end
2483
    end
2484
    join
2485
 
2486
    /*// read data from second write
2487
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2488
    read_data`READ_ADDRESS = target_address ;
2489
    read_data`READ_SEL     = 4'hF ;
2490
    read_data`READ_TAG_STIM = 0 ;
2491
 
2492
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2493
 
2494
    if ( read_status`READ_DATA !== wmem_data[101] )
2495
    begin
2496
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2497
    end
2498
    */
2499
 
2500
    // read error status register - no errors should be reported since reporting was disabled
2501
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2502
 
2503
    @(posedge pci_clock) ;
2504
    // wait for two WB clocks for synchronization to be finished
2505
    repeat (2)
2506
        @(posedge wb_clock) ;
2507
 
2508
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2509
    if ( temp_val1[8] !== 0 )
2510
    begin
2511
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2512
        $display("Error reporting was disabled, but error was reported anyway!") ;
2513
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2514
        disable main ;
2515
    end
2516
    test_ok ;
2517
 
2518
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2519
    // check for interrupts - there should be no interrupt requests active
2520
    `ifdef HOST
2521
        repeat(4)
2522
            @(posedge wb_clock) ;
2523
 
2524
        if ( INT_O !== 0 )
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 WISHBONE bus!") ;
2528
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2529
        end
2530
        else
2531
            test_ok ;
2532
    `else
2533
    `ifdef GUEST
2534
        repeat( 4 )
2535
            @(posedge pci_clock) ;
2536
 
2537
        if ( INTA !== 1 )
2538
        begin
2539
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2540
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2541
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2542
        end
2543
        else
2544
            test_ok ;
2545
    `endif
2546
    `endif
2547
 
2548
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2549
    // check PCI status register
2550
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2551
    if ( temp_val1[29] !== 1 )
2552
    begin
2553
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2554
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2555
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2556
    end
2557
    else
2558
        test_ok ;
2559
 
2560
    // clear
2561
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2562
 
2563
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2564
 
2565
    $display("Introducing master abort error to CAB write!") ;
2566
    // now enable error reporting mechanism
2567
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2568
    // enable error interrupts
2569
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2570
 
2571
    // configure flags for CAB transfer
2572
    write_flags`WB_TRANSFER_CAB = 1 ;
2573
    write_flags`WB_TRANSFER_SIZE = 3 ;
2574
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2575
 
2576
    // prepare data for erroneous write
2577
    for ( i = 0 ; i < 3 ; i = i + 1 )
2578
    begin
2579
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2580
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2581
        write_data`WRITE_SEL     = 4'hF ;
2582
        wishbone_master.blk_write_data[i] = write_data ;
2583
    end
2584
 
2585
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2586
    fork
2587
    begin
2588
        wishbone_master.wb_block_write(write_flags, write_status) ;
2589
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2590
        begin
2591
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2592
            $display("Complete burst write through WB slave didn't succeed!") ;
2593
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2594
            disable main ;
2595
        end
2596
    end
2597
    begin
2598
        musnt_respond(ok) ;
2599
        if ( ok !== 1 )
2600
        begin
2601
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2602
            $display("Testbench is configured wrong!") ;
2603
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2604
        end
2605
        else
2606
            test_ok ;
2607
    end
2608
    join
2609
 
2610
    // check error status address, data, byte enables and bus command
2611
    // error status bit is signalled on PCI clock and synchronized to WB clock
2612
    // wait one PCI clock cycle
2613
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2614
    ok = 1 ;
2615
    @(posedge pci_clock) ;
2616
 
2617
    // wait for two WB clocks for synchronization to be finished
2618
    repeat (2)
2619
        @(posedge wb_clock) ;
2620
 
2621
    // read registers
2622
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2623
    if ( temp_val1[8] !== 1 )
2624
    begin
2625
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2626
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2627
        ok = 0 ;
2628
    end
2629
 
2630
    if ( temp_val1[9] !== 1 )
2631
    begin
2632
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2633
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2634
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2635
        ok = 0 ;
2636
    end
2637
 
2638
    if ( temp_val1[31:28] !== 0 )
2639
    begin
2640
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2641
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2642
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2643
        ok = 0 ;
2644
    end
2645
 
2646
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2647
    begin
2648
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2649
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2650
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2651
        ok = 0 ;
2652
    end
2653
 
2654
    // read error address register
2655
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2656
    if ( temp_val1 !== target_address )
2657
    begin
2658
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2659
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2660
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2661
        ok = 0 ;
2662
    end
2663
 
2664
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2665
    if ( temp_val1 !== wmem_data[110] )
2666
    begin
2667
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2668
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2669
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2670
        ok = 0 ;
2671
    end
2672
 
2673
    // check PCI status register
2674
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2675
    if ( temp_val1[29] !== 1 )
2676
    begin
2677
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2678
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2679
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2680
        ok = 0 ;
2681
    end
2682
 
2683
    if ( temp_val1[28] !== 0 )
2684
    begin
2685
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2686
        $display("Received Target Abort bit was set for no reason!") ;
2687
        test_fail("Received Target Abort bit was set for no reason") ;
2688
        ok = 0 ;
2689
    end
2690
 
2691
    if ( ok )
2692
        test_ok ;
2693
 
2694
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2695
 
2696
    // clear error status bit
2697
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2698
 
2699
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2700
 
2701
    ok = 1 ;
2702
 
2703
    `ifdef HOST
2704
        repeat(4)
2705
        @(posedge wb_clock) ;
2706
        if ( INT_O !== 1 )
2707
        begin
2708
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2709
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2710
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2711
            ok = 0 ;
2712
        end
2713
    `else
2714
    `ifdef GUEST
2715
        repeat(4)
2716
        @(posedge pci_clock) ;
2717
        if ( INTA !== 0 )
2718
        begin
2719
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2720
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2721
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2722
            ok = 0 ;
2723
        end
2724
    `endif
2725
    `endif
2726
 
2727
    // read interrupt status register
2728
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2729
    if ( temp_val1 !== 32'h0000_0002 )
2730
    begin
2731
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2732
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2733
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2734
        test_fail("Interrupt Status register returned wrong value") ;
2735
        ok = 0 ;
2736
    end
2737
 
2738
    if ( ok )
2739
        test_ok ;
2740
    // clear interrupt status bits
2741
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2742
 
2743
    ok = 1 ;
2744
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2745
    // wait for two clock cycles before checking interrupt request deassertion
2746
    `ifdef HOST
2747
        repeat (4)
2748
            @(posedge wb_clock) ;
2749
 
2750
        if ( INT_O !== 0 )
2751
        begin
2752
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2753
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2754
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2755
            ok = 0 ;
2756
        end
2757
    `else
2758
    `ifdef GUEST
2759
        repeat (4)
2760
            @(posedge pci_clock) ;
2761
 
2762
        if ( INTA !== 1 )
2763
        begin
2764
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2765
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2766
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2767
            ok = 0 ;
2768
        end
2769
    `endif
2770
    `endif
2771
 
2772
    if ( ok )
2773
        test_ok ;
2774
 
2775
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2776
    ok = 1 ;
2777
    // enable target
2778 45 mihad
    configuration_cycle_write(0,                        // bus number
2779
                              `TAR1_IDSEL_INDEX - 11,   // device number
2780
                              0,                        // function number
2781
                              1,                        // register number
2782
                              0,                        // type of configuration cycle
2783
                              4'b0001,                  // byte enables
2784
                              32'h0000_0007             // data
2785 15 mihad
                             ) ;
2786
    // prepare data for ok write
2787
    for ( i = 0 ; i < 3 ; i = i + 1 )
2788
    begin
2789
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2790
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2791
        write_data`WRITE_SEL     = 4'hF ;
2792
        wishbone_master.blk_write_data[i] = write_data ;
2793
    end
2794
 
2795
    wishbone_master.wb_block_write(write_flags, write_status) ;
2796
 
2797
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2798
    begin
2799
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2800
        $display("Complete burst write through WB slave didn't succeed!") ;
2801
        test_fail("WB Slave state machine failed to post CAB write") ;
2802
        disable main ;
2803
    end
2804
 
2805
    // do a read
2806
    for ( i = 0 ; i < 3 ; i = i + 1 )
2807
    begin
2808
        read_data`READ_ADDRESS = target_address + 4*i ;
2809
        read_data`READ_SEL     = 4'hF ;
2810
        wishbone_master.blk_read_data_in[i] = read_data ;
2811
    end
2812
 
2813
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2814
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2815
    write_flags`WB_TRANSFER_CAB    = 1 ;
2816
 
2817
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2818
 
2819
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2820
    begin
2821
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2822
        $display("Complete burst read through WB slave didn't succeed!") ;
2823
        test_fail("Delayed CAB write was not processed as expected") ;
2824
        disable main ;
2825
    end
2826
 
2827
    for ( i = 0 ; i < 3 ; i = i + 1 )
2828
    begin
2829
        read_status = wishbone_master.blk_read_data_out[i] ;
2830
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2831
        begin
2832
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2833
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2834
        end
2835
    end
2836
 
2837
    $display("Introducing master abort error to single read!") ;
2838
    // disable target
2839 45 mihad
    configuration_cycle_write(0,                        // bus number
2840
                              `TAR1_IDSEL_INDEX - 11,   // device number
2841
                              0,                        // function number
2842
                              1,                        // register number
2843
                              0,                        // type of configuration cycle
2844
                              4'b0001,                  // byte enables
2845
                              32'h0000_0000             // data
2846 15 mihad
                             ) ;
2847
    // set read data
2848
    read_data`READ_ADDRESS = target_address ;
2849
    read_data`READ_SEL     = 4'hF ;
2850
 
2851
    // enable automatic retry handling
2852
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2853
    write_flags`WB_TRANSFER_CAB    = 0 ;
2854
 
2855
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2856
    fork
2857
    begin
2858
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2859
    end
2860
    begin
2861
        musnt_respond(ok) ;
2862
        if ( ok !== 1 )
2863
        begin
2864
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2865
            $display("Testbench is configured wrong!") ;
2866
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2867
        end
2868
    end
2869
    join
2870
 
2871
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2872
    begin
2873
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2874
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2875
        $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) ;
2876
        test_fail("read didn't finish on WB bus as expected") ;
2877
        disable main ;
2878
    end
2879
 
2880
    test_ok ;
2881
 
2882
 
2883
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2884
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2885
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2886
    if ( temp_val1[8] !== 0 )
2887
    begin
2888
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2889
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2890
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2891
    end
2892
    else
2893
        test_ok ;
2894
 
2895
    // now check normal read operation
2896 45 mihad
    configuration_cycle_write(0,                        // bus number
2897
                              `TAR1_IDSEL_INDEX - 11,   // device number
2898
                              0,                        // function number
2899
                              1,                        // register number
2900
                              0,                        // type of configuration cycle
2901
                              4'b0001,                  // byte enables
2902
                              32'h0000_0007             // data
2903 15 mihad
                             ) ;
2904
 
2905 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
2906 15 mihad
    read_data`READ_ADDRESS = target_address ;
2907
    read_data`READ_SEL     = 4'hF ;
2908
 
2909
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2910
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2911
    begin
2912
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2913
        $display("WB slave failed to process single read!") ;
2914
        $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) ;
2915
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2916
        disable main ;
2917
    end
2918
 
2919
    if ( read_status`READ_DATA !== wmem_data[113] )
2920
    begin
2921
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2922
        test_fail("when read finished on WB bus, wrong data was provided") ;
2923
    end
2924
    else
2925
        test_ok ;
2926
 
2927
    // check PCI status register
2928 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
2929 15 mihad
    ok = 1 ;
2930
 
2931
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2932
    if ( temp_val1[29] !== 1 )
2933
    begin
2934
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2935
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2936
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2937
        ok = 0 ;
2938
    end
2939
 
2940
    if ( temp_val1[28] !== 0 )
2941
    begin
2942
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2943
        $display("Received Target Abort bit was set for no reason!") ;
2944
        test_fail("Received Target Abort bit was set for no reason") ;
2945
        ok = 0 ;
2946
    end
2947
    if ( ok )
2948
        test_ok ;
2949
 
2950
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2951
 
2952
    $display("Introducing master abort error to CAB read!") ;
2953
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
2954
 
2955 45 mihad
    configuration_cycle_write(0,                        // bus number
2956
                              `TAR1_IDSEL_INDEX - 11,   // device number
2957
                              0,                        // function number
2958
                              1,                        // register number
2959
                              0,                        // type of configuration cycle
2960
                              4'b0001,                  // byte enables
2961
                              32'h0000_0000             // data
2962 15 mihad
                             ) ;
2963
 
2964
    for ( i = 0 ; i < 3 ; i = i + 1 )
2965
    begin
2966
        read_data`READ_ADDRESS = target_address + 4*i ;
2967
        read_data`READ_SEL     = 4'hF ;
2968
        wishbone_master.blk_read_data_in[i] = read_data ;
2969
    end
2970
 
2971
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2972
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2973
    write_flags`WB_TRANSFER_CAB    = 1 ;
2974
 
2975
    fork
2976
    begin
2977
        wishbone_master.wb_block_read( write_flags, read_status ) ;
2978
    end
2979
    begin
2980
        musnt_respond(ok) ;
2981
        if ( ok !== 1 )
2982
        begin
2983
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2984
            $display("Testbench is configured wrong!") ;
2985
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2986
        end
2987
    end
2988
    join
2989
 
2990
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2991
    begin
2992
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2993
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2994
        $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) ;
2995
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
2996
        disable main ;
2997
    end
2998
    else
2999
        test_ok ;
3000
 
3001
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3002
    ok = 1 ;
3003
    // check PCI status register
3004
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3005
    if ( temp_val1[29] !== 1 )
3006
    begin
3007
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3008
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3009
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3010
        ok = 0 ;
3011
    end
3012
 
3013
    if ( temp_val1[28] !== 0 )
3014
    begin
3015
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3016
        $display("Received Target Abort bit was set for no reason!") ;
3017
        test_fail("Received Target Abort bit was set for no reason") ;
3018
        ok = 0 ;
3019
    end
3020
 
3021
    if ( ok )
3022
        test_ok ;
3023
 
3024
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3025
 
3026
    $display("Introducing target abort termination to single write!") ;
3027
 
3028
    // disable error reporting and interrupts
3029
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3030
 
3031 45 mihad
    configuration_cycle_write(0,                        // bus number
3032
                              `TAR1_IDSEL_INDEX - 11,   // device number
3033
                              0,                        // function number
3034
                              1,                        // register number
3035
                              0,                        // type of configuration cycle
3036
                              4'b0001,                  // byte enables
3037
                              32'h0000_0007             // data
3038 15 mihad
                             ) ;
3039
 
3040
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3041
    if ( ok !== 1 )
3042
    begin
3043
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3044
        test_fail("WB Error Control and Status register couldn't be written to") ;
3045
        disable main ;
3046
    end
3047
 
3048
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3049
    if ( ok !== 1 )
3050
    begin
3051
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3052
        test_fail("Interrupt Control register couldn't be written to") ;
3053
        disable main ;
3054
    end
3055
 
3056
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3057
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3058
 
3059
    write_data`WRITE_ADDRESS = target_address ;
3060
    write_data`WRITE_DATA    = wmem_data[0] ;
3061
    write_data`WRITE_SEL     = 4'hF ;
3062
 
3063
    wishbone_master.blk_write_data[0] = write_data ;
3064
 
3065
    write_data`WRITE_ADDRESS = target_address + 4;
3066
    write_data`WRITE_DATA    = wmem_data[1] ;
3067
    write_data`WRITE_SEL     = 4'hF ;
3068
 
3069
    wishbone_master.blk_write_data[1] = write_data ;
3070
 
3071
    write_flags`WB_TRANSFER_SIZE = 2 ;
3072
 
3073
    // don't handle retries
3074
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3075
    write_flags`WB_TRANSFER_CAB    = 0 ;
3076
 
3077
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3078
    fork
3079
    begin
3080
        wishbone_master.wb_block_write(write_flags, write_status) ;
3081
 
3082
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3083
        begin
3084
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3085
            $display("Image writes were not accepted as expected!") ;
3086
            $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) ;
3087
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3088
            disable main ;
3089
        end
3090
 
3091
        // read data back to see, if it was written OK
3092
        read_data`READ_ADDRESS         = target_address + 4;
3093
        read_data`READ_SEL             = 4'hF ;
3094
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3095
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3096
    end
3097
    begin
3098
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3099
        if ( ok !== 1 )
3100
        begin
3101
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3102
        end
3103
        else
3104
            test_ok ;
3105
 
3106
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3107
 
3108
        // when first transaction finishes - enable normal target response!
3109
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3110
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3111
 
3112
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3113
        if ( ok !== 1 )
3114
        begin
3115
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3116
        end
3117
        else
3118
            test_ok ;
3119
 
3120
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3121
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3122
        if ( ok !== 1 )
3123
        begin
3124
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3125
        end
3126
    end
3127
    join
3128
 
3129
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3130
    begin
3131
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3132
        $display("Bridge failed to process single read after target abort terminated write!") ;
3133
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3134
        disable main ;
3135
    end
3136
 
3137
    if ( read_status`READ_DATA !== wmem_data[1] )
3138
    begin
3139
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3140
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3141
    end
3142
    else
3143
        test_ok ;
3144
 
3145
    // check interrupt and error statuses!
3146
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3147
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3148
    if ( temp_val1[8] !== 0 )
3149
    begin
3150
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3151
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3152
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3153
    end
3154
    else
3155
        test_ok ;
3156
 
3157
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3158
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3159
    if ( temp_val1[1] !== 0 )
3160
    begin
3161
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3162
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3163
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3164
    end
3165
    else
3166
        test_ok ;
3167
 
3168
    // check PCI status register
3169
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3170
    ok = 1 ;
3171
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3172
    if ( temp_val1[29] !== 0 )
3173
    begin
3174
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3175
        $display("Received Master Abort bit was set with no reason!") ;
3176
        test_fail("Received Master Abort bit was set with no reason") ;
3177
        ok = 0 ;
3178
    end
3179
 
3180
    if ( temp_val1[28] !== 1 )
3181
    begin
3182
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3183
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3184
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3185
        ok = 0 ;
3186
    end
3187
 
3188
    if ( ok )
3189
        test_ok ;
3190
 
3191
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3192
 
3193
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3194
 
3195
    $display("Introducing target abort termination to CAB write!") ;
3196
    // enable error reporting mechanism
3197
 
3198
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3199
    if ( ok !== 1 )
3200
    begin
3201
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3202
        test_fail("WB Error Control and Status register could not be written to") ;
3203
        disable main ;
3204
    end
3205
 
3206
    for ( i = 0 ; i < 3 ; i = i + 1 )
3207
    begin
3208
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3209
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3210
        write_data`WRITE_SEL     = 4'b1010 ;
3211
        wishbone_master.blk_write_data[i] = write_data ;
3212
    end
3213
 
3214
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3215
    write_flags`WB_TRANSFER_CAB    = 1 ;
3216
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3217
 
3218
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3219
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3220
 
3221
    fork
3222
    begin
3223
        wishbone_master.wb_block_write(write_flags, write_status) ;
3224
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3225
        begin
3226
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3227
            $display("Bridge failed to process complete CAB write!") ;
3228
            test_fail("bridge failed to post CAB Memory Write") ;
3229
            disable main ;
3230
        end
3231
    end
3232
    begin
3233
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3234
        if ( ok !== 1 )
3235
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3236
        else
3237
            test_ok ;
3238
    end
3239
    join
3240
 
3241
    // check statuses and data from error
3242
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3243
    ok = 1 ;
3244
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3245
    if ( temp_val1[8] !== 1 )
3246
    begin
3247
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3248
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3249
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3250
        ok = 0 ;
3251
    end
3252
 
3253
    if ( temp_val1[9] !== 0 )
3254
    begin
3255
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3256
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3257
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3258
        ok = 0 ;
3259
    end
3260
 
3261
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3262
    begin
3263
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3264
        $display("Value in W_ERR_CS register was wrong!") ;
3265
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3266
        test_fail("BE Field didn't provided expected value") ;
3267
        ok = 0 ;
3268
    end
3269
 
3270
    if ( ok )
3271
        test_ok ;
3272
 
3273
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3274
    ok = 1 ;
3275
    // check erroneous address and data
3276
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3277
    if ( temp_val1 !== (target_address + 8) )
3278
    begin
3279
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3280
        $display("Value in W_ERR_ADDR register was wrong!") ;
3281
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3282
        test_fail("Value in WB Erroneous Address register was wrong") ;
3283
        ok = 0 ;
3284
    end
3285
 
3286
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3287
    if ( temp_val1 !== wmem_data[120] )
3288
    begin
3289
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3290
        $display("Value in W_ERR_DATA register was wrong!") ;
3291
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3292
        test_fail("Value in WB Erroneous Data register was wrong") ;
3293
        ok = 0 ;
3294
    end
3295
 
3296
    if ( ok )
3297
        test_ok ;
3298
 
3299
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3300
    ok = 1 ;
3301
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3302
    if ( temp_val1[29] !== 0 )
3303
    begin
3304
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3305
        $display("Received Master Abort bit was set with no reason!") ;
3306
        test_fail("Received Master Abort bit was set for no reason") ;
3307
        ok = 0 ;
3308
    end
3309
 
3310
    if ( temp_val1[28] !== 1 )
3311
    begin
3312
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3313
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3314
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3315
        ok = 0 ;
3316
    end
3317
 
3318
    if ( ok )
3319
        test_ok ;
3320
 
3321
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3322
 
3323
    // clear error status bit and enable error interrupts
3324
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3325
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3326
 
3327
    // check if error bit was cleared
3328
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3329
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3330
    if ( temp_val1[8] !== 0 )
3331
    begin
3332
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3333
        $display("Error bit was not cleared even though one was written to its location!") ;
3334
        test_fail("Error bit was not cleared even though one was written to its location") ;
3335
    end
3336
 
3337
    // repeat same write with different target configuration
3338
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3339
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3340
 
3341
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3342
    fork
3343
    begin
3344
        write_flags`WB_TRANSFER_SIZE = 2 ;
3345
        wishbone_master.wb_block_write(write_flags, write_status) ;
3346
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3347
        begin
3348
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3349
            $display("Bridge failed to process complete CAB write!") ;
3350
            test_fail("bridge failed to post CAB Memory Write") ;
3351
            disable main ;
3352
        end
3353
 
3354
        write_flags`WB_TRANSFER_SIZE = 3 ;
3355
        wishbone_master.wb_block_write(write_flags, write_status) ;
3356
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3357
        begin
3358
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3359
            $display("Bridge failed to process complete CAB write!") ;
3360
            test_fail("bridge failed to post CAB Memory Write") ;
3361
            disable main ;
3362
        end
3363
    end
3364
    begin
3365
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3366
        if ( ok !== 1 )
3367
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3368
        else
3369
        begin
3370
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3371
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3372
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3373
            if ( ok !== 1 )
3374
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3375
            else
3376
                test_ok ;
3377
        end
3378
    end
3379
    join
3380
 
3381
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3382
    ok = 1 ;
3383
    // check statuses and data from error
3384
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3385
    if ( temp_val1[8] !== 1 )
3386
    begin
3387
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3388
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3389
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3390
        ok = 0 ;
3391
    end
3392
 
3393
    if ( temp_val1[9] !== 0 )
3394
    begin
3395
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3396
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3397
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3398
        ok = 0 ;
3399
    end
3400
 
3401
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3402
    begin
3403
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3404
        $display("Value in W_ERR_CS register was wrong!") ;
3405
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3406
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3407
        ok = 0 ;
3408
    end
3409
 
3410
    if ( ok )
3411
        test_ok ;
3412
 
3413
    // check erroneous address and data
3414
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3415
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3416
    ok = 1 ;
3417
    if ( temp_val1 !== (target_address + 8 + 4) )
3418
    begin
3419
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3420
        $display("Value in W_ERR_ADDR register was wrong!") ;
3421
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3422
        test_fail("Value in WB Erroneous Address register was wrong") ;
3423
        ok = 0 ;
3424
 
3425
    end
3426
 
3427
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3428
    if ( temp_val1 !== wmem_data[121] )
3429
    begin
3430
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3431
        $display("Value in W_ERR_DATA register was wrong!") ;
3432
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3433
        test_fail("Value in WB Erroneous Data register was wrong") ;
3434
        ok = 0 ;
3435
    end
3436
 
3437
    if ( ok )
3438
        test_ok ;
3439
 
3440
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3441
    `ifdef HOST
3442
        repeat(4)
3443
            @(posedge wb_clock) ;
3444
        if ( INT_O !== 1 )
3445
        begin
3446
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3447
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3448
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3449
        end
3450
        else
3451
            test_ok ;
3452
    `else
3453
    `ifdef GUEST
3454
        repeat(4)
3455
            @(posedge pci_clock) ;
3456
        if ( INTA !== 0 )
3457
        begin
3458
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3459
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3460
            test_fail("interrupt request was not presented on PCI bus") ;
3461
        end
3462
        else
3463
            test_ok ;
3464
    `endif
3465
    `endif
3466
 
3467
    // read interrupt status register
3468
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3469
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3470
    if ( temp_val1[1] !== 1 )
3471
    begin
3472
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3473
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3474
        test_fail("Expected Interrupt status bit wasn't set") ;
3475
    end
3476
 
3477
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3478
 
3479
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3480
    ok = 1 ;
3481
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3482
    if ( temp_val1[29] !== 0 )
3483
    begin
3484
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3485
        $display("Received Master Abort bit was set with no reason!") ;
3486
        test_fail("Received Master Abort bit was set with no reason") ;
3487
        ok = 0 ;
3488
    end
3489
 
3490
    if ( temp_val1[28] !== 1 )
3491
    begin
3492
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3493
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3494
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3495
        ok = 0 ;
3496
    end
3497
 
3498
    if ( ok )
3499
        test_ok ;
3500
 
3501
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3502
 
3503
    // clear interrupts and errors
3504
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3505
    repeat( 3 )
3506
        @(posedge pci_clock) ;
3507
 
3508
    repeat( 2 )
3509
        @(posedge wb_clock) ;
3510
 
3511
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3512
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3513
    if ( temp_val1[1] !== 0 )
3514
    begin
3515
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3516
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3517
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3518
    end
3519
    else
3520
        test_ok ;
3521
 
3522
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3523
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3524
    if ( temp_val1[8] !== 0 )
3525
    begin
3526
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3527
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3528
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3529
    end
3530
 
3531
 
3532
    $display("Introducing Target Abort error to single read!") ;
3533
    // set read data
3534
    read_data`READ_ADDRESS = target_address + 8 ;
3535
    read_data`READ_SEL     = 4'hF ;
3536
 
3537
    // enable automatic retry handling
3538
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3539
    write_flags`WB_TRANSFER_CAB    = 0 ;
3540
 
3541
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3542
 
3543
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3544
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3545
 
3546
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3547
 
3548
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3549
    begin
3550
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3551
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3552
        $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) ;
3553
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3554
        disable main ;
3555
    end
3556
    else
3557
        test_ok ;
3558
 
3559
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3560
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3561
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3562
    if ( temp_val1[8] !== 0 )
3563
    begin
3564
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3565
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3566
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3567
    end
3568
    else
3569
        test_ok ;
3570
 
3571
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3572
    ok = 1 ;
3573
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3574
    if ( temp_val1[29] !== 0 )
3575
    begin
3576
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3577
        $display("Received Master Abort bit was set with no reason!") ;
3578
        test_fail("Received Master Abort bit was set with no reason") ;
3579
        ok = 0 ;
3580
    end
3581
 
3582
    if ( temp_val1[28] !== 1 )
3583
    begin
3584
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3585
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3586
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3587
        ok = 0 ;
3588
    end
3589
 
3590
    if ( ok )
3591
        test_ok ;
3592
 
3593
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3594
 
3595
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3596
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3597
    if ( temp_val1[1] !== 0 )
3598
    begin
3599
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3600
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3601
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3602
    end
3603
    else
3604
        test_ok ;
3605
 
3606
    $display("Introducing Target Abort error to CAB read!") ;
3607
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3608
 
3609
    for ( i = 0 ; i < 4 ; i = i + 1 )
3610
    begin
3611
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3612
        read_data`READ_SEL     = 4'b1010 ;
3613
        wishbone_master.blk_read_data_in[i] = read_data ;
3614
    end
3615
 
3616
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3617
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3618
    write_flags`WB_TRANSFER_CAB    = 1 ;
3619
 
3620
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3621
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3622
 
3623
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3624
 
3625
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3626
    begin
3627
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3628
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3629
        $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) ;
3630
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3631
        disable main ;
3632
    end
3633
 
3634
    read_status = wishbone_master.blk_read_data_out[0] ;
3635
    temp_val1 = read_status`READ_DATA ;
3636
    temp_val2 = wmem_data[120] ;
3637
 
3638
    // last write to this address was with only two byte enables - check only those
3639
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3640
    begin
3641
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3642
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3643
    end
3644
    else
3645
        test_ok ;
3646
 
3647
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3648
    ok = 1 ;
3649
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3650
    if ( temp_val1[29] !== 0 )
3651
    begin
3652
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3653
        $display("Received Master Abort bit was set with no reason!") ;
3654
        test_fail("Received Master Abort bit was set with no reason") ;
3655
        ok = 0 ;
3656
    end
3657
 
3658
    if ( temp_val1[28] !== 1 )
3659
    begin
3660
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3661
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3662
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3663
        ok = 0 ;
3664
    end
3665
 
3666
    if ( ok )
3667
       test_ok ;
3668
 
3669
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3670
 
3671
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3672
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3673
 
3674
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3675
    for ( i = 0 ; i < 3 ; i = i + 1 )
3676
    begin
3677
        read_data`READ_ADDRESS = target_address + 4*i ;
3678
        read_data`READ_SEL     = 4'b1111 ;
3679
        wishbone_master.blk_read_data_in[i] = read_data ;
3680
    end
3681
 
3682
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3683
 
3684
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3685
 
3686
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3687
    begin
3688
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3689
        $display("Complete burst read through WB slave didn't succeed!") ;
3690
        test_fail("bridge didn't process Burst Read in an expected way") ;
3691
        disable main ;
3692
    end
3693
    else
3694
        test_ok ;
3695
 
3696
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3697
 
3698
    for ( i = 0 ; i < 3 ; i = i + 1 )
3699
    begin
3700
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3701
        read_data`READ_SEL     = 4'b1111 ;
3702
        wishbone_master.blk_read_data_in[i] = read_data ;
3703
    end
3704
 
3705
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3706
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3707
    write_flags`WB_TRANSFER_CAB    = 1 ;
3708
 
3709
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3710
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3711
 
3712
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3713
 
3714
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3715
    begin
3716
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3717
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3718
        $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) ;
3719
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3720
        disable main ;
3721
    end
3722
 
3723
    for ( i = 0 ; i < 3 ; i = i + 1 )
3724
    begin
3725
        ok = 1 ;
3726
        read_status = wishbone_master.blk_read_data_out[i] ;
3727
        temp_val1 = read_status`READ_DATA ;
3728
        temp_val2 = wmem_data[120 + i] ;
3729
 
3730
        // last write to this address was with only two byte enables - check only those
3731
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3732
        begin
3733
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3734
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3735
            ok = 0 ;
3736
        end
3737
    end
3738
 
3739
    if ( ok )
3740
        test_ok ;
3741
 
3742
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3743
    ok = 1 ;
3744
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3745
    if ( temp_val1[29] !== 0 )
3746
    begin
3747
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3748
        $display("Received Master Abort bit was set with no reason!") ;
3749
        test_fail("Received Master Abort bit was set with no reason") ;
3750
        ok = 0 ;
3751
    end
3752
 
3753
    if ( temp_val1[28] !== 1 )
3754
    begin
3755
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3756
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3757
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3758
        ok = 0 ;
3759
    end
3760
 
3761
    if ( ok )
3762
       test_ok ;
3763
 
3764
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3765
 
3766
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3767
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3768
 
3769
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3770
    for ( i = 0 ; i < 3 ; i = i + 1 )
3771
    begin
3772
        read_data`READ_ADDRESS = target_address + 4*i ;
3773
        read_data`READ_SEL     = 4'b1111 ;
3774
        wishbone_master.blk_read_data_in[i] = read_data ;
3775
    end
3776
 
3777
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3778
 
3779
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3780
 
3781
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3782
    begin
3783
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3784
        $display("Complete burst read through WB slave didn't succeed!") ;
3785
        test_fail("bridge didn't process Burst Read in an expected way") ;
3786
        disable main ;
3787
    end
3788
    else
3789
        test_ok ;
3790
 
3791
    // test error on IO write
3792
    // change base address
3793
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3794
    write_data`WRITE_SEL     = 4'b0101 ;
3795
    write_data`WRITE_ADDRESS = target_address ;
3796
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3797
 
3798
    write_flags`WB_TRANSFER_CAB    = 0 ;
3799
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3800
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3801
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3802
    fork
3803
    begin
3804
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3805
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3806
        begin
3807
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3808
            $display("WB slave failed to accept IO write!") ;
3809
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3810
            disable main ;
3811
        end
3812
    end
3813
    begin
3814
        musnt_respond(ok) ;
3815
        if ( ok !== 1 )
3816
        begin
3817
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3818
            $display("Testbench is configured wrong!") ;
3819
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3820
        end
3821
        else
3822
            test_ok ;
3823
    end
3824
    join
3825
 
3826
    // check statuses and everything else
3827
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3828
    ok = 1 ;
3829
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3830
    if ( temp_val1[8] !== 1 )
3831
    begin
3832
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3833
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3834
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3835
        ok = 0 ;
3836
    end
3837
 
3838
    if ( temp_val1[9] !== 1 )
3839
    begin
3840
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3841
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3842
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3843
        ok = 0 ;
3844
    end
3845
 
3846
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3847
    begin
3848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3849
        $display("Value in W_ERR_CS register was wrong!") ;
3850
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3851
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3852
        ok = 0 ;
3853
    end
3854
 
3855
    if ( ok )
3856
        test_ok ;
3857
 
3858
    // check erroneous address and data
3859
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3860
    ok = 1 ;
3861
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3862
    if ( temp_val1 !== target_address )
3863
    begin
3864
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3865
        $display("Value in W_ERR_ADDR register was wrong!") ;
3866
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3867
        test_fail("WB Erroneous Address register didn't provide right value") ;
3868
        ok = 0 ;
3869
    end
3870
 
3871
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3872
    if ( temp_val1 !== 32'hAAAA_AAAA )
3873
    begin
3874
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3875
        $display("Value in W_ERR_DATA register was wrong!") ;
3876
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3877
        test_fail("WB Erroneous Data register didn't provide right value") ;
3878
        ok = 0 ;
3879
    end
3880
 
3881
    if ( ok )
3882
        test_ok ;
3883
 
3884
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3885
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3886
    if ( temp_val1[1] !== 1 )
3887
    begin
3888
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3889
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3890
        test_fail("expected interrupt status bit was not set") ;
3891
    end
3892
    else
3893
        test_ok ;
3894
 
3895
    // clear interrupts and errors
3896
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3897
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3898
 
3899
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3900
    ok = 1 ;
3901
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3902
    if ( temp_val1[29] !== 1 )
3903
    begin
3904
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3905
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3906
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3907
        ok = 0 ;
3908
    end
3909
 
3910
    if ( temp_val1[28] !== 0 )
3911
    begin
3912
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3913
        $display("Received Target Abort bit was set for no reason!") ;
3914
        test_fail("Received Target Abort bit was set for no reason") ;
3915
        ok = 0 ;
3916
    end
3917
 
3918
    if ( ok )
3919
        test_ok ;
3920
 
3921
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3922
 
3923
    // disable image
3924
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3925
    if ( ok !== 1 )
3926
    begin
3927
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3928
        test_fail("WB Image Address Mask register couldn't be written") ;
3929
        disable main ;
3930
    end
3931
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3932
 
3933
end
3934
endtask
3935
 
3936
task parity_checking ;
3937
    reg   [11:0] ctrl_offset ;
3938
    reg   [11:0] ba_offset ;
3939
    reg   [11:0] am_offset ;
3940
    reg   [11:0] ta_offset ;
3941
    reg `WRITE_STIM_TYPE write_data ;
3942
    reg `READ_STIM_TYPE  read_data ;
3943
    reg `READ_RETURN_TYPE read_status ;
3944
 
3945
    reg `WRITE_RETURN_TYPE write_status ;
3946
    reg `WB_TRANSFER_FLAGS write_flags ;
3947
    reg [31:0] temp_val1 ;
3948
    reg [31:0] temp_val2 ;
3949
    reg        ok   ;
3950
    reg [11:0] pci_ctrl_offset ;
3951
    reg [31:0] image_base ;
3952
    reg [31:0] target_address ;
3953
    reg [11:0] icr_offset ;
3954
    reg [11:0] isr_offset ;
3955
    reg [11:0] p_ba_offset ;
3956
    reg [11:0] p_am_offset ;
3957
    reg [11:0] p_ctrl_offset ;
3958
    integer    i ;
3959
    reg        perr_asserted ;
3960
begin:main
3961
    $display("******************************* Testing Parity Checker functions ********************************") ;
3962
    $display("Testing Parity Errors during Master Transactions!") ;
3963
    $display("Introducing Parity Erros to Master Writes!") ;
3964
    $fdisplay(pci_mon_log_file_desc,
3965
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
3966
 
3967
    // image 1 is used for error testing, since it is always implemented
3968
    pci_ctrl_offset = 12'h004 ;
3969
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
3970
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
3971
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
3972
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
3973
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
3974
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
3975
 
3976
    // image 1 for PCI target
3977
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
3978
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
3979
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
3980
 
3981
    target_address  = `BEH_TAR1_MEM_START ;
3982
    image_base      = 0 ;
3983
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
3984
 
3985
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
3986
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
3987
    write_flags                    = 0 ;
3988
    write_flags`INIT_WAITS         = tb_init_waits ;
3989
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
3990
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3991
 
3992
    // enable master & target operation and disable parity functions
3993
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
3994
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
3995
    if ( ok !== 1 )
3996
    begin
3997
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
3998
        test_fail("PCI Device Control register could not be written to") ;
3999
        disable main ;
4000
    end
4001
 
4002
    // prepare image control register
4003
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4004
    if ( ok !== 1 )
4005
    begin
4006
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4007
        test_fail("WB Image Control register could not be written to") ;
4008
        disable main ;
4009
    end
4010
 
4011
    // prepare base address register
4012
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4013
    if ( ok !== 1 )
4014
    begin
4015
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4016
        test_fail("WB Image Base Address register could not be written to") ;
4017
        disable main ;
4018
    end
4019
 
4020
    // write address mask register
4021
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4022
    if ( ok !== 1 )
4023
    begin
4024
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4025
        test_fail("WB Image Address Mask register could not be written to") ;
4026
        disable main ;
4027
    end
4028
 
4029
    // disable parity interrupts
4030
    config_write( icr_offset, 0, 4'hF, ok ) ;
4031
    if ( ok !== 1 )
4032
    begin
4033
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4034
        test_fail("Interrupt Control register could not be written to") ;
4035
        disable main ;
4036
    end
4037
 
4038
    write_data`WRITE_ADDRESS = target_address ;
4039
    write_data`WRITE_DATA    = wmem_data[0] ;
4040
    write_data`WRITE_SEL     = 4'b1111 ;
4041
 
4042
    // enable target's 1 response to parity errors
4043 45 mihad
    configuration_cycle_write(0,                        // bus number
4044
                              `TAR1_IDSEL_INDEX - 11,   // device number
4045
                              0,                        // function number
4046
                              1,                        // register number
4047
                              0,                        // type of configuration cycle
4048
                              4'b0001,                  // byte enables
4049
                              32'h0000_0047             // data
4050 15 mihad
                             ) ;
4051
 
4052
    // disable target's 2 response to parity errors
4053 45 mihad
    configuration_cycle_write(0,                        // bus number
4054
                              `TAR2_IDSEL_INDEX - 11,   // device number
4055
                              0,                        // function number
4056
                              1,                        // register number
4057
                              0,                        // type of configuration cycle
4058
                              4'b0001,                  // byte enables
4059
                              32'h0000_0007             // data
4060 15 mihad
                             ) ;
4061
 
4062
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4063
 
4064
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4065
    fork
4066
    begin
4067
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4068
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4069
        begin
4070
            $display("Parity checker testing failed! Time %t ", $time) ;
4071
            $display("Bridge failed to process single memory write!") ;
4072
            test_fail("bridge failed to post single WB memory write") ;
4073
            disable main ;
4074
        end
4075
    end
4076
    begin:wait_perr1
4077
        perr_asserted = 0 ;
4078
        @(posedge pci_clock) ;
4079
 
4080 35 mihad
        while ( PERR !== 0 )
4081 15 mihad
            @(posedge pci_clock) ;
4082
 
4083 35 mihad
        perr_asserted = 1 ;
4084 15 mihad
 
4085
    end
4086
    begin
4087
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4088
 
4089
        if ( ok !== 1 )
4090
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4091
 
4092 35 mihad
        repeat(2)
4093 15 mihad
            @(posedge pci_clock) ;
4094
 
4095 35 mihad
        #1 ;
4096
        if ( !perr_asserted )
4097
            disable wait_perr1 ;
4098 15 mihad
    end
4099
    join
4100
 
4101
    if ( perr_asserted && ok )
4102
    begin
4103
        test_ok ;
4104
    end
4105
    else
4106
    if ( ~perr_asserted )
4107
    begin
4108
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4109
        disable main ;
4110
    end
4111
 
4112
    // check all the statuses - if HOST is defined, wait for them to be synced
4113
    `ifdef HOST
4114
    repeat(4)
4115
        @(posedge wb_clock) ;
4116
    `endif
4117
 
4118
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4119
    ok = 1 ;
4120
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4121 45 mihad
    if ( temp_val1[31] !== 0 )
4122 15 mihad
    begin
4123
        $display("Parity checker testing failed! Time %t ", $time) ;
4124 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4125
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4126 15 mihad
        ok = 0 ;
4127
    end
4128
 
4129
    if ( temp_val1[30] !== 0 )
4130
    begin
4131
        $display("Parity checker testing failed! Time %t ", $time) ;
4132
        $display("Signalled System Error bit was set for no reason!") ;
4133
        test_fail("Signalled System Error bit was set for no reason") ;
4134
        ok = 0 ;
4135
    end
4136
 
4137
    if ( temp_val1[24] !== 0 )
4138
    begin
4139
        $display("Parity checker testing failed! Time %t ", $time) ;
4140
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4141
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4142
        ok = 0 ;
4143
    end
4144
 
4145
    if ( ok )
4146
        test_ok ;
4147
 
4148
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4149
    // clear parity bits and enable parity response
4150
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4151
    if ( ok !== 1 )
4152
    begin
4153
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4154
        test_fail("write to PCI Status Register failed") ;
4155
        disable main ;
4156
    end
4157
 
4158
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4159
    fork
4160
    begin
4161
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4162
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4163
        begin
4164
            $display("Parity checker testing failed! Time %t ", $time) ;
4165
            $display("Bridge failed to process single memory write!") ;
4166
            test_fail("bridge failed to post single memory write") ;
4167
            disable main ;
4168
        end
4169
    end
4170
    begin:wait_perr2
4171
        perr_asserted = 0 ;
4172
        @(posedge pci_clock) ;
4173
 
4174 35 mihad
        while ( PERR !== 0 )
4175 15 mihad
            @(posedge pci_clock) ;
4176
 
4177 35 mihad
        perr_asserted = 1 ;
4178 15 mihad
 
4179
    end
4180
    begin
4181
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4182
 
4183
        if ( ok !== 1 )
4184
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4185
 
4186 35 mihad
        repeat(2)
4187 15 mihad
            @(posedge pci_clock) ;
4188
 
4189 35 mihad
        #1 ;
4190
        if (!perr_asserted)
4191
            disable wait_perr2 ;
4192 15 mihad
    end
4193
    join
4194
 
4195
    if ( perr_asserted && ok )
4196
    begin
4197
        test_ok ;
4198
    end
4199
    else
4200
    if ( ~perr_asserted )
4201
    begin
4202
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4203
        disable main ;
4204
    end
4205
 
4206
    // check all the statuses - if HOST is defined, wait for them to be synced
4207
    `ifdef HOST
4208
    repeat(4)
4209
        @(posedge wb_clock) ;
4210
    `endif
4211
 
4212
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4213
    ok = 1 ;
4214
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4215 45 mihad
    if ( temp_val1[31] !== 0 )
4216 15 mihad
    begin
4217
        $display("Parity checker testing failed! Time %t ", $time) ;
4218 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4219
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4220 15 mihad
        ok = 0 ;
4221
    end
4222
 
4223
    if ( temp_val1[30] !== 0 )
4224
    begin
4225
        $display("Parity checker testing failed! Time %t ", $time) ;
4226
        $display("Signalled System Error bit was set for no reason!") ;
4227
        test_fail("Signalled System Error bit was set for no reason") ;
4228
        ok = 0 ;
4229
    end
4230
 
4231
    if ( temp_val1[24] !== 1 )
4232
    begin
4233
        $display("Parity checker testing failed! Time %t ", $time) ;
4234 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!") ;
4235
        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") ;
4236 15 mihad
        ok = 0 ;
4237
    end
4238
 
4239
    if ( ok )
4240
        test_ok ;
4241
 
4242
    // clear status bits and disable parity error response
4243
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4244
 
4245
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4246
 
4247
    // disable perr generation and perform a write - no bits should be set
4248
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4249
    fork
4250
    begin
4251
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4252
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4253
        begin
4254
            $display("Parity checker testing failed! Time %t ", $time) ;
4255
            $display("Bridge failed to process single memory write!") ;
4256
            test_fail("bridge failed to post single memory write") ;
4257
            disable main ;
4258
        end
4259
    end
4260
    begin
4261
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4262
 
4263
        if ( ok !== 1 )
4264
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4265
        else
4266
            test_ok ;
4267
 
4268
        repeat(3)
4269
            @(posedge pci_clock) ;
4270
    end
4271
    join
4272
 
4273
    `ifdef HOST
4274
    repeat(4)
4275
        @(posedge wb_clock) ;
4276
    `endif
4277
 
4278
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4279
    ok = 1 ;
4280
 
4281
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4282
    if ( temp_val1[31] !== 0 )
4283
    begin
4284
        $display("Parity checker testing failed! Time %t ", $time) ;
4285
        $display("Detected Parity Error bit was set for no reason!") ;
4286
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4287
        ok = 0 ;
4288
    end
4289
 
4290
    if ( temp_val1[30] !== 0 )
4291
    begin
4292
        $display("Parity checker testing failed! Time %t ", $time) ;
4293
        $display("Signalled System Error bit was set for no reason!") ;
4294
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4295
        ok = 0 ;
4296
    end
4297
 
4298
    if ( temp_val1[24] !== 0 )
4299
    begin
4300
        $display("Parity checker testing failed! Time %t ", $time) ;
4301
        $display("Master Data Parity Error bit was set for no reason!") ;
4302
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4303
        ok = 0 ;
4304
    end
4305
 
4306
    if ( ok )
4307
        test_ok ;
4308
 
4309
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4310
 
4311
    read_data = 0 ;
4312
    read_data`READ_ADDRESS  = target_address ;
4313
    read_data`READ_SEL      = 4'hF ;
4314
    read_data`READ_TAG_STIM = 0 ;
4315
 
4316
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4317
 
4318
    // enable parity and system error interrupts
4319
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4320
 
4321
    // enable parity error response
4322
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4323
 
4324
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4325
 
4326
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4327
    fork
4328
    begin
4329
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4330
    end
4331
    begin:wait_perr4
4332
        perr_asserted = 0 ;
4333
        @(posedge pci_clock) ;
4334 35 mihad
        while ( PERR !== 0 )
4335 15 mihad
            @(posedge pci_clock) ;
4336
 
4337 35 mihad
        perr_asserted = 1 ;
4338 15 mihad
 
4339
    end
4340
    begin
4341
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4342
 
4343
        if ( ok !== 1 )
4344
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4345
 
4346
        repeat(2)
4347
            @(posedge pci_clock) ;
4348
 
4349 35 mihad
        #1 ;
4350
        if ( !perr_asserted )
4351
            disable wait_perr4 ;
4352 15 mihad
    end
4353
    join
4354
 
4355
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4356
    begin
4357
        $display("Parity checker testing failed! Time %t ", $time) ;
4358
        $display("Bridge failed to process single memory read!") ;
4359
        test_fail("bridge didn't process single memory read correctly") ;
4360
        ok = 0 ;
4361
    end
4362
 
4363
    if ( perr_asserted && ok )
4364
    begin
4365
        test_ok ;
4366
    end
4367
    else
4368
    if ( ~perr_asserted )
4369
    begin
4370
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4371
        disable main ;
4372
    end
4373
 
4374
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4375
    // interrupt should also be present
4376
    `ifdef HOST
4377
        repeat(4)
4378 26 mihad
            @(posedge pci_clock) ;
4379
        repeat(4)
4380 15 mihad
            @(posedge wb_clock) ;
4381
 
4382
        if ( INT_O !== 1 )
4383
        begin
4384
            $display("Parity checker testing failed! Time %t ", $time) ;
4385
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4386
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4387
        end
4388
        else
4389
            test_ok ;
4390
    `else
4391
    `ifdef GUEST
4392 26 mihad
        repeat(4)
4393
            @(posedge wb_clock) ;
4394
        repeat(4)
4395 15 mihad
            @(posedge pci_clock) ;
4396
 
4397
        if ( INTA !== 1 )
4398
        begin
4399
            $display("Parity checker testing failed! Time %t ", $time) ;
4400
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4401
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4402
        end
4403
        else
4404
            test_ok ;
4405
    `endif
4406
    `endif
4407
 
4408
    // check statuses!
4409
 
4410
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4411
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4412
    ok = 1 ;
4413
 
4414
    if ( temp_val1[31] !== 1 )
4415
    begin
4416
        $display("Parity checker testing failed! Time %t ", $time) ;
4417 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4418
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4419 15 mihad
        ok = 0 ;
4420
    end
4421
 
4422
    if ( temp_val1[30] !== 0 )
4423
    begin
4424
        $display("Parity checker testing failed! Time %t ", $time) ;
4425
        $display("Signalled System Error bit was set for no reason!") ;
4426
        test_fail("Signalled System Error bit was set for no reason") ;
4427
        ok = 0 ;
4428
    end
4429
 
4430
    if ( temp_val1[24] !== 1 )
4431
    begin
4432
        $display("Parity checker testing failed! Time %t ", $time) ;
4433 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4434
        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") ;
4435 15 mihad
        ok = 0 ;
4436
    end
4437
 
4438
    if ( ok )
4439
        test_ok ;
4440
 
4441
    // clear statuses and disable parity error response
4442
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4443
 
4444
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4445
    ok = 1 ;
4446
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4447
 
4448
    if ( temp_val1[4] !== 0 )
4449
    begin
4450
        $display("Parity checker testing failed! Time %t ", $time) ;
4451
        $display("System error interrupt status bit set for no reason!") ;
4452
        test_fail("System error interrupt status bit set for no reason") ;
4453
        ok = 0 ;
4454
    end
4455
 
4456
    `ifdef HOST
4457
    if ( temp_val1[3] !== 1 )
4458
    begin
4459
        $display("Parity checker testing failed! Time %t ", $time) ;
4460
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4461
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4462
        ok = 0 ;
4463
    end
4464
    `else
4465
    if ( temp_val1[3] !== 0 )
4466
    begin
4467
        $display("Parity checker testing failed! Time %t ", $time) ;
4468
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4469
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4470
        ok = 0 ;
4471
    end
4472
    `endif
4473
 
4474
    if ( ok )
4475
        test_ok ;
4476
 
4477
    // clear int statuses
4478
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4479
 
4480
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4481
 
4482
    `ifdef HOST
4483
        repeat(4)
4484 26 mihad
            @(posedge pci_clock) ;
4485
        repeat(4)
4486 15 mihad
            @(posedge wb_clock) ;
4487
 
4488
        if ( INT_O !== 0 )
4489
        begin
4490
            $display("Parity checker testing failed! Time %t ", $time) ;
4491
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4492
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4493
        end
4494
        else
4495
            test_ok ;
4496
    `else
4497
    `ifdef GUEST
4498 26 mihad
        repeat(4)
4499
            @(posedge wb_clock) ;
4500
        repeat(4)
4501 15 mihad
            @(posedge pci_clock) ;
4502
 
4503
        if ( INTA !== 1 )
4504
        begin
4505
            $display("Parity checker testing failed! Time %t ", $time) ;
4506
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4507
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4508
        end
4509
        else
4510
            test_ok ;
4511
    `endif
4512
    `endif
4513
 
4514
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4515
 
4516
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4517
    fork
4518
    begin
4519
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4520
    end
4521
    begin:wait_perr5
4522
        perr_asserted = 0 ;
4523
        @(posedge pci_clock) ;
4524
        while ( PERR === 1 )
4525
            @(posedge pci_clock) ;
4526
 
4527
        perr_asserted = 1 ;
4528
        $display("Parity checker testing failed! Time %t ", $time) ;
4529 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4530
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4531 15 mihad
    end
4532
    begin
4533
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4534
        if ( ok !== 1 )
4535
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4536
 
4537
        // perr can be asserted on idle or next PCI address phase
4538
        repeat(2)
4539
            @(posedge pci_clock) ;
4540
 
4541 35 mihad
        #1 ;
4542
        if ( !perr_asserted )
4543
            disable wait_perr5 ;
4544 15 mihad
    end
4545
    join
4546
 
4547
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4548
    begin
4549
        $display("Parity checker testing failed! Time %t ", $time) ;
4550
        $display("Bridge failed to process single memory read!") ;
4551
        test_fail("bridge failed to process single memory read correctly") ;
4552
        ok = 0 ;
4553
    end
4554
 
4555
    if ( ok && !perr_asserted)
4556
        test_ok ;
4557
 
4558
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4559
 
4560
    // interrupts should not be present
4561
    `ifdef HOST
4562
        repeat( 4 )
4563 26 mihad
            @(posedge pci_clock) ;
4564
        repeat( 4 )
4565 15 mihad
            @(posedge wb_clock) ;
4566
        if ( INT_O !== 0 )
4567
        begin
4568
            $display("Parity checker testing failed! Time %t ", $time) ;
4569
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4570
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4571
        end
4572
        else
4573
            test_ok ;
4574
    `else
4575
    `ifdef GUEST
4576
        repeat( 4 )
4577 26 mihad
            @(posedge wb_clock) ;
4578
        repeat( 4 )
4579 15 mihad
            @(posedge pci_clock) ;
4580
        if ( INTA !== 1 )
4581
        begin
4582
            $display("Parity checker testing failed! Time %t ", $time) ;
4583
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4584
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4585
        end
4586
        else
4587
            test_ok ;
4588
    `endif
4589
    `endif
4590
 
4591
    // check statuses!
4592
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4593
    ok = 1 ;
4594
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4595
    if ( temp_val1[31] !== 1 )
4596
    begin
4597
        $display("Parity checker testing failed! Time %t ", $time) ;
4598 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4599 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4600
        ok = 0 ;
4601
    end
4602
 
4603
    if ( temp_val1[30] !== 0 )
4604
    begin
4605
        $display("Parity checker testing failed! Time %t ", $time) ;
4606
        $display("Signalled System Error bit was set for no reason!") ;
4607
        test_fail("Signalled System Error bit was set for no reason") ;
4608
        ok = 0 ;
4609
    end
4610
 
4611
    if ( temp_val1[24] !== 0 )
4612
    begin
4613
        $display("Parity checker testing failed! Time %t ", $time) ;
4614 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4615 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4616
        ok = 0 ;
4617
    end
4618
 
4619
    if ( ok )
4620
        test_ok ;
4621
 
4622
    // clear statuses
4623
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4624
 
4625
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4626
    ok = 1 ;
4627
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4628
 
4629
    if ( temp_val1[4] !== 0 )
4630
    begin
4631
        $display("Parity checker testing failed! Time %t ", $time) ;
4632
        $display("System error interrupt status bit set for no reason!") ;
4633
        test_fail("System error interrupt status bit set for no reason") ;
4634
        ok = 0 ;
4635
    end
4636
 
4637
    if ( temp_val1[3] !== 0 )
4638
    begin
4639
        $display("Parity checker testing failed! Time %t ", $time) ;
4640
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4641
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4642
        ok = 0 ;
4643
    end
4644
 
4645
    if ( ok )
4646
        test_ok ;
4647
 
4648
    // enable all responses to parity errors!
4649
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4650
 
4651
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4652
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4653
 
4654
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4655
 
4656
    // repeat a read
4657
    fork
4658
    begin
4659
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4660
    end
4661
    begin:wait_perr6
4662
        perr_asserted = 0 ;
4663
        @(posedge pci_clock) ;
4664
        while ( PERR === 1 )
4665
            @(posedge pci_clock) ;
4666
 
4667
        perr_asserted = 1 ;
4668
        $display("Parity checker testing failed! Time %t ", $time) ;
4669
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4670
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4671
    end
4672
    begin
4673
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4674
        if ( ok !== 1 )
4675
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4676
 
4677
        repeat(2)
4678
            @(posedge pci_clock) ;
4679
 
4680 35 mihad
        #1 ;
4681
        if ( !perr_asserted )
4682
            disable wait_perr6 ;
4683 15 mihad
    end
4684
    join
4685
 
4686
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4687
    begin
4688
        $display("Parity checker testing failed! Time %t ", $time) ;
4689
        $display("Bridge failed to process single memory read!") ;
4690
        test_fail("bridge didn't process single memory read as expected") ;
4691
        ok = 0 ;
4692
    end
4693
 
4694
    if ( ok && !perr_asserted)
4695
        test_ok ;
4696
 
4697
    // check statuses!
4698
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4699
    ok = 1 ;
4700
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4701
    if ( temp_val1[31] !== 0 )
4702
    begin
4703
        $display("Parity checker testing failed! Time %t ", $time) ;
4704
        $display("Detected Parity Error bit was set for no reason!") ;
4705
        test_fail("Detected Parity Error bit was set for no reason") ;
4706
        ok = 0 ;
4707
    end
4708
 
4709
    if ( temp_val1[30] !== 0 )
4710
    begin
4711
        $display("Parity checker testing failed! Time %t ", $time) ;
4712
        $display("Signalled System Error bit was set for no reason!") ;
4713
        test_fail("Signalled System Error bit was set for no reason") ;
4714
        ok = 0 ;
4715
    end
4716
 
4717
    if ( temp_val1[24] !== 0 )
4718
    begin
4719
        $display("Parity checker testing failed! Time %t ", $time) ;
4720
        $display("Master Data Parity Error bit was set for no reason!") ;
4721
        test_fail("Master Data Parity Error bit was set for no reason") ;
4722
        ok = 0 ;
4723
    end
4724
 
4725
    if ( ok )
4726
        test_ok ;
4727
 
4728
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4729
    ok = 1 ;
4730
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4731
 
4732
    if ( temp_val1[4] !== 0 )
4733
    begin
4734
        $display("Parity checker testing failed! Time %t ", $time) ;
4735
        $display("System error interrupt status bit set for no reason!") ;
4736
        test_fail("System error interrupt status bit set for no reason") ;
4737
        ok = 0 ;
4738
    end
4739
 
4740
    if ( temp_val1[3] !== 0 )
4741
    begin
4742
        $display("Parity checker testing failed! Time %t ", $time) ;
4743
        $display("Parity error interrupt status bit set for no reason!") ;
4744
        test_fail("Parity error interrupt status bit set for no reason") ;
4745
        ok = 0 ;
4746
    end
4747
 
4748
    if ( ok )
4749
        test_ok ;
4750
 
4751
    $display("Presenting address parity error on PCI bus!") ;
4752
    // enable parity errors - this should not affect system errors
4753
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4754
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4755
 
4756
    // perform PCI write
4757
    // check transaction progress
4758
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4759
    fork
4760
    begin
4761
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4762
               target_address, 32'h1234_5678,
4763
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4764
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4765
        do_pause( 1 ) ;
4766
    end
4767
    begin:wait_serr7
4768
        perr_asserted = 0 ;
4769
        @(posedge pci_clock) ;
4770
        while( SERR === 1 )
4771
            @(posedge pci_clock) ;
4772
 
4773
        perr_asserted = 1 ;
4774
        $display("Parity checker testing failed! Time %t ", $time) ;
4775
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4776
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4777
    end
4778
    begin
4779
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4780
        if ( ok !== 1 )
4781
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4782
 
4783 35 mihad
        if ( !perr_asserted )
4784
            disable wait_serr7 ;
4785 15 mihad
    end
4786
    join
4787
 
4788
    if ( ok && !perr_asserted)
4789
        test_ok ;
4790
 
4791
    // check statuses!
4792
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4793
    ok = 1 ;
4794
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4795
    if ( temp_val1[31] !== 1 )
4796
    begin
4797
        $display("Parity checker testing failed! Time %t ", $time) ;
4798
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4799
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4800
        ok = 0 ;
4801
    end
4802
 
4803
    if ( temp_val1[30] !== 0 )
4804
    begin
4805
        $display("Parity checker testing failed! Time %t ", $time) ;
4806
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4807
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4808
        ok = 0 ;
4809
    end
4810
 
4811
    if ( temp_val1[24] !== 0 )
4812
    begin
4813
        $display("Parity checker testing failed! Time %t ", $time) ;
4814
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4815
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4816
        ok = 0 ;
4817
    end
4818
 
4819
    if ( ok )
4820
        test_ok ;
4821
 
4822
    // clear statuses
4823
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4824
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4825
    fork
4826
    begin
4827
        ipci_unsupported_commands_master.master_reference
4828
        (
4829
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4830
            32'h5555_5555,      // second part of address in dual address cycle
4831
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4832
            `BC_MEM_WRITE,      // normal command
4833
            4'h0,               // byte enables
4834
            32'h1234_5678,      // data
4835
            1'b1,               // make address parity error on first phase of dual address
4836
            1'b0,               // make address parity error on second phase of dual address
4837
            ok                  // result of operation
4838
        ) ;
4839 35 mihad
        if ( !perr_asserted )
4840
            disable wait_serr8 ;
4841 15 mihad
    end
4842
    begin:wait_serr8
4843
        perr_asserted = 0 ;
4844
        @(posedge pci_clock) ;
4845
        while( SERR === 1 )
4846
            @(posedge pci_clock) ;
4847
 
4848
        perr_asserted = 1 ;
4849
        $display("Parity checker testing failed! Time %t ", $time) ;
4850
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4851
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4852
    end
4853
    join
4854
 
4855
    if ( ok && !perr_asserted)
4856
        test_ok ;
4857
 
4858
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4859
    fork
4860
    begin
4861
        ipci_unsupported_commands_master.master_reference
4862
        (
4863
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4864
            32'h5555_5555,      // second part of address in dual address cycle
4865
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4866
            `BC_MEM_WRITE,      // normal command
4867
            4'h0,               // byte enables
4868
            32'h1234_5678,      // data
4869
            1'b0,               // make address parity error on first phase of dual address
4870
            1'b1,               // make address parity error on second phase of dual address
4871
            ok                  // result of operation
4872
        ) ;
4873 35 mihad
        if ( !perr_asserted )
4874
            disable wait_serr9 ;
4875 15 mihad
    end
4876
    begin:wait_serr9
4877
        perr_asserted = 0 ;
4878
        @(posedge pci_clock) ;
4879
        while( SERR === 1 )
4880
            @(posedge pci_clock) ;
4881
 
4882
        perr_asserted = 1 ;
4883
        $display("Parity checker testing failed! Time %t ", $time) ;
4884
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4885
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4886
    end
4887
    join
4888
 
4889
    if ( ok && !perr_asserted)
4890
        test_ok ;
4891
 
4892
    // check statuses!
4893
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4894
    ok = 1 ;
4895
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4896
    if ( temp_val1[31] !== 1 )
4897
    begin
4898
        $display("Parity checker testing failed! Time %t ", $time) ;
4899
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4900
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4901
        ok = 0 ;
4902
    end
4903
 
4904
    if ( temp_val1[30] !== 0 )
4905
    begin
4906
        $display("Parity checker testing failed! Time %t ", $time) ;
4907
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4908
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4909
        ok = 0 ;
4910
    end
4911
 
4912
    if ( temp_val1[24] !== 0 )
4913
    begin
4914
        $display("Parity checker testing failed! Time %t ", $time) ;
4915
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4916
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4917
        ok = 0 ;
4918
    end
4919
 
4920
    if ( ok )
4921
        test_ok ;
4922
 
4923
    // clear statuses
4924
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4925
 
4926
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4927
    fork
4928
    begin
4929
        ipci_unsupported_commands_master.master_reference
4930
        (
4931
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4932
            32'h5555_5555,      // second part of address in dual address cycle
4933
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4934
            `BC_MEM_WRITE,      // normal command
4935
            4'h0,               // byte enables
4936
            32'h1234_5678,      // data
4937
            1'b1,               // make address parity error on first phase of dual address
4938
            1'b1,               // make address parity error on second phase of dual address
4939
            ok                  // result of operation
4940
        ) ;
4941 35 mihad
        if ( !perr_asserted )
4942
            disable wait_serr10 ;
4943 15 mihad
    end
4944
    begin:wait_serr10
4945
        perr_asserted = 0 ;
4946
        @(posedge pci_clock) ;
4947
        while( SERR === 1 )
4948
            @(posedge pci_clock) ;
4949
 
4950
        perr_asserted = 1 ;
4951
        $display("Parity checker testing failed! Time %t ", $time) ;
4952
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4953
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4954
    end
4955
    join
4956
 
4957
    if ( ok && !perr_asserted)
4958
        test_ok ;
4959
 
4960
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
4961
 
4962
    `ifdef HOST
4963
        repeat(4)
4964 26 mihad
            @(posedge pci_clock) ;
4965
        repeat(4)
4966 15 mihad
            @(posedge wb_clock) ;
4967
        if ( INT_O !== 0 )
4968
        begin
4969
            $display("Parity checker testing failed! Time %t ", $time) ;
4970
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
4971
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
4972
        end
4973
        else
4974
            test_ok ;
4975
    `else
4976
    `ifdef GUEST
4977 26 mihad
        repeat(4)
4978
            @(posedge wb_clock) ;
4979
        repeat(4)
4980 15 mihad
            @(posedge pci_clock) ;
4981
 
4982
        if ( INTA !== 1 )
4983
        begin
4984
            $display("Parity checker testing failed! Time %t ", $time) ;
4985
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
4986
            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") ;
4987
        end
4988
        else
4989
            test_ok ;
4990
    `endif
4991
    `endif
4992
 
4993
    // check statuses!
4994
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4995
    ok = 1 ;
4996
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4997
    if ( temp_val1[31] !== 1 )
4998
    begin
4999
        $display("Parity checker testing failed! Time %t ", $time) ;
5000
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5001
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5002
        ok = 0 ;
5003
    end
5004
 
5005
    if ( temp_val1[30] !== 0 )
5006
    begin
5007
        $display("Parity checker testing failed! Time %t ", $time) ;
5008
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5009
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5010
        ok = 0 ;
5011
    end
5012
 
5013
    if ( temp_val1[24] !== 0 )
5014
    begin
5015
        $display("Parity checker testing failed! Time %t ", $time) ;
5016
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5017
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5018
        ok = 0 ;
5019
    end
5020
 
5021
    if ( ok )
5022
        test_ok ;
5023
 
5024
    // clear statuses
5025
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5026
 
5027
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5028
    ok = 1 ;
5029
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5030
 
5031
    if ( temp_val1[4] !== 0 )
5032
    begin
5033
        $display("Parity checker testing failed! Time %t ", $time) ;
5034
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5035
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5036
        ok = 0 ;
5037
    end
5038
 
5039
    if ( temp_val1[3] !== 0 )
5040
    begin
5041
        $display("Parity checker testing failed! Time %t ", $time) ;
5042
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5043
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5044
        ok = 0 ;
5045
    end
5046
 
5047
    if ( ok )
5048
        test_ok ;
5049
 
5050
    // now enable system error signaling and test response
5051
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5052
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5053
 
5054
    fork
5055
    begin
5056
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5057
               target_address, 32'h1234_5678,
5058
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5059
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5060
        do_pause( 1 ) ;
5061
    end
5062
    begin:wait_serr11
5063
        perr_asserted = 0 ;
5064
        @(posedge pci_clock) ;
5065 35 mihad
        while( SERR !== 0 )
5066 15 mihad
            @(posedge pci_clock) ;
5067
 
5068 35 mihad
        perr_asserted = 1 ;
5069 15 mihad
    end
5070
    begin
5071
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5072
        if ( ok !== 1 )
5073
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5074
 
5075
        @(posedge pci_clock) ;
5076 35 mihad
        #1 ;
5077
        if ( !perr_asserted )
5078
            disable wait_serr11 ;
5079 15 mihad
    end
5080
    join
5081
 
5082
    if ( ok && perr_asserted)
5083
        test_ok ;
5084
    else
5085
    if ( !perr_asserted )
5086
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5087
 
5088
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5089
 
5090
    `ifdef HOST
5091
        repeat(4)
5092 26 mihad
            @(posedge pci_clock) ;
5093
        repeat(4)
5094 15 mihad
            @(posedge wb_clock) ;
5095
        if ( INT_O !== 1 )
5096
        begin
5097
            $display("Parity checker testing failed! Time %t ", $time) ;
5098
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5099
            test_fail("Interrupt Request was not triggered as expected") ;
5100
        end
5101
        else
5102
            test_ok ;
5103
    `else
5104
    `ifdef GUEST
5105 26 mihad
        repeat(4)
5106
            @(posedge wb_clock) ;
5107
        repeat(4)
5108 15 mihad
            @(posedge pci_clock) ;
5109
 
5110
        if ( INTA !== 1 )
5111
        begin
5112
            $display("Parity checker testing failed! Time %t ", $time) ;
5113
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5114
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5115
        end
5116
        else
5117
            test_ok ;
5118
    `endif
5119
    `endif
5120
 
5121
    // check statuses!
5122
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5123
    ok = 1 ;
5124
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5125
    if ( temp_val1[31] !== 1 )
5126
    begin
5127
        $display("Parity checker testing failed! Time %t ", $time) ;
5128
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5129
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5130
        ok = 0 ;
5131
    end
5132
 
5133
    if ( temp_val1[30] !== 1 )
5134
    begin
5135
        $display("Parity checker testing failed! Time %t ", $time) ;
5136
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5137
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5138
        ok = 0 ;
5139
    end
5140
 
5141
    if ( temp_val1[24] !== 0 )
5142
    begin
5143
        $display("Parity checker testing failed! Time %t ", $time) ;
5144
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5145
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5146
        ok = 0 ;
5147
    end
5148
 
5149
    if ( ok )
5150
        test_ok ;
5151
 
5152
    // clear statuses
5153
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5154
 
5155
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5156
 
5157
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5158
    ok = 1 ;
5159
 
5160
    `ifdef HOST
5161
    if ( temp_val1[4] !== 1 )
5162
    begin
5163
        $display("Parity checker testing failed! Time %t ", $time) ;
5164
        $display("System error interrupt status bit not set when expected!") ;
5165
        test_fail("System error interrupt status bit not set when expected") ;
5166
        ok = 0 ;
5167
    end
5168
    `else
5169
    if ( temp_val1[4] !== 0 )
5170
    begin
5171
        $display("Parity checker testing failed! Time %t ", $time) ;
5172
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5173
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5174
        ok = 0 ;
5175
    end
5176
    `endif
5177
 
5178
    if ( temp_val1[3] !== 0 )
5179
    begin
5180
        $display("Parity checker testing failed! Time %t ", $time) ;
5181
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5182
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5183
        ok = 0 ;
5184
    end
5185
 
5186
    if ( ok )
5187
        test_ok ;
5188
 
5189
    // clear statuses
5190
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5191
 
5192
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5193
    fork
5194
    begin
5195
        ipci_unsupported_commands_master.master_reference
5196
        (
5197
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5198
            32'h5555_5555,      // second part of address in dual address cycle
5199
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5200
            `BC_MEM_WRITE,      // normal command
5201
            4'h0,               // byte enables
5202
            32'h1234_5678,      // data
5203
            1'b1,               // make address parity error on first phase of dual address
5204
            1'b0,               // make address parity error on second phase of dual address
5205
            ok                  // result of operation
5206
        ) ;
5207 35 mihad
        if ( !perr_asserted )
5208
            disable wait_serr14 ;
5209 15 mihad
    end
5210
    begin:wait_serr14
5211
        perr_asserted = 0 ;
5212
        @(posedge pci_clock) ;
5213 35 mihad
        while( SERR !== 0 )
5214 15 mihad
            @(posedge pci_clock) ;
5215
 
5216 35 mihad
        perr_asserted = 1 ;
5217 15 mihad
    end
5218
    join
5219
 
5220
    if ( ok && perr_asserted)
5221
        test_ok ;
5222
    else
5223
    if ( !perr_asserted )
5224
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5225
 
5226
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5227
 
5228
    `ifdef HOST
5229
        repeat(4)
5230 26 mihad
            @(posedge pci_clock) ;
5231
        repeat(4)
5232 15 mihad
            @(posedge wb_clock) ;
5233
        if ( INT_O !== 1 )
5234
        begin
5235
            $display("Parity checker testing failed! Time %t ", $time) ;
5236
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5237
            test_fail("Interrupt Request was not triggered as expected") ;
5238
        end
5239
        else
5240
            test_ok ;
5241
    `else
5242
    `ifdef GUEST
5243 26 mihad
        repeat(4)
5244
            @(posedge wb_clock) ;
5245
        repeat(4)
5246 15 mihad
            @(posedge pci_clock) ;
5247
 
5248
        if ( INTA !== 1 )
5249
        begin
5250
            $display("Parity checker testing failed! Time %t ", $time) ;
5251
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5252
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5253
        end
5254
        else
5255
            test_ok ;
5256
    `endif
5257
    `endif
5258
 
5259
    // check statuses!
5260
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5261
    ok = 1 ;
5262
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5263
    if ( temp_val1[31] !== 1 )
5264
    begin
5265
        $display("Parity checker testing failed! Time %t ", $time) ;
5266
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5267
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5268
        ok = 0 ;
5269
    end
5270
 
5271
    if ( temp_val1[30] !== 1 )
5272
    begin
5273
        $display("Parity checker testing failed! Time %t ", $time) ;
5274
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5275
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5276
        ok = 0 ;
5277
    end
5278
 
5279
    if ( temp_val1[24] !== 0 )
5280
    begin
5281
        $display("Parity checker testing failed! Time %t ", $time) ;
5282
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5283
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5284
        ok = 0 ;
5285
    end
5286
 
5287
    if ( ok )
5288
        test_ok ;
5289
 
5290
    // clear statuses
5291
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5292
 
5293
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5294
 
5295
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5296
    ok = 1 ;
5297
 
5298
    `ifdef HOST
5299
    if ( temp_val1[4] !== 1 )
5300
    begin
5301
        $display("Parity checker testing failed! Time %t ", $time) ;
5302
        $display("System error interrupt status bit not set when expected!") ;
5303
        test_fail("System error interrupt status bit not set when expected") ;
5304
        ok = 0 ;
5305
    end
5306
    `else
5307
    if ( temp_val1[4] !== 0 )
5308
    begin
5309
        $display("Parity checker testing failed! Time %t ", $time) ;
5310
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5311
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5312
        ok = 0 ;
5313
    end
5314
    `endif
5315
 
5316
    if ( temp_val1[3] !== 0 )
5317
    begin
5318
        $display("Parity checker testing failed! Time %t ", $time) ;
5319
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5320
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5321
        ok = 0 ;
5322
    end
5323
 
5324
    if ( ok )
5325
        test_ok ;
5326
 
5327
    // clear statuses
5328
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5329
 
5330
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5331
    fork
5332
    begin
5333
        ipci_unsupported_commands_master.master_reference
5334
        (
5335
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5336
            32'h5555_5555,      // second part of address in dual address cycle
5337
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5338
            `BC_MEM_WRITE,      // normal command
5339
            4'h0,               // byte enables
5340
            32'h1234_5678,      // data
5341
            1'b0,               // make address parity error on first phase of dual address
5342
            1'b1,               // make address parity error on second phase of dual address
5343
            ok                  // result of operation
5344
        ) ;
5345 35 mihad
        if ( !perr_asserted )
5346
            disable wait_serr15 ;
5347 15 mihad
    end
5348
    begin:wait_serr15
5349
        perr_asserted = 0 ;
5350
        @(posedge pci_clock) ;
5351 35 mihad
        while( SERR !== 0 )
5352 15 mihad
            @(posedge pci_clock) ;
5353
 
5354 35 mihad
        perr_asserted = 1 ;
5355 15 mihad
    end
5356
    join
5357
 
5358
    if ( ok && perr_asserted)
5359
        test_ok ;
5360
    else
5361
    if ( !perr_asserted )
5362
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5363
 
5364
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5365
 
5366
    `ifdef HOST
5367
        repeat(4)
5368 26 mihad
            @(posedge pci_clock) ;
5369
        repeat(4)
5370 15 mihad
            @(posedge wb_clock) ;
5371
        if ( INT_O !== 1 )
5372
        begin
5373
            $display("Parity checker testing failed! Time %t ", $time) ;
5374
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5375
            test_fail("Interrupt Request was not triggered as expected") ;
5376
        end
5377
        else
5378
            test_ok ;
5379
    `else
5380
    `ifdef GUEST
5381 26 mihad
        repeat(4)
5382
            @(posedge wb_clock) ;
5383
        repeat(4)
5384 15 mihad
            @(posedge pci_clock) ;
5385
 
5386
        if ( INTA !== 1 )
5387
        begin
5388
            $display("Parity checker testing failed! Time %t ", $time) ;
5389
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5390
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5391
        end
5392
        else
5393
            test_ok ;
5394
    `endif
5395
    `endif
5396
 
5397
    // check statuses!
5398
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5399
    ok = 1 ;
5400
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5401
    if ( temp_val1[31] !== 1 )
5402
    begin
5403
        $display("Parity checker testing failed! Time %t ", $time) ;
5404
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5405
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5406
        ok = 0 ;
5407
    end
5408
 
5409
    if ( temp_val1[30] !== 1 )
5410
    begin
5411
        $display("Parity checker testing failed! Time %t ", $time) ;
5412
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5413
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5414
        ok = 0 ;
5415
    end
5416
 
5417
    if ( temp_val1[24] !== 0 )
5418
    begin
5419
        $display("Parity checker testing failed! Time %t ", $time) ;
5420
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5421
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5422
        ok = 0 ;
5423
    end
5424
 
5425
    if ( ok )
5426
        test_ok ;
5427
 
5428
    // clear statuses
5429
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5430
 
5431
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5432
 
5433
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5434
    ok = 1 ;
5435
 
5436
    `ifdef HOST
5437
    if ( temp_val1[4] !== 1 )
5438
    begin
5439
        $display("Parity checker testing failed! Time %t ", $time) ;
5440
        $display("System error interrupt status bit not set when expected!") ;
5441
        test_fail("System error interrupt status bit not set when expected") ;
5442
        ok = 0 ;
5443
    end
5444
    `else
5445
    if ( temp_val1[4] !== 0 )
5446
    begin
5447
        $display("Parity checker testing failed! Time %t ", $time) ;
5448
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5449
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5450
        ok = 0 ;
5451
    end
5452
    `endif
5453
 
5454
    if ( temp_val1[3] !== 0 )
5455
    begin
5456
        $display("Parity checker testing failed! Time %t ", $time) ;
5457
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5458
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5459
        ok = 0 ;
5460
    end
5461
 
5462
    if ( ok )
5463
        test_ok ;
5464
 
5465
    // clear statuses
5466
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5467
 
5468
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5469
    fork
5470
    begin
5471
        ipci_unsupported_commands_master.master_reference
5472
        (
5473
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5474
            32'h5555_5555,      // second part of address in dual address cycle
5475
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5476
            `BC_MEM_WRITE,      // normal command
5477
            4'h0,               // byte enables
5478
            32'h1234_5678,      // data
5479
            1'b1,               // make address parity error on first phase of dual address
5480
            1'b1,               // make address parity error on second phase of dual address
5481
            ok                  // result of operation
5482
        ) ;
5483 35 mihad
        if ( !perr_asserted )
5484
            disable wait_serr16 ;
5485 15 mihad
    end
5486
    begin:wait_serr16
5487
        perr_asserted = 0 ;
5488
        @(posedge pci_clock) ;
5489 35 mihad
        while( SERR !== 0 )
5490 15 mihad
            @(posedge pci_clock) ;
5491
 
5492 35 mihad
        perr_asserted = 1 ;
5493 15 mihad
    end
5494
    join
5495
 
5496
    if ( ok && perr_asserted)
5497
        test_ok ;
5498
    else
5499
    if ( !perr_asserted )
5500
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5501
 
5502
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5503
 
5504
    `ifdef HOST
5505
        repeat(4)
5506 26 mihad
            @(posedge pci_clock) ;
5507
        repeat(4)
5508 15 mihad
            @(posedge wb_clock) ;
5509
        if ( INT_O !== 1 )
5510
        begin
5511
            $display("Parity checker testing failed! Time %t ", $time) ;
5512
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5513
            test_fail("Interrupt Request was not triggered as expected") ;
5514
        end
5515
        else
5516
            test_ok ;
5517
    `else
5518
    `ifdef GUEST
5519 26 mihad
        repeat(4)
5520
            @(posedge wb_clock) ;
5521
        repeat(4)
5522 15 mihad
            @(posedge pci_clock) ;
5523
 
5524
        if ( INTA !== 1 )
5525
        begin
5526
            $display("Parity checker testing failed! Time %t ", $time) ;
5527
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5528
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5529
        end
5530
        else
5531
            test_ok ;
5532
    `endif
5533
    `endif
5534
 
5535
    // check statuses!
5536
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5537
    ok = 1 ;
5538
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5539
    if ( temp_val1[31] !== 1 )
5540
    begin
5541
        $display("Parity checker testing failed! Time %t ", $time) ;
5542
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5543
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5544
        ok = 0 ;
5545
    end
5546
 
5547
    if ( temp_val1[30] !== 1 )
5548
    begin
5549
        $display("Parity checker testing failed! Time %t ", $time) ;
5550
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5551
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5552
        ok = 0 ;
5553
    end
5554
 
5555
    if ( temp_val1[24] !== 0 )
5556
    begin
5557
        $display("Parity checker testing failed! Time %t ", $time) ;
5558
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5559
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5560
        ok = 0 ;
5561
    end
5562
 
5563
    if ( ok )
5564
        test_ok ;
5565
 
5566
    // clear statuses
5567
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5568
 
5569
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5570
 
5571
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5572
    ok = 1 ;
5573
 
5574
    `ifdef HOST
5575
    if ( temp_val1[4] !== 1 )
5576
    begin
5577
        $display("Parity checker testing failed! Time %t ", $time) ;
5578
        $display("System error interrupt status bit not set when expected!") ;
5579
        test_fail("System error interrupt status bit not set when expected") ;
5580
        ok = 0 ;
5581
    end
5582
    `else
5583
    if ( temp_val1[4] !== 0 )
5584
    begin
5585
        $display("Parity checker testing failed! Time %t ", $time) ;
5586
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5587
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5588
        ok = 0 ;
5589
    end
5590
    `endif
5591
 
5592
    if ( temp_val1[3] !== 0 )
5593
    begin
5594
        $display("Parity checker testing failed! Time %t ", $time) ;
5595
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5596
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5597
        ok = 0 ;
5598
    end
5599
 
5600
    if ( ok )
5601
        test_ok ;
5602
 
5603
    // clear statuses
5604
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5605
 
5606
    // now just disable Parity Error response - on Address par errors nothing should happen
5607
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5608
 
5609
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5610
    fork
5611
    begin
5612
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5613
               target_address, 32'h1234_5678,
5614
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5615
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5616
        do_pause( 1 ) ;
5617
    end
5618
    begin:wait_serr12
5619
        perr_asserted = 0 ;
5620
        @(posedge pci_clock) ;
5621
        while( SERR === 1 )
5622
            @(posedge pci_clock) ;
5623
 
5624
        perr_asserted = 1 ;
5625
        $display("Parity checker testing failed! Time %t ", $time) ;
5626
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5627
        test_fail("SERR asserted when parity error response was disabled") ;
5628
    end
5629
    begin
5630
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5631
        if ( ok !== 1 )
5632
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5633
 
5634 35 mihad
        @(posedge pci_clock) ;
5635
        #1 ;
5636
        if ( !perr_asserted )
5637
            disable wait_serr12 ;
5638 15 mihad
    end
5639
    join
5640
 
5641
    if ( ok && !perr_asserted )
5642
        test_ok ;
5643
 
5644
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5645
    `ifdef HOST
5646 26 mihad
        repeat (4)
5647
            @(posedge pci_clock) ;
5648 15 mihad
        repeat(4)
5649
            @(posedge wb_clock) ;
5650
        if ( INT_O !== 0 )
5651
        begin
5652
            $display("Parity checker testing failed! Time %t ", $time) ;
5653
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5654
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5655
        end
5656
        else
5657
            test_ok ;
5658
    `else
5659
    `ifdef GUEST
5660 26 mihad
        repeat(4)
5661
            @(posedge wb_clock) ;
5662
        repeat (4)
5663 15 mihad
            @(posedge pci_clock) ;
5664
 
5665
        if ( INTA !== 1 )
5666
        begin
5667
            $display("Parity checker testing failed! Time %t ", $time) ;
5668
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5669
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5670
        end
5671
        else
5672
            test_ok ;
5673
    `endif
5674
    `endif
5675
 
5676
    // check statuses!
5677
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5678
    ok = 1 ;
5679
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5680
    if ( temp_val1[31] !== 1 )
5681
    begin
5682
        $display("Parity checker testing failed! Time %t ", $time) ;
5683
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5684
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5685
        ok = 0 ;
5686
    end
5687
 
5688
    if ( temp_val1[30] !== 0 )
5689
    begin
5690
        $display("Parity checker testing failed! Time %t ", $time) ;
5691
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5692
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5693
        ok = 0 ;
5694
    end
5695
 
5696
    if ( temp_val1[24] !== 0 )
5697
    begin
5698
        $display("Parity checker testing failed! Time %t ", $time) ;
5699
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5700
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5701
        ok = 0 ;
5702
    end
5703
 
5704
    if ( ok )
5705
        test_ok ;
5706
 
5707
    // clear statuses
5708
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5709
 
5710
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5711
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5712
    ok = 1 ;
5713
    if ( temp_val1[4] !== 0 )
5714
    begin
5715
        $display("Parity checker testing failed! Time %t ", $time) ;
5716
        $display("System error interrupt status bit set when not expected!") ;
5717
        test_fail("System error interrupt status bit set when not expected") ;
5718
        ok = 0 ;
5719
    end
5720
 
5721
    if ( temp_val1[3] !== 0 )
5722
    begin
5723
        $display("Parity checker testing failed! Time %t ", $time) ;
5724
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5725
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5726
        ok = 0 ;
5727
    end
5728
 
5729
    if ( ok )
5730
        test_ok ;
5731
 
5732
    // clear statuses
5733
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5734
 
5735
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5736
    fork
5737
    begin
5738
        ipci_unsupported_commands_master.master_reference
5739
        (
5740
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5741
            32'h5555_5555,      // second part of address in dual address cycle
5742
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5743
            `BC_MEM_WRITE,      // normal command
5744
            4'h0,               // byte enables
5745
            32'h1234_5678,      // data
5746
            1'b1,               // make address parity error on first phase of dual address
5747
            1'b0,               // make address parity error on second phase of dual address
5748
            ok                  // result of operation
5749
        ) ;
5750 35 mihad
        if ( !perr_asserted )
5751
            disable wait_serr17 ;
5752 15 mihad
    end
5753
    begin:wait_serr17
5754
        perr_asserted = 0 ;
5755
        @(posedge pci_clock) ;
5756
        while( SERR === 1 )
5757
            @(posedge pci_clock) ;
5758
 
5759
        perr_asserted = 1 ;
5760
        $display("Parity checker testing failed! Time %t ", $time) ;
5761
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5762
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5763
    end
5764
    join
5765
 
5766
    if ( ok && !perr_asserted)
5767
        test_ok ;
5768
 
5769
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5770
    fork
5771
    begin
5772
        ipci_unsupported_commands_master.master_reference
5773
        (
5774
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5775
            32'h5555_5555,      // second part of address in dual address cycle
5776
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5777
            `BC_MEM_WRITE,      // normal command
5778
            4'h0,               // byte enables
5779
            32'h1234_5678,      // data
5780
            1'b0,               // make address parity error on first phase of dual address
5781
            1'b1,               // make address parity error on second phase of dual address
5782
            ok                  // result of operation
5783
        ) ;
5784 35 mihad
        if ( !perr_asserted )
5785
            disable wait_serr18 ;
5786 15 mihad
    end
5787
    begin:wait_serr18
5788
        perr_asserted = 0 ;
5789
        @(posedge pci_clock) ;
5790
        while( SERR === 1 )
5791
            @(posedge pci_clock) ;
5792
 
5793
        perr_asserted = 1 ;
5794
        $display("Parity checker testing failed! Time %t ", $time) ;
5795
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5796
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5797
    end
5798
    join
5799
 
5800
    if ( ok && !perr_asserted)
5801
        test_ok ;
5802
 
5803
    // check statuses!
5804
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5805
    ok = 1 ;
5806
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5807
    if ( temp_val1[31] !== 1 )
5808
    begin
5809
        $display("Parity checker testing failed! Time %t ", $time) ;
5810
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5811
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5812
        ok = 0 ;
5813
    end
5814
 
5815
    if ( temp_val1[30] !== 0 )
5816
    begin
5817
        $display("Parity checker testing failed! Time %t ", $time) ;
5818
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5819
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5820
        ok = 0 ;
5821
    end
5822
 
5823
    if ( temp_val1[24] !== 0 )
5824
    begin
5825
        $display("Parity checker testing failed! Time %t ", $time) ;
5826
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5827
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5828
        ok = 0 ;
5829
    end
5830
 
5831
    if ( ok )
5832
        test_ok ;
5833
 
5834
    // clear statuses
5835
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5836
 
5837
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5838
    fork
5839
    begin
5840
        ipci_unsupported_commands_master.master_reference
5841
        (
5842
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5843
            32'h5555_5555,      // second part of address in dual address cycle
5844
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5845
            `BC_MEM_WRITE,      // normal command
5846
            4'h0,               // byte enables
5847
            32'h1234_5678,      // data
5848
            1'b1,               // make address parity error on first phase of dual address
5849
            1'b1,               // make address parity error on second phase of dual address
5850
            ok                  // result of operation
5851
        ) ;
5852 35 mihad
        if ( !perr_asserted )
5853
            disable wait_serr19 ;
5854 15 mihad
    end
5855
    begin:wait_serr19
5856
        perr_asserted = 0 ;
5857
        @(posedge pci_clock) ;
5858
        while( SERR === 1 )
5859
            @(posedge pci_clock) ;
5860
 
5861
        perr_asserted = 1 ;
5862
        $display("Parity checker testing failed! Time %t ", $time) ;
5863
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5864
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5865
    end
5866
    join
5867
 
5868
    if ( ok && !perr_asserted)
5869
        test_ok ;
5870
 
5871
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5872
 
5873
    `ifdef HOST
5874
        repeat(4)
5875 26 mihad
            @(posedge pci_clock) ;
5876
        repeat(4)
5877 15 mihad
            @(posedge wb_clock) ;
5878
        if ( INT_O !== 0 )
5879
        begin
5880
            $display("Parity checker testing failed! Time %t ", $time) ;
5881
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5882
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5883
        end
5884
        else
5885
            test_ok ;
5886
    `else
5887
    `ifdef GUEST
5888 26 mihad
        repeat(4)
5889
            @(posedge wb_clock) ;
5890
        repeat(4)
5891 15 mihad
            @(posedge pci_clock) ;
5892
 
5893
        if ( INTA !== 1 )
5894
        begin
5895
            $display("Parity checker testing failed! Time %t ", $time) ;
5896
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5897
            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") ;
5898
        end
5899
        else
5900
            test_ok ;
5901
    `endif
5902
    `endif
5903
 
5904
    // check statuses!
5905
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5906
    ok = 1 ;
5907
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5908
    if ( temp_val1[31] !== 1 )
5909
    begin
5910
        $display("Parity checker testing failed! Time %t ", $time) ;
5911
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5912
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5913
        ok = 0 ;
5914
    end
5915
 
5916
    if ( temp_val1[30] !== 0 )
5917
    begin
5918
        $display("Parity checker testing failed! Time %t ", $time) ;
5919
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5920
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5921
        ok = 0 ;
5922
    end
5923
 
5924
    if ( temp_val1[24] !== 0 )
5925
    begin
5926
        $display("Parity checker testing failed! Time %t ", $time) ;
5927
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5928
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5929
        ok = 0 ;
5930
    end
5931
 
5932
    if ( ok )
5933
        test_ok ;
5934
 
5935
    // clear statuses
5936
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5937
 
5938
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5939
 
5940
    // do normal write
5941
    fork
5942
    begin
5943
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5944
               target_address, 32'h1234_5678, `Test_All_Bytes,
5945
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5946
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5947
        do_pause( 1 ) ;
5948
    end
5949
    begin:wait_serr13
5950
        perr_asserted = 0 ;
5951
        @(posedge pci_clock) ;
5952
        while( SERR === 1 )
5953
            @(posedge pci_clock) ;
5954
 
5955
        perr_asserted = 1 ;
5956
        $display("Parity checker testing failed! Time %t ", $time) ;
5957
        $display("SERR asserted for no reason!") ;
5958
        test_fail("SERR was asserted for no reason") ;
5959
    end
5960
    begin
5961
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5962
        if ( ok !== 1 )
5963
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5964
 
5965 35 mihad
        @(posedge pci_clock) ;
5966
        #1 ;
5967
        if ( !perr_asserted )
5968
            disable wait_serr13 ;
5969 15 mihad
    end
5970
    join
5971
 
5972
    if ( ok && !perr_asserted )
5973
        test_ok ;
5974
 
5975
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
5976
    `ifdef HOST
5977 26 mihad
        repeat( 4 )
5978
            @(posedge pci_clock) ;
5979 15 mihad
        repeat(4)
5980
            @(posedge wb_clock) ;
5981
        if ( INT_O !== 0 )
5982
        begin
5983
            $display("Parity checker testing failed! Time %t ", $time) ;
5984
            $display("Interrupt request asserted for no reason!") ;
5985
            test_fail("Interrupt request was asserted for no reason") ;
5986
        end
5987
        else
5988
            test_ok ;
5989
    `else
5990
    `ifdef GUEST
5991 26 mihad
        repeat(4)
5992
            @(posedge wb_clock) ;
5993
        repeat(4)
5994 15 mihad
            @(posedge pci_clock) ;
5995
 
5996
        if ( INTA !== 1 )
5997
        begin
5998
            $display("Parity checker testing failed! Time %t ", $time) ;
5999
            $display("Interrupt request asserted for no reason!") ;
6000
            test_fail("Interrupt request was asserted for no reason") ;
6001
        end
6002
        else
6003
            test_ok ;
6004
    `endif
6005
    `endif
6006
 
6007
    // check statuses!
6008
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6009
    ok = 1 ;
6010
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6011
    if ( temp_val1[31] !== 0 )
6012
    begin
6013
        $display("Parity checker testing failed! Time %t ", $time) ;
6014
        $display("Detected Parity Error bit was set for no reason!") ;
6015
        test_fail("Detected Parity Error bit was set for no reason") ;
6016
        ok = 0 ;
6017
    end
6018
 
6019
    if ( temp_val1[30] !== 0 )
6020
    begin
6021
        $display("Parity checker testing failed! Time %t ", $time) ;
6022
        $display("Signalled System Error bit was set for no reason!") ;
6023
        test_fail("Signalled System Error bit was set for no reason") ;
6024
        ok = 0 ;
6025
    end
6026
 
6027
    if ( temp_val1[24] !== 0 )
6028
    begin
6029
        $display("Parity checker testing failed! Time %t ", $time) ;
6030
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6031
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6032
        ok = 0 ;
6033
    end
6034
 
6035
    if ( ok )
6036
        test_ok ;
6037
 
6038
    // clear statuses
6039
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6040
 
6041
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6042
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6043
    ok = 1 ;
6044
 
6045
    if ( temp_val1[4] !== 0 )
6046
    begin
6047
        $display("Parity checker testing failed! Time %t ", $time) ;
6048
        $display("System error interrupt status bit set when not expected!") ;
6049
        test_fail("System error interrupt status bit set when not expected") ;
6050
        ok = 0 ;
6051
    end
6052
 
6053
    if ( temp_val1[3] !== 0 )
6054
    begin
6055
        $display("Parity checker testing failed! Time %t ", $time) ;
6056
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6057
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6058
        ok = 0 ;
6059
    end
6060
 
6061
    if ( ok )
6062
        test_ok ;
6063
 
6064
    // clear statuses
6065
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6066
 
6067
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6068
 
6069
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6070
 
6071
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6072
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6073
 
6074
    // setup target's image!
6075
    target_address  = Target_Base_Addr_R[1] ;
6076
 
6077
    // base address
6078
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6079
 
6080
    // address mask
6081
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6082
 
6083
    // image control
6084
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6085
 
6086
    // enable everything possible for parity checking
6087
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6088
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6089
 
6090
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6091
 
6092
    fork
6093
    begin
6094
        if ( target_mem_image === 1 )
6095
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6096
                   target_address, 32'h1234_5678,
6097
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6098
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6099
        else
6100
            PCIU_IO_WRITE_MAKE_PERR (
6101
                                    `Test_Master_1,
6102
                                    target_address,
6103
                                    32'h1234_5678,
6104
                                    4'h0,
6105
                                    1,
6106
                                    `Test_Target_Normal_Completion
6107
                                    );
6108
 
6109
        do_pause( 1 ) ;
6110
    end
6111
    begin:wait_perr11
6112
        perr_asserted = 0 ;
6113
        @(posedge pci_clock) ;
6114 35 mihad
        while ( PERR !== 0 )
6115 15 mihad
            @(posedge pci_clock) ;
6116
 
6117 35 mihad
        perr_asserted = 1 ;
6118 15 mihad
 
6119
    end
6120
    begin
6121
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6122
 
6123
        if ( ok !== 1 )
6124
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6125
 
6126
        repeat(2)
6127
            @(posedge pci_clock) ;
6128
 
6129 35 mihad
        #1 ;
6130
        if ( !perr_asserted )
6131
            disable wait_perr11 ;
6132 15 mihad
    end
6133
    join
6134
 
6135
    if ( ok && perr_asserted )
6136
        test_ok ;
6137
    else
6138
    if ( !perr_asserted )
6139
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6140
 
6141
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6142
    `ifdef HOST
6143 26 mihad
        repeat (4)
6144
            @(posedge pci_clock) ;
6145 15 mihad
        repeat(4)
6146
            @(posedge wb_clock) ;
6147
        if ( INT_O !== 0 )
6148
        begin
6149
            $display("Parity checker testing failed! Time %t ", $time) ;
6150
            $display("Interrupt request asserted for no reason!") ;
6151
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6152
        end
6153
        else
6154
            test_ok ;
6155
    `else
6156
    `ifdef GUEST
6157 26 mihad
        repeat(4)
6158
            @(posedge wb_clock) ;
6159
        repeat (4)
6160 15 mihad
            @(posedge pci_clock) ;
6161
 
6162
        if ( INTA !== 1 )
6163
        begin
6164
            $display("Parity checker testing failed! Time %t ", $time) ;
6165
            $display("Interrupt request asserted for no reason!") ;
6166
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6167
        end
6168
        else
6169
            test_ok ;
6170
 
6171
    `endif
6172
    `endif
6173
 
6174
    // check statuses!
6175
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6176
    ok = 1 ;
6177
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6178
    if ( temp_val1[31] !== 1 )
6179
    begin
6180
        $display("Parity checker testing failed! Time %t ", $time) ;
6181 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6182
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6183 15 mihad
        ok = 0 ;
6184
    end
6185
 
6186
    if ( temp_val1[30] !== 0 )
6187
    begin
6188
        $display("Parity checker testing failed! Time %t ", $time) ;
6189
        $display("Signalled System Error bit was set for no reason!") ;
6190
        test_fail("Signalled System Error bit was set for no reason") ;
6191
        ok = 0 ;
6192
    end
6193
 
6194
    if ( temp_val1[24] !== 0 )
6195
    begin
6196
        $display("Parity checker testing failed! Time %t ", $time) ;
6197
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6198
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6199
        ok = 0 ;
6200
    end
6201
 
6202
    if ( ok )
6203
        test_ok ;
6204
 
6205
    // clear statuses
6206
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6207
 
6208
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6209
 
6210
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6211
    ok = 1 ;
6212
    if ( temp_val1[4] !== 0 )
6213
    begin
6214
        $display("Parity checker testing failed! Time %t ", $time) ;
6215
        $display("System error interrupt status bit set when not expected!") ;
6216
        test_fail("System error interrupt status bit set when not expected") ;
6217
        ok = 0 ;
6218
    end
6219
 
6220
    if ( temp_val1[3] !== 0 )
6221
    begin
6222
        $display("Parity checker testing failed! Time %t ", $time) ;
6223
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6224
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6225
        ok = 0 ;
6226
    end
6227
 
6228
    if ( ok )
6229
        test_ok ;
6230
 
6231
    // clear statuses
6232
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6233
 
6234
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6235
 
6236
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6237
    fork
6238
    begin
6239
        if ( target_mem_image === 1 )
6240
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6241
                          target_address, 32'h1234_5678,
6242
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6243
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6244
        else
6245
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6246
 
6247
        do_pause( 1 ) ;
6248
    end
6249
    begin:wait_perr12
6250
        perr_asserted = 0 ;
6251
        @(posedge pci_clock) ;
6252 35 mihad
        while ( PERR !== 0 )
6253 15 mihad
            @(posedge pci_clock) ;
6254
 
6255 35 mihad
        perr_asserted = 1 ;
6256 15 mihad
    end
6257
    begin
6258
 
6259
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6260
        if ( ok !== 1 )
6261
        begin
6262
            test_fail("Bridge failed to process Target Memory read correctly") ;
6263
            disable main ;
6264
        end
6265
 
6266
        repeat(3)
6267
            @(posedge pci_clock) ;
6268
 
6269
        if ( target_mem_image === 1 )
6270
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6271
                    target_address, 32'h1234_5678,
6272
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6273
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6274
        else
6275
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6276
 
6277
        do_pause( 1 ) ;
6278
 
6279
    end
6280
    begin
6281
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6282
        if ( ok !== 1 )
6283
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6284
        else
6285
        begin
6286
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6287
            if ( ok !== 1 )
6288
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6289
        end
6290
 
6291 35 mihad
        repeat(2)
6292 15 mihad
            @(posedge pci_clock) ;
6293
 
6294 35 mihad
        #1 ;
6295
        if ( !perr_asserted )
6296
            disable wait_perr12 ;
6297 15 mihad
    end
6298
    join
6299
 
6300
    if ( ok && perr_asserted )
6301
        test_ok ;
6302
    else
6303
    if ( !perr_asserted )
6304
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6305
 
6306
 
6307
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6308
    `ifdef HOST
6309
        repeat(4)
6310 26 mihad
            @(posedge pci_clock) ;
6311
        repeat(4)
6312 15 mihad
            @(posedge wb_clock) ;
6313
        if ( INT_O !== 0 )
6314
        begin
6315
            $display("Parity checker testing failed! Time %t ", $time) ;
6316
            $display("Interrupt request asserted for no reason!") ;
6317
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6318
        end
6319
        else
6320
            test_ok ;
6321
    `else
6322
    `ifdef GUEST
6323 26 mihad
        repeat(4)
6324
            @(posedge wb_clock) ;
6325
        repeat(4)
6326 15 mihad
            @(posedge pci_clock) ;
6327
 
6328
        if ( INTA !== 1 )
6329
        begin
6330
            $display("Parity checker testing failed! Time %t ", $time) ;
6331
            $display("Interrupt request asserted for no reason!") ;
6332
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6333
        end
6334
        else
6335
            test_ok ;
6336
    `endif
6337
    `endif
6338
 
6339
    // check statuses!
6340
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6341
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6342
    ok = 1 ;
6343 45 mihad
    if ( temp_val1[31] !== 0 )
6344 15 mihad
    begin
6345
        $display("Parity checker testing failed! Time %t ", $time) ;
6346 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6347
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6348 15 mihad
        ok = 0 ;
6349
    end
6350
 
6351
    if ( temp_val1[30] !== 0 )
6352
    begin
6353
        $display("Parity checker testing failed! Time %t ", $time) ;
6354
        $display("Signalled System Error bit was set for no reason!") ;
6355
        test_fail("Signalled System Error bit was set for no reason") ;
6356
        ok = 0 ;
6357
    end
6358
 
6359
    if ( temp_val1[24] !== 0 )
6360
    begin
6361
        $display("Parity checker testing failed! Time %t ", $time) ;
6362
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6363
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6364
        ok = 0 ;
6365
    end
6366
 
6367
    if ( ok )
6368
        test_ok ;
6369
 
6370
    // clear statuses
6371
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6372
 
6373
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6374
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6375
    ok = 1 ;
6376
    if ( temp_val1[4] !== 0 )
6377
    begin
6378
        $display("Parity checker testing failed! Time %t ", $time) ;
6379
        $display("System error interrupt status bit set when not expected!") ;
6380
        test_fail("System error interrupt status bit set when not expected") ;
6381
        ok = 0 ;
6382
    end
6383
 
6384
    if ( temp_val1[3] !== 0 )
6385
    begin
6386
        $display("Parity checker testing failed! Time %t ", $time) ;
6387
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6388
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6389
        ok = 0 ;
6390
    end
6391
 
6392
    if ( ok )
6393
        test_ok ;
6394
    // clear statuses
6395
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6396
 
6397
    $fdisplay(pci_mon_log_file_desc,
6398
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6399
    test_name = "DISABLE USED IMAGES" ;
6400
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6401
    if ( ok !== 1 )
6402
    begin
6403
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6404
        test_fail("WB Image Address Mask register could not be written to") ;
6405
        disable main ;
6406
    end
6407
 
6408 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6409 15 mihad
    if ( ok !== 1 )
6410
    begin
6411
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6412
        test_fail("PCI Image Address Mask register could not be written to") ;
6413
        disable main ;
6414
    end
6415
 
6416
    // disable target's 1 response to parity errors
6417 45 mihad
    configuration_cycle_write(0,                        // bus number
6418
                              `TAR1_IDSEL_INDEX - 11,   // device number
6419
                              0,                        // function number
6420
                              1,                        // register number
6421
                              0,                        // type of configuration cycle
6422
                              4'b0001,                  // byte enables
6423
                              32'h0000_0007             // data
6424 15 mihad
                             ) ;
6425
 
6426
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6427
end
6428
endtask // parity_checking
6429
 
6430
task wb_to_pci_transactions ;
6431
    reg   [11:0] ctrl_offset ;
6432
    reg   [11:0] ba_offset ;
6433
    reg   [11:0] am_offset ;
6434
    reg   [11:0] pci_ctrl_offset ;
6435
    reg   [11:0] err_cs_offset ;
6436
    reg   [11:0] icr_offset ;
6437
    reg   [11:0] isr_offset ;
6438
    reg   [11:0] lat_tim_cls_offset ;
6439
 
6440
    reg `WRITE_STIM_TYPE  write_data ;
6441
    reg `READ_STIM_TYPE   read_data ;
6442
    reg `READ_RETURN_TYPE read_status ;
6443
 
6444
    reg `WRITE_RETURN_TYPE write_status ;
6445
    reg `WB_TRANSFER_FLAGS write_flags ;
6446
    reg [31:0] temp_val1 ;
6447
    reg [31:0] temp_val2 ;
6448
    reg        ok   ;
6449
 
6450
    reg [31:0] image_base ;
6451
    reg [31:0] target_address ;
6452
    integer i ;
6453
    integer required_reads ;
6454
    integer writes_left ;
6455
 
6456
begin:main
6457
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6458
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6459
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6460
    pci_ctrl_offset    = 12'h4 ;
6461
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6462
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6463
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6464
    lat_tim_cls_offset = 12'hC ;
6465
 
6466
    $display("Checking WB to PCI transaction lengths!") ;
6467
    target_address  = `BEH_TAR1_MEM_START ;
6468
    image_base      = 0 ;
6469
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6470
 
6471
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6472
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6473
    write_flags                    = 0 ;
6474
    write_flags`INIT_WAITS         = tb_init_waits ;
6475
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6476
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6477
 
6478
    // enable master & target operation
6479
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6480
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6481
    if ( ok !== 1 )
6482
    begin
6483
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6484
        test_fail("write to PCI Device Control register failed") ;
6485
        disable main ;
6486
    end
6487
 
6488
    // prepare image control register
6489
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6490
    if ( ok !== 1 )
6491
    begin
6492
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6493
        test_fail("write to WB Image Control register failed") ;
6494
        disable main ;
6495
    end
6496
 
6497
    // prepare base address register
6498
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6499
    if ( ok !== 1 )
6500
    begin
6501
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6502
        test_fail("write to WB Base Address register failed") ;
6503
        disable main ;
6504
    end
6505
 
6506
    // write address mask register
6507
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6508
    if ( ok !== 1 )
6509
    begin
6510
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6511
        test_fail("write to WB Address Mask register failed") ;
6512
        disable main ;
6513
    end
6514
 
6515
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6516
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6517
    if ( ok !== 1 )
6518
    begin
6519
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6520
        test_fail("write to WB Error Control and Status register failed") ;
6521
        disable main ;
6522
    end
6523
 
6524
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6525
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6526
    if ( ok !== 1 )
6527
    begin
6528
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6529
        test_fail("write to Interrupt Control register failed") ;
6530
        disable main ;
6531
    end
6532
 
6533
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6534
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6535
    if ( ok !== 1 )
6536
    begin
6537
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6538
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6539
        disable main ;
6540
    end
6541
 
6542
    $display("Testing single write transaction progress from WB to PCI!") ;
6543
    write_data`WRITE_ADDRESS = target_address ;
6544
    write_data`WRITE_DATA    = wmem_data[0] ;
6545
    write_data`WRITE_SEL     = 4'hF ;
6546
 
6547
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6548
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6549
 
6550
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6551
    fork
6552
    begin
6553
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6554
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6555
        begin
6556
            $display("Transaction progress testing failed! Time %t ", $time) ;
6557
            $display("Bridge failed to process single memory write!") ;
6558
            test_fail("bridge failed to post single memory write") ;
6559
            disable main ;
6560
        end
6561
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6562
    end
6563
    begin
6564
        // wait two retries, then enable target response
6565
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6566
        if ( ok !== 1 )
6567
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6568
        else
6569
            test_ok ;
6570
 
6571
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6572
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6573
        if ( ok !== 1 )
6574
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6575
        else
6576
            test_ok ;
6577
 
6578
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6579
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6580
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6581
 
6582
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6583
        if ( ok !== 1 )
6584
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6585
        else
6586
            test_ok ;
6587
    end
6588
    join
6589
 
6590
    $display("Testing burst write transaction progress from WB to PCI!") ;
6591
    write_data`WRITE_ADDRESS = target_address ;
6592
    write_data`WRITE_DATA    = wmem_data[0] ;
6593
    write_data`WRITE_SEL     = 4'hF ;
6594
 
6595
    wishbone_master.blk_write_data[0] = write_data ;
6596
 
6597
    write_data`WRITE_ADDRESS = target_address + 4 ;
6598
    write_data`WRITE_DATA    = wmem_data[1] ;
6599
    write_data`WRITE_SEL     = 4'hF ;
6600
 
6601
    wishbone_master.blk_write_data[1] = write_data ;
6602
 
6603
    write_flags`WB_TRANSFER_SIZE = 2 ;
6604
    write_flags`WB_TRANSFER_CAB  = 1 ;
6605
 
6606
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6607
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6608
 
6609
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6610
 
6611
    fork
6612
    begin
6613
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6614
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6615
        begin
6616
            $display("Transaction progress testing failed! Time %t ", $time) ;
6617
            $display("Bridge failed to process whole CAB memory write!") ;
6618
            test_fail("bridge failed to post whole CAB memory write") ;
6619
            disable main ;
6620
        end
6621
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6622
    end
6623
    begin
6624
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6625
        if ( ok !== 1 )
6626
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6627
        else
6628
            test_ok ;
6629
 
6630
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6631
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6632
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6633
 
6634
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6635
        if ( ok !== 1 )
6636
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6637
        else
6638
            test_ok ;
6639
 
6640
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6641
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6642
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6643
 
6644
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6645
        if ( ok !== 1 )
6646
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6647
        else
6648
            test_ok ;
6649
    end
6650
    join
6651
 
6652
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6653
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6654
 
6655
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6656
    // try same write with other terminations
6657
    fork
6658
    begin
6659
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6660
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6661
        begin
6662
            $display("Transaction progress testing failed! Time %t ", $time) ;
6663
            $display("Bridge failed to process whole CAB memory write!") ;
6664
            test_fail("bridge failed to post whole CAB memory write") ;
6665
            disable main ;
6666
        end
6667
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6668
    end
6669
    begin
6670
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6671
        if ( ok !== 1 )
6672
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6673
        else
6674
            test_ok ;
6675
 
6676
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6677
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6678
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6679
 
6680
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6681
        if ( ok !== 1 )
6682
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6683
        else
6684
            test_ok ;
6685
    end
6686
    join
6687
 
6688
    // repeat the write with normal completion
6689
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6690
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6691
 
6692
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6693
    fork
6694
    begin
6695
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6696
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6697
        begin
6698
            $display("Transaction progress testing failed! Time %t ", $time) ;
6699
            $display("Bridge failed to process whole CAB memory write!") ;
6700
            test_fail("bridge failed to post whole CAB memory write") ;
6701
            disable main ;
6702
        end
6703
    end
6704
    begin
6705
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6706
        if ( ok !== 1 )
6707
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6708
        else
6709
            test_ok ;
6710
    end
6711
    join
6712
 
6713
    // do the same thing with burst length of 3
6714
    write_data`WRITE_ADDRESS = target_address + 8 ;
6715
    write_data`WRITE_DATA    = wmem_data[2] ;
6716
    write_data`WRITE_SEL     = 4'hF ;
6717
 
6718
    wishbone_master.blk_write_data[2] = write_data ;
6719
 
6720
    write_flags`WB_TRANSFER_SIZE = 3 ;
6721
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6722
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6723
 
6724
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6725
 
6726
    fork
6727
    begin
6728
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6729
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6730
        begin
6731
            $display("Transaction progress testing failed! Time %t ", $time) ;
6732
            $display("Bridge failed to process whole CAB memory write!") ;
6733
            test_fail("bridge failed to post whole CAB memory write") ;
6734
            disable main ;
6735
        end
6736
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6737
    end
6738
    begin
6739
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6740
        if ( ok !== 1 )
6741
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6742
        else
6743
            test_ok ;
6744
 
6745
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6746
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6747
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6748
 
6749
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6750
        if ( ok !== 1 )
6751
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6752
        else
6753
            test_ok ;
6754
    end
6755
    join
6756
 
6757
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6758
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6759
 
6760
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6761
    fork
6762
    begin
6763
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6764
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6765
        begin
6766
            $display("Transaction progress testing failed! Time %t ", $time) ;
6767
            $display("Bridge failed to process whole CAB memory write!") ;
6768
            test_fail("bridge failed to post whole CAB memory write") ;
6769
            disable main ;
6770
        end
6771
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6772
    end
6773
    begin
6774
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6775
        if ( ok !== 1 )
6776
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6777
        else
6778
            test_ok ;
6779
 
6780
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6781
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6782
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6783
 
6784
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6785
        if ( ok !== 1 )
6786
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6787
        else
6788
            test_ok ;
6789
 
6790
    end
6791
    join
6792
 
6793
    // repeat with normal completion
6794
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6795
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6796
 
6797
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6798
    fork
6799
    begin
6800
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6801
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6802
        begin
6803
            $display("Transaction progress testing failed! Time %t ", $time) ;
6804
            $display("Bridge failed to process whole CAB memory write!") ;
6805
            test_fail("bridge failed to post whole CAB memory write") ;
6806
            disable main ;
6807
        end
6808
    end
6809
    begin
6810
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6811
        if ( ok !== 1 )
6812
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6813
        else
6814
            test_ok ;
6815
 
6816
    end
6817
    join
6818
 
6819
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6820
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6821
    begin
6822
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6823
        write_data`WRITE_DATA    = wmem_data[i] ;
6824
        write_data`WRITE_SEL     = 4'hF ;
6825
 
6826
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6827
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6828
 
6829
        wishbone_master.blk_write_data[i]   = write_data ;
6830
        wishbone_master.blk_read_data_in[i] = read_data ;
6831
    end
6832
 
6833
    write_flags`WB_TRANSFER_CAB      = 1 ;
6834
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6835
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6836
 
6837
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6838
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6839
 
6840
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6841
    fork
6842
    begin
6843
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6844
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6845
        begin
6846
            $display("Transaction progress testing failed! Time %t ", $time) ;
6847
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6848
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6849
            test_fail("bridge failed to post whole CAB memory write") ;
6850
            disable main ;
6851
        end
6852
 
6853
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6854
 
6855
        // read here just checks if data was transfered OK
6856
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6857
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6858
 
6859
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6860
 
6861
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6862
        begin
6863
            $display("Transaction progress testing failed! Time %t ", $time) ;
6864
            $display("Bridge processed CAB read wrong!") ;
6865
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6866
        end
6867
 
6868
    end
6869
    begin
6870
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6871
        if ( ok !== 1 )
6872
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6873
        else
6874
            test_ok ;
6875
 
6876
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6877
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6878
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6879
 
6880
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6881
        if ( ok !== 1 )
6882
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6883
        else
6884
            test_ok ;
6885
 
6886
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6887
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6888
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6889
 
6890
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6891
        if ( ok !== 1 )
6892
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6893
        else
6894
            test_ok ;
6895
 
6896
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6897
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6898
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6899
 
6900
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6901
        if ( ok !== 1 )
6902
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6903
        else
6904
            test_ok ;
6905
 
6906
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6907
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6908
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6909
 
6910
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6911
        if ( ok !== 1 )
6912
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6913
        else
6914
            test_ok ;
6915
 
6916
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6917
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6918
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6919
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6920
        begin
6921
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6922
            if ( ok !== 1 )
6923
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6924
        end
6925
    end
6926
    join
6927
 
6928
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6929
    begin
6930
        read_status = wishbone_master.blk_read_data_out[i] ;
6931
        if (read_status`READ_DATA !== wmem_data[i])
6932
        begin
6933
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6934
            test_fail("data read from target wasn't the same as data written to it") ;
6935
            ok = 0 ;
6936
        end
6937
    end
6938
 
6939
    if ( ok )
6940
        test_ok ;
6941
 
6942
    $display("Testing single read transaction progress from WB to PCI!") ;
6943
    read_data`READ_ADDRESS = target_address + 8 ;
6944
    read_data`READ_SEL     = 4'hF ;
6945
 
6946
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6947
 
6948
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6949
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6950
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6951
 
6952
    fork
6953
    begin
6954
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
6955
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
6956
        begin
6957
            $display("Transaction progress testing failed! Time %t ", $time) ;
6958
            $display("Bridge processed single read wrong!") ;
6959
            test_fail("bridge processed single read wrong") ;
6960
            disable main ;
6961
        end
6962
 
6963
        if (read_status`READ_DATA !== wmem_data[2])
6964
        begin
6965
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
6966
            test_fail("data returned from single read was not as expected") ;
6967
        end
6968
        else
6969
        if ( ok )
6970
            test_ok ;
6971
    end
6972
    begin
6973
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
6974
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6975
 
6976
        if ( ok !== 1 )
6977
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6978
 
6979
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
6980
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6981
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6982
 
6983
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6984
        if ( ok !== 1 )
6985
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
6986
    end
6987
    join
6988
 
6989
    $display("Testing CAB read transaction progress from WB to PCI!") ;
6990
 
6991
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6992
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6993
 
6994
    test_name = "FILL TARGET MEMORY WITH DATA" ;
6995
    // first fill target's memory with enough data to fill WBR_FIFO
6996
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
6997
    begin
6998
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6999
        write_data`WRITE_DATA    = wmem_data[i] ;
7000
        write_data`WRITE_SEL     = 4'hF ;
7001
 
7002
        wishbone_master.blk_write_data[i] = write_data ;
7003
    end
7004
 
7005
    write_flags`WB_TRANSFER_CAB = 1 ;
7006
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7007
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7008
 
7009
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7010
 
7011
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7012
    begin
7013
        $display("Transaction progress testing failed! Time %t ", $time) ;
7014
        $display("Bridge processed CAB write wrong!") ;
7015
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7016
        disable main ;
7017
    end
7018
 
7019
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7020
    // perform single read to force write data to pci
7021
    read_data`READ_ADDRESS = target_address + 8;
7022
    read_data`READ_SEL     = 4'hF ;
7023
 
7024
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7025
 
7026
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7027
    begin
7028
        $display("Transaction progress testing failed! Time %t ", $time) ;
7029
        $display("Bridge processed single read wrong!") ;
7030
        test_fail("bridge didn't process single memory read as expected") ;
7031
        disable main ;
7032
    end
7033
 
7034
    wishbone_master.blk_read_data_in[0] = read_data ;
7035
 
7036
    read_data`READ_ADDRESS = target_address + 12 ;
7037
    read_data`READ_SEL     = 4'hF ;
7038
 
7039
    wishbone_master.blk_read_data_in[1] = read_data ;
7040
 
7041
    read_data`READ_ADDRESS = target_address + 16 ;
7042
    read_data`READ_SEL     = 4'hF ;
7043
 
7044
    wishbone_master.blk_read_data_in[2] = read_data ;
7045
 
7046
    write_flags`WB_TRANSFER_CAB  = 1 ;
7047
    write_flags`WB_TRANSFER_SIZE = 2 ;
7048
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7049
    read_status = 0 ;
7050
 
7051
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7052
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7053
 
7054
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7055
 
7056
    ok = 1 ;
7057
    fork
7058
    begin
7059
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7060
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7061
 
7062
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7063
        begin
7064
            $display("Transaction progress testing failed! Time %t ", $time) ;
7065
            $display("Bridge processed CAB read wrong!") ;
7066
            test_fail("bridge didn't process disconnected burst read as expected") ;
7067
        end
7068
        else
7069
        begin
7070
 
7071
            read_status = wishbone_master.blk_read_data_out[0] ;
7072
 
7073
            if (read_status`READ_DATA !== wmem_data[2])
7074
            begin
7075
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7076
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7077
            end
7078
            else
7079
                test_ok ;
7080
        end
7081
 
7082
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7083
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7084
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7085
 
7086
        read_status = 0 ;
7087
 
7088
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7089
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7090
 
7091
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7092
        begin
7093
            $display("Transaction progress testing failed! Time %t ", $time) ;
7094
            $display("Bridge processed CAB read wrong!") ;
7095
            test_fail("bridge didn't process disconnected burst read as expected") ;
7096
        end
7097
        else
7098
        begin
7099
 
7100
            read_status = wishbone_master.blk_read_data_out[0] ;
7101
 
7102
            if (read_status`READ_DATA !== wmem_data[3])
7103
            begin
7104
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7105
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7106
            end
7107
            else
7108
                test_ok ;
7109
        end
7110
 
7111
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7112
        // complete delayed read which was requested
7113
        read_data = wishbone_master.blk_read_data_in[2] ;
7114
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7115
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7116
 
7117
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7118
        begin
7119
            $display("Transaction progress testing failed! Time %t ", $time) ;
7120
            $display("Bridge processed single out of burst read wrong!") ;
7121
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7122
        end
7123
        else
7124
        begin
7125
 
7126
            if (read_status`READ_DATA !== wmem_data[4])
7127
            begin
7128
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7129
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7130
            end
7131
            else
7132
                test_ok ;
7133
        end
7134
 
7135
    end
7136
    begin
7137
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7138
 
7139
        if ( ok !== 1 )
7140
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7141
 
7142
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7143
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7144
 
7145
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7146
        if ( ok !== 1 )
7147
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7148
 
7149
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7150
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7151
 
7152
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7153
        if ( ok !== 1 )
7154
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7155
    end
7156
    join
7157
 
7158
    // now try burst read with normal termination
7159
    read_data`READ_ADDRESS = target_address + 12 ;
7160
    read_data`READ_SEL     = 4'hF ;
7161
 
7162
    wishbone_master.blk_read_data_in[0] = read_data ;
7163
 
7164
    read_data`READ_ADDRESS = target_address + 16 ;
7165
    read_data`READ_SEL     = 4'hF ;
7166
 
7167
    wishbone_master.blk_read_data_in[1] = read_data ;
7168
 
7169
    write_flags`WB_TRANSFER_SIZE = 2 ;
7170
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7171
    write_flags`WB_TRANSFER_CAB = 1 ;
7172
 
7173
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7174
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7175
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7176
 
7177
    fork
7178
    begin
7179
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7180
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7181
        begin
7182
            $display("Transaction progress testing failed! Time %t ", $time) ;
7183
            $display("Bridge processed CAB read wrong!") ;
7184
            test_fail("bridge didn't process burst read as expected") ;
7185
            ok = 0 ;
7186
        end
7187
    end
7188
    begin
7189
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7190
        if ( ok !== 1 )
7191
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7192
    end
7193
    join
7194
 
7195
    if ( ok )
7196
    begin
7197
        read_status = wishbone_master.blk_read_data_out[0] ;
7198
        if ( read_status`READ_DATA !== wmem_data[3] )
7199
        begin
7200
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7201
            test_fail("data provided from normaly terminated read was wrong") ;
7202
            ok = 0 ;
7203
        end
7204
 
7205
        read_status = wishbone_master.blk_read_data_out[1] ;
7206
        if ( read_status`READ_DATA !== wmem_data[4] )
7207
        begin
7208
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7209
            test_fail("data provided from normaly terminated read was wrong") ;
7210
            ok = 0 ;
7211
        end
7212
    end
7213
 
7214
    if ( ok )
7215
        test_ok ;
7216
 
7217
    // disable memory read line command and enable prefetch
7218
    // prepare image control register
7219
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7220
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7221
    if ( ok !== 1 )
7222
    begin
7223
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7224
        test_fail("WB Image Control register couldn't be written to") ;
7225
        disable main ;
7226
    end
7227
 
7228
    write_flags`WB_TRANSFER_SIZE = 4 ;
7229
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7230
    write_flags`WB_TRANSFER_CAB = 1 ;
7231
 
7232
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7233
 
7234
    for ( i = 0 ; i < 4 ; i = i + 1 )
7235
    begin
7236
        read_data`READ_ADDRESS = target_address + i*4 ;
7237
        read_data`READ_SEL     = 4'b1010 ;
7238
 
7239
        wishbone_master.blk_read_data_in[i] = read_data ;
7240
    end
7241
 
7242
    fork
7243
    begin
7244
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7245
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7246
        begin
7247
            $display("Transaction progress testing failed! Time %t ", $time) ;
7248
            $display("Bridge processed CAB read wrong!") ;
7249
            test_fail("bridge didn't process prefetched burst read as expected") ;
7250
            ok = 0 ;
7251
        end
7252
    end
7253
    begin
7254
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7255
        if ( ok !== 1 )
7256
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7257
    end
7258
    join
7259
 
7260
    if ( ok )
7261
    begin
7262
        for ( i = 0 ; i < 4 ; i = i + 1 )
7263
        begin
7264
            read_status = wishbone_master.blk_read_data_out[i] ;
7265
            if ( read_status`READ_DATA !== wmem_data[i] )
7266
            begin
7267
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7268
                test_fail("burst read returned unexpected data") ;
7269
                ok = 0 ;
7270
            end
7271
        end
7272
    end
7273
 
7274
    if ( ok )
7275
        test_ok ;
7276
 
7277
    // do one single read with different byte enables
7278
    read_data`READ_ADDRESS = target_address + 4 ;
7279
    read_data`READ_SEL     = 4'b1010 ;
7280
 
7281
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7282
    fork
7283
    begin
7284
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7285
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7286
        begin
7287
            $display("Transaction progress testing failed! Time %t ", $time) ;
7288
            $display("Bridge processed single read wrong!") ;
7289
            test_fail("bridge didn't process single memory read as expected") ;
7290
            ok = 0 ;
7291
        end
7292
    end
7293
    begin
7294
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7295
        if ( ok !== 1 )
7296
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7297
    end
7298
    join
7299
 
7300
    // check read data
7301
    if ( ok )
7302
    begin
7303
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7304
        begin
7305
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7306
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7307
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7308
            ok = 0 ;
7309
            test_fail("unexpected data received from single read") ;
7310
        end
7311
    end
7312
 
7313
    if ( ok )
7314
         test_ok ;
7315
 
7316
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7317
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7318
 
7319
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7320
    if ( ok !== 1 )
7321
    begin
7322
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7323
        test_fail("WB Image Control register could not be written") ;
7324
        disable main ;
7325
    end
7326
 
7327
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7328
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7329
    begin
7330
        read_data`READ_ADDRESS = target_address + i*4 ;
7331
        read_data`READ_SEL     = 4'b1111 ;
7332
 
7333
        wishbone_master.blk_read_data_in[i] = read_data ;
7334
    end
7335
 
7336
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7337
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7338
    write_flags`WB_TRANSFER_CAB = 1 ;
7339
 
7340
    fork
7341
    begin
7342
        read_status         = 0 ;
7343
        read_status`CYC_RTY = 1 ;
7344
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7345
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7346
 
7347
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7348
        begin
7349
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7350
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7351
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7352
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7353
            ok = 0 ;
7354
        end
7355
    end
7356
    begin
7357
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7358
        if ( ok !== 1 )
7359
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7360
    end
7361
    join
7362
 
7363
    // now repeat single read to flush redundant read initiated
7364
    write_flags`WB_TRANSFER_SIZE = 1 ;
7365
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7366
    write_flags`WB_TRANSFER_CAB = 1 ;
7367
 
7368
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7369
    read_data`READ_SEL     = 4'hF ;
7370
 
7371
    wishbone_master.blk_read_data_in[0] = read_data ;
7372
 
7373
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7374
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7375
 
7376
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7377
    begin
7378
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7379
        $display(" PCI bridge failed to process single CAB read!") ;
7380
        test_fail("single CAB write was not processed as expected") ;
7381
    end
7382
 
7383
    // because last read could be very long on PCI - delete target abort status
7384
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7385
 
7386
    // write unsupported value to cache line size register
7387
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7388
 
7389
    read_data`READ_ADDRESS = target_address ;
7390
    read_data`READ_SEL     = 4'hF ;
7391
    wishbone_master.blk_read_data_in[0] = read_data ;
7392
 
7393
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7394
    // perform a read
7395
    fork
7396
    begin
7397
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7398
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7399
        begin
7400
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7401
            $display(" PCI bridge failed to process single CAB read!") ;
7402
            test_fail("burst read was not processed as expected") ;
7403
            ok = 0 ;
7404
        end
7405
    end
7406
    begin
7407
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7408
        if ( ok !== 1 )
7409
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7410
    end
7411
    join
7412
 
7413
    if ( ok )
7414
        test_ok ;
7415
 
7416
    // write 2 to cache line size register
7417
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7418
 
7419
    // perform a read
7420
    fork
7421
    begin
7422
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7423
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7424
        begin
7425
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7426
            $display(" PCI bridge failed to process single CAB read!") ;
7427
            test_fail("burst read was not processed as expected") ;
7428
            ok = 0 ;
7429
        end
7430
    end
7431
    begin
7432
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7433
        if ( ok !== 1 )
7434
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7435
    end
7436
    join
7437
 
7438
    if ( ok )
7439
        test_ok ;
7440
 
7441
    // write 0 to cache line size
7442
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7443
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7444
 
7445
    // perform a read
7446
    fork
7447
    begin
7448
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7449
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7450
        begin
7451
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7452
            $display(" PCI bridge failed to process single CAB read!") ;
7453
            test_fail("burst read was not processed as expected") ;
7454
            ok = 0 ;
7455
        end
7456
    end
7457
    begin
7458
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7459
        if ( ok !== 1 )
7460
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7461
    end
7462
    join
7463
 
7464
    if ( ok )
7465
        test_ok ;
7466
 
7467
    // write normal value to cls register
7468
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7469
 
7470
    $display("Testing Master's latency timer operation!") ;
7471
    $display("Testing Latency timer during Master Writes!") ;
7472
 
7473
    for ( i = 0 ; i < 6 ; i = i + 1 )
7474
    begin
7475
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7476
        write_data`WRITE_SEL     = 4'b1111 ;
7477
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7478
 
7479
        wishbone_master.blk_write_data[i] = write_data ;
7480
    end
7481
 
7482
    write_flags`WB_TRANSFER_SIZE = 6 ;
7483
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7484
    write_flags`WB_TRANSFER_CAB = 1 ;
7485
 
7486
    // start wb write, pci write and monitor in parallel
7487
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7488
    fork
7489
    begin
7490
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7491
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7492
        begin
7493
            $display("Transaction progress testing failed! Time %t ", $time) ;
7494
            $display("Bridge failed to process CAB write!") ;
7495
            test_fail("bridge didn't post whole burst memory write") ;
7496
            disable main ;
7497
        end
7498
    end
7499
    begin
7500
        // wait for bridge's master to start transaction
7501
        @(posedge pci_clock) ;
7502
        while ( FRAME === 1 )
7503
            @(posedge pci_clock) ;
7504
 
7505
        // start behavioral master request
7506
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7507
               target_address, wmem_data[1023], `Test_All_Bytes,
7508
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7509
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7510
 
7511
        do_pause ( 1 ) ;
7512
    end
7513
    begin
7514
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7515
        if ( ok !== 1 )
7516
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7517
        else
7518
            test_ok ;
7519
    end
7520
    join
7521
 
7522
    // perform a read to check data
7523
    for ( i = 0 ; i < 6 ; i = i + 1 )
7524
    begin
7525
        read_data`READ_ADDRESS = target_address + i*4 ;
7526
        read_data`READ_SEL     = 4'b1111 ;
7527
 
7528
        wishbone_master.blk_read_data_in[i] = read_data ;
7529
    end
7530
 
7531
    write_flags`WB_TRANSFER_SIZE = 6 ;
7532
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7533
    write_flags`WB_TRANSFER_CAB = 1 ;
7534
 
7535
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7536
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7537
 
7538
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7539
    begin
7540
        $display("Transaction progress testing failed! Time %t ", $time) ;
7541
        $display("Bridge failed to process CAB read!") ;
7542
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7543
        disable main ;
7544
    end
7545
 
7546
    ok = 1 ;
7547
    for ( i = 0 ; i < 6 ; i = i + 1 )
7548
    begin
7549
        read_status = wishbone_master.blk_read_data_out[i] ;
7550
 
7551
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7552
        begin
7553
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7554
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7555
            test_fail("unexpected data read back from PCI") ;
7556
            ok = 0 ;
7557
        end
7558
    end
7559
 
7560
    if ( ok )
7561
        test_ok ;
7562
 
7563
    $display("Testing Latency timer during Master Reads!") ;
7564
 
7565
    // at least 2 words are transfered during Master Reads terminated with timeout
7566
    write_flags`WB_TRANSFER_SIZE = 2 ;
7567
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7568
    fork
7569
    begin
7570
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7571
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7572
        begin
7573
            $display("Transaction progress testing failed! Time %t ", $time) ;
7574
            $display("Bridge failed to process CAB read!") ;
7575
            test_fail("bridge didn't process burst read as expected") ;
7576
            ok = 0 ;
7577
        end
7578
    end
7579
    begin
7580
        // wait for bridge's master to start transaction
7581
        @(posedge pci_clock) ;
7582
        while ( FRAME === 1 )
7583
            @(posedge pci_clock) ;
7584
 
7585
        // start behavioral master request
7586
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7587
               target_address, wmem_data[0], `Test_All_Bytes,
7588
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7589
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7590
 
7591
        do_pause ( 1 ) ;
7592
    end
7593
    begin
7594
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7595
        if ( ok !== 1 )
7596
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7597
    end
7598
    join
7599
 
7600
    // check data provided by target
7601
    if ( ok )
7602
    begin
7603
        for ( i = 0 ; i < 2 ; i = i + 1 )
7604
        begin
7605
            read_status = wishbone_master.blk_read_data_out[i] ;
7606
 
7607
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7608
            begin
7609
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7610
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7611
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7612
                ok = 0 ;
7613
            end
7614
        end
7615
    end
7616
    if ( ok )
7617
        test_ok ;
7618
 
7619
    test_name = "DISABLE_IMAGE" ;
7620
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7621
    if ( ok !== 1 )
7622
    begin
7623
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7624
        test_fail("write to WB Address Mask register failed") ;
7625
        disable main ;
7626
    end
7627
 
7628
end
7629
endtask //wb_to_pci_transactions
7630
 
7631
task iack_cycle ;
7632
    reg `READ_STIM_TYPE   read_data ;
7633
    reg `READ_RETURN_TYPE read_status ;
7634
    reg `WB_TRANSFER_FLAGS flags ;
7635
 
7636
    reg [31:0] temp_var ;
7637
    reg ok ;
7638 45 mihad
    reg ok_wb ;
7639
    reg ok_pci ;
7640
 
7641
    reg [31:0] irq_vector ;
7642 15 mihad
begin
7643
 
7644 45 mihad
    ok     = 1 ;
7645
    ok_wb  = 1 ;
7646
    ok_pci = 1 ;
7647
 
7648 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7649
 
7650
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7651
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7652
 
7653
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7654
    read_data`READ_SEL     = 4'hF ;
7655
 
7656
    flags = 0 ;
7657
 
7658
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7659
 
7660
    irq_vector  = 32'hAAAA_AAAA ;
7661
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7662
 
7663 45 mihad
    // disable both pci blue behavioral targets
7664
    configuration_cycle_write
7665
    (
7666
        0,                          // bus number [7:0]
7667
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7668
        0,                          // function number [2:0]
7669
        1,                          // register number [5:0]
7670
        0,                          // type [1:0]
7671
        4'h1,                       // byte enables [3:0]
7672
        32'h0000_0044               // data to write [31:0]
7673
    ) ;
7674
 
7675
    configuration_cycle_write
7676
    (
7677
        0,                          // bus number [7:0]
7678
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7679
        0,                          // function number [2:0]
7680
        1,                          // register number [5:0]
7681
        0,                          // type [1:0]
7682
        4'h1,                       // byte enables [3:0]
7683
        32'h0000_0044               // data to write [31:0]
7684
    ) ;
7685
 
7686 15 mihad
    fork
7687
    begin
7688
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7689
    end
7690
    begin
7691 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7692
        if ( ok_pci !== 1 )
7693 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7694
    end
7695
    join
7696
 
7697
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7698
    begin
7699 45 mihad
        ok_wb = 0 ;
7700 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7701
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7702
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7703
    end
7704 45 mihad
 
7705
    if ( ok_pci && ok_wb )
7706 15 mihad
        test_ok ;
7707 45 mihad
 
7708
    ok_wb = 1 ;
7709
    ok_pci = 1 ;
7710
    ok = 1 ;
7711 15 mihad
 
7712 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7713
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7714 15 mihad
 
7715
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7716 45 mihad
    // enable pci blue behavioral target 1
7717
    configuration_cycle_write
7718
    (
7719
        0,                          // bus number [7:0]
7720
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7721
        0,                          // function number [2:0]
7722
        1,                          // register number [5:0]
7723
        0,                          // type [1:0]
7724
        4'h1,                       // byte enables [3:0]
7725
        32'h0000_0047               // data to write [31:0]
7726
    ) ;
7727 15 mihad
    fork
7728
    begin
7729
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7730
    end
7731
    begin
7732 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7733
        if ( ok_pci !== 1 )
7734 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7735
    end
7736
    join
7737
 
7738
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7739
    begin
7740 45 mihad
        ok_wb = 0 ;
7741 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7742
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7743
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7744
    end
7745
 
7746
    if ( read_status`READ_DATA !== irq_vector )
7747
    begin
7748
        $display(" Time %t ", $time ) ;
7749
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7750
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7751 45 mihad
        ok_wb = 0 ;
7752 15 mihad
    end
7753
 
7754 45 mihad
    if ( ok_pci && ok_wb )
7755 15 mihad
        test_ok ;
7756
 
7757 45 mihad
    ok_pci = 1 ;
7758
    ok_wb  = 1 ;
7759
    ok     = 1 ;
7760
 
7761 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7762 45 mihad
    irq_vector  = 32'h5555_5555 ;
7763
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7764
 
7765 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7766
    fork
7767
    begin
7768
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7769
    end
7770
    begin
7771 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7772
        if ( ok_pci !== 1 )
7773 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7774
    end
7775
    join
7776
 
7777
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7778
    begin
7779
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7780
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7781
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7782 45 mihad
        ok_wb = 0 ;
7783 15 mihad
    end
7784
 
7785 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7786 15 mihad
    begin
7787
        $display(" Time %t ", $time ) ;
7788 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7789 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7790 45 mihad
        ok_wb = 0 ;
7791 15 mihad
    end
7792
 
7793 45 mihad
    if (ok_pci && ok_wb)
7794 15 mihad
        test_ok ;
7795
 
7796 45 mihad
    ok_pci = 1 ;
7797
    ok_wb  = 1 ;
7798
    ok     = 1 ;
7799 15 mihad
 
7800 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7801
 
7802
    // set target to terminate with target abort
7803
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7804
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7805
 
7806
    fork
7807
    begin
7808
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7809
    end
7810
    begin
7811
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7812
        if ( ok_pci !== 1 )
7813
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7814
    end
7815
    join
7816
 
7817
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7818
    begin
7819
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7820
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7821
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7822
        ok_wb = 0 ;
7823
    end
7824
 
7825
    // set target to terminate with target abort
7826
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7827
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7828
 
7829
    // enable pci blue behavioral target 2
7830
    configuration_cycle_write
7831
    (
7832
        0,                          // bus number [7:0]
7833
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7834
        0,                          // function number [2:0]
7835
        1,                          // register number [5:0]
7836
        0,                          // type [1:0]
7837
        4'h1,                       // byte enables [3:0]
7838
        32'h0000_0047               // data to write [31:0]
7839
    ) ;
7840
 
7841
    // read PCI Device status
7842
    config_read(12'h4, 4'hC, temp_var) ;
7843
    if (temp_var[29] !== 1)
7844
    begin
7845
        $display("Time %t", $time) ;
7846
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7847
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7848
        ok_wb = 0 ;
7849
    end
7850
 
7851
    if (temp_var[28] !== 1)
7852
    begin
7853
        $display("Time %t", $time) ;
7854
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7855
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7856
        ok_wb = 0 ;
7857
    end
7858
 
7859
    // clearing the status bits
7860
        config_write(12'h4, temp_var, 4'hC, ok);
7861
 
7862
    if ( ok && ok_pci && ok_wb )
7863
        test_ok ;
7864
 
7865 15 mihad
end
7866
endtask //iack_cycle
7867
 
7868
task transaction_ordering ;
7869
    reg   [11:0] wb_ctrl_offset ;
7870
    reg   [11:0] wb_ba_offset ;
7871
    reg   [11:0] wb_am_offset ;
7872
    reg   [11:0] pci_ctrl_offset ;
7873
    reg   [11:0] pci_ba_offset ;
7874
    reg   [11:0] pci_am_offset ;
7875
    reg   [11:0] pci_device_ctrl_offset ;
7876
    reg   [11:0] wb_err_cs_offset ;
7877
    reg   [11:0] pci_err_cs_offset ;
7878
    reg   [11:0] icr_offset ;
7879
    reg   [11:0] isr_offset ;
7880
    reg   [11:0] lat_tim_cls_offset ;
7881
 
7882
    reg `WRITE_STIM_TYPE  write_data ;
7883
    reg `READ_STIM_TYPE   read_data ;
7884
    reg `READ_RETURN_TYPE read_status ;
7885
 
7886
    reg `WRITE_RETURN_TYPE write_status ;
7887
    reg `WB_TRANSFER_FLAGS write_flags ;
7888
    reg [31:0] temp_val1 ;
7889
    reg [31:0] temp_val2 ;
7890
    reg        ok   ;
7891
 
7892
    reg [31:0] wb_image_base ;
7893
    reg [31:0] wb_target_address ;
7894
    reg [31:0] pci_image_base ;
7895
    integer i ;
7896
 
7897
    reg     error_monitor_done ;
7898
begin:main
7899
    write_flags`INIT_WAITS = tb_init_waits ;
7900
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7901
 
7902
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7903
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7904
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7905
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7906
 
7907
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7908
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7909
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7910
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7911
 
7912
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7913
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7914
    lat_tim_cls_offset = 12'hC ;
7915
    pci_device_ctrl_offset    = 12'h4 ;
7916
 
7917
    wb_target_address  = `BEH_TAR1_MEM_START ;
7918
    wb_image_base      = 0 ;
7919
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7920
 
7921
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7922
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7923
    write_flags                    = 0 ;
7924
    write_flags`INIT_WAITS         = 0 ;
7925
    write_flags`SUBSEQ_WAITS       = 0 ;
7926
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7927
 
7928
    pci_image_base = Target_Base_Addr_R[1] ;
7929
 
7930
    // enable master & target operation
7931
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7932
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7933
    if ( ok !== 1 )
7934
    begin
7935
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7936
        test_fail("write to PCI Device Control register failed") ;
7937
        disable main ;
7938
    end
7939
 
7940
    // prepare image control register
7941
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7942
    if ( ok !== 1 )
7943
    begin
7944
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7945
        test_fail("write to WB Image Control register failed") ;
7946
        disable main ;
7947
    end
7948
 
7949
    // prepare base address register
7950
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
7951
    if ( ok !== 1 )
7952
    begin
7953
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
7954
        test_fail("write to WB Base Address register failed") ;
7955
        disable main ;
7956
    end
7957
 
7958
    // write address mask register
7959
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7960
    if ( ok !== 1 )
7961
    begin
7962
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7963
        test_fail("write to WB Address Mask register failed") ;
7964
        disable main ;
7965
    end
7966
 
7967
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
7968
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7969
    if ( ok !== 1 )
7970
    begin
7971
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
7972
        test_fail("write to WB Error Control and Status register failed") ;
7973
        disable main ;
7974
    end
7975
 
7976
    // prepare image control register
7977
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7978
    if ( ok !== 1 )
7979
    begin
7980
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
7981
        test_fail("write to PCI Image Control register failed") ;
7982
        disable main ;
7983
    end
7984
 
7985
    // prepare base address register
7986
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
7987
    if ( ok !== 1 )
7988
    begin
7989
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
7990
        test_fail("write to PCI Base Address register failed") ;
7991
        disable main ;
7992
    end
7993
 
7994
    // write address mask register
7995
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
7996
    if ( ok !== 1 )
7997
    begin
7998
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
7999
        test_fail("write to PCI Address Mask register failed") ;
8000
        disable main ;
8001
    end
8002
 
8003
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8004
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8005
    if ( ok !== 1 )
8006
    begin
8007
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8008
        test_fail("write to PCI Error Control and Status register failed") ;
8009
        disable main ;
8010
    end
8011
 
8012
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8013
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8014
    if ( ok !== 1 )
8015
    begin
8016
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8017
        test_fail("write to Interrupt Control register failed") ;
8018
        disable main ;
8019
    end
8020
 
8021
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8022
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8023
    if ( ok !== 1 )
8024
    begin
8025
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8026
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8027
        disable main ;
8028
    end
8029
 
8030
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8031
 
8032
    // prepare wb_master write and read data
8033
    for ( i = 0 ; i < 4 ; i = i + 1 )
8034
    begin
8035
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8036
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8037
        write_data`WRITE_SEL     = 4'hF ;
8038
 
8039
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8040
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8041
 
8042
        wishbone_master.blk_write_data[i]   = write_data ;
8043
        wishbone_master.blk_read_data_in[i] = read_data ;
8044
    end
8045
 
8046
    // put wishbone slave in acknowledge and pci target in retry mode
8047
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8048
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8049
 
8050
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8051
 
8052
    fork
8053
    begin
8054
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8055
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8056
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8057
        begin
8058
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8059
            test_fail("Bridge didn't post single memory write as expected") ;
8060
        end
8061
 
8062
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8063
        if ( ok !== 1 )
8064
        begin
8065
            $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) ;
8066
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8067
            ok = 0 ;
8068
        end
8069
 
8070
        // now post single write to target - normal progress
8071
        if ( target_mem_image == 1 )
8072
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8073
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8074
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8075
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8076
        else
8077
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8078
 
8079
        do_pause( 1 ) ;
8080
 
8081
    end
8082
    begin:error_monitor_1
8083 35 mihad
        error_monitor_done = 0 ;
8084 15 mihad
        @(error_event_int) ;
8085
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8086
        ok = 0 ;
8087 35 mihad
        error_monitor_done = 1 ;
8088 15 mihad
    end
8089
    begin
8090
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8091
        if ( ok !== 1 )
8092
        begin
8093
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8094
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8095
        end
8096
        else
8097
        begin
8098 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8099
//            while ( FRAME === 0 || IRDY === 0 )
8100
//                @(posedge pci_clock) ;
8101 15 mihad
 
8102
            // enable response in PCI target
8103
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8104
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8105
 
8106
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8107
            if ( ok !== 1 )
8108
            begin
8109
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8110
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8111
            end
8112
        end
8113
 
8114 35 mihad
        #1 ;
8115
        if ( !error_monitor_done )
8116
            disable error_monitor_1 ;
8117 15 mihad
    end
8118
    join
8119
 
8120
    if ( ok )
8121
        test_ok ;
8122
 
8123
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8124
 
8125
    // put WISHBONE slave in retry mode
8126
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8127
 
8128
    fork
8129
    begin
8130
        // now post single write to target - normal progress
8131
        if ( target_mem_image == 1 )
8132
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8133
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8134
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8135
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8136
        else
8137
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8138
 
8139
        do_pause( 1 ) ;
8140
 
8141
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8142
        if ( ok !== 1 )
8143
        begin
8144
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8145
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8146
        end
8147
 
8148
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8149
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8150
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8151
        begin
8152
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8153
            test_fail("Bridge didn't post single memory write as expected") ;
8154
        end
8155
 
8156
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8157
        if ( ok !== 1 )
8158
        begin
8159
            $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) ;
8160
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8161
            ok = 0 ;
8162
        end
8163
 
8164
        wait ( CYC_O === 0 ) ;
8165
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8166
 
8167
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8168
        if ( ok !== 1 )
8169
        begin
8170
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8171
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8172
        end
8173
 
8174 35 mihad
        #1 ;
8175
        if ( !error_monitor_done )
8176
            disable error_monitor_2 ;
8177 15 mihad
    end
8178
    begin:error_monitor_2
8179 35 mihad
        error_monitor_done = 0 ;
8180 15 mihad
        @(error_event_int) ;
8181
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8182
        ok = 0 ;
8183 35 mihad
        error_monitor_done = 1 ;
8184 15 mihad
    end
8185
    join
8186
 
8187
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8188
 
8189
    // put wishbone slave in acknowledge and pci target in retry mode
8190
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8191
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8192
 
8193
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8194
 
8195
    fork
8196
    begin
8197
        write_flags`WB_TRANSFER_SIZE = 3 ;
8198
        write_flags`WB_TRANSFER_CAB  = 1 ;
8199
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8200
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8201
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8202
        begin
8203
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8204
            test_fail("Bridge didn't post burst memory write as expected") ;
8205
        end
8206
 
8207
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8208
        if ( ok !== 1 )
8209
        begin
8210
            $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) ;
8211
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8212
            ok = 0 ;
8213
        end
8214
 
8215
        // now post single write to target - normal progress
8216
        if ( target_mem_image == 1 )
8217
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8218
                        pci_image_base, 32'h5555_5555, 4'h0,
8219
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8220
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8221
        else
8222
        begin
8223
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8224
            do_pause( 1 ) ;
8225
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8226
        end
8227
 
8228
        do_pause( 1 ) ;
8229
 
8230
    end
8231
    begin:error_monitor_3
8232 35 mihad
        error_monitor_done = 0 ;
8233 15 mihad
        @(error_event_int) ;
8234
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8235
        ok = 0 ;
8236 35 mihad
        error_monitor_done = 1 ;
8237 15 mihad
    end
8238
    begin
8239
        if ( target_mem_image == 1 )
8240
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8241
        else
8242
        begin
8243
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8244
            if ( ok )
8245
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8246
        end
8247
 
8248
        if ( ok !== 1 )
8249
        begin
8250
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8251
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8252
        end
8253
        else
8254
        begin
8255 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8256
//            while ( FRAME === 0 || IRDY === 0 )
8257
//                @(posedge pci_clock) ;
8258 15 mihad
 
8259
            // enable response in PCI target
8260
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8261
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8262
 
8263
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8264
            if ( ok !== 1 )
8265
            begin
8266
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8267
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8268
            end
8269
        end
8270
 
8271 35 mihad
        #1 ;
8272
        if ( !error_monitor_done )
8273
            disable error_monitor_3 ;
8274 15 mihad
    end
8275
    join
8276
 
8277
    if ( ok )
8278
        test_ok ;
8279
 
8280
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8281
 
8282
    // put WISHBONE slave in retry mode
8283
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8284
 
8285
    fork
8286
    begin
8287
        // now post single write to target - normal progress
8288
        if ( target_mem_image == 1 )
8289
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8290
                        pci_image_base, 32'h5555_5555, 4'h0,
8291
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8292
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8293
        else
8294
        begin
8295
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8296
            do_pause( 1 ) ;
8297
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8298
        end
8299
 
8300
        do_pause( 1 ) ;
8301
 
8302
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8303
 
8304
        if ( ok !== 1 )
8305
        begin
8306
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8307
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8308
        end
8309
 
8310
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8311
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8312
        write_flags`WB_TRANSFER_CAB      = 1 ;
8313
 
8314
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8315
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8316
        begin
8317
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8318
            test_fail("Bridge didn't post burst memory write as expected") ;
8319
        end
8320
 
8321
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8322
        if ( ok !== 1 )
8323
        begin
8324
            $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) ;
8325
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8326
            ok = 0 ;
8327
        end
8328
 
8329
        @(posedge wb_clock) ;
8330
        while ( CYC_O === 1 )
8331
            @(posedge wb_clock) ;
8332
 
8333
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8334
 
8335
        if ( target_mem_image == 1 )
8336
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8337
        else
8338
        begin
8339
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8340
            if ( ok )
8341
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8342
        end
8343
 
8344 35 mihad
        #1 ;
8345
        if ( !error_monitor_done )
8346
            disable error_monitor_4 ;
8347 15 mihad
    end
8348
    begin:error_monitor_4
8349 35 mihad
        error_monitor_done = 0 ;
8350 15 mihad
        @(error_event_int) ;
8351
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8352
        ok = 0 ;
8353 35 mihad
        error_monitor_done = 1 ;
8354 15 mihad
    end
8355
    join
8356
 
8357
    if ( ok )
8358
        test_ok ;
8359
 
8360
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8361
 
8362
    // put wishbone slave in acknowledge and pci target in retry mode
8363
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8364
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8365
 
8366
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8367
 
8368
    master1_check_received_data = 1 ;
8369
 
8370
    error_monitor_done = 0 ;
8371
    fork
8372
    begin:error_monitor_5
8373
        @(error_event_int or error_monitor_done) ;
8374
        if ( !error_monitor_done )
8375
        begin
8376
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8377
            ok = 0 ;
8378
        end
8379
    end
8380
    begin
8381
 
8382
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8383
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8384
        begin
8385
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8386
            test_fail("Bridge didn't post single memory write as expected") ;
8387
        end
8388
 
8389
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8390
        if ( ok !== 1 )
8391
        begin
8392
            $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) ;
8393
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8394
            ok = 0 ;
8395
        end
8396
 
8397
        // start Read Through pci target
8398
        if ( target_mem_image == 1 )
8399
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8400
                          pci_image_base, 32'h5555_5555,
8401
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8402
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8403
        else
8404
            PCIU_IO_READ
8405
             (
8406
                `Test_Master_1,
8407
                pci_image_base,
8408
                32'h5555_5555,
8409
                4'h0,
8410
                1,
8411
                `Test_Target_Retry_On
8412
             );
8413
 
8414
         do_pause( 1 ) ;
8415
 
8416
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8417
         if ( ok !== 1 )
8418
         begin
8419
            $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) ;
8420
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8421
         end
8422
 
8423
         // repeat the read 4 times - it should be retried all the time by pci target
8424
        for ( i = 0 ; i < 4 ; i = i + 1 )
8425
        begin
8426
            if ( target_mem_image == 1 )
8427
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8428
                            pci_image_base, 32'h5555_5555,
8429
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8430
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8431
            else
8432
                PCIU_IO_READ
8433
                (
8434
                    `Test_Master_1,
8435
                    pci_image_base,
8436
                    32'h5555_5555,
8437
                    4'h0,
8438
                    1,
8439
                    `Test_Target_Retry_On
8440
                );
8441
 
8442
            do_pause( 1 ) ;
8443
        end
8444
 
8445
        // now do posted write through target - it must go through OK
8446
        if ( target_mem_image == 1 )
8447
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8448
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8449
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8450
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8451
        else
8452
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8453
 
8454
        do_pause( 1 ) ;
8455
 
8456
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8457
        if ( ok !== 1 )
8458
        begin
8459
           $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) ;
8460
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8461
        end
8462
 
8463
        // start a read through wb_slave
8464
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8465
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8466
        begin
8467
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8468
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8469
            ok = 0 ;
8470
        end
8471
 
8472 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8473
//        while ( FRAME === 0 || IRDY === 0 )
8474
//            @(posedge pci_clock) ;
8475 15 mihad
 
8476
        // set the target to normal completion
8477
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8478
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8479
 
8480
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8481
        if ( ok !== 1 )
8482
        begin
8483
            $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) ;
8484
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8485
            ok = 0 ;
8486
        end
8487
 
8488
        // now wait for delayed read to finish
8489
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8490
        if ( ok !== 1 )
8491
        begin
8492
            $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) ;
8493
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8494
            ok = 0 ;
8495
        end
8496
 
8497
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8498
        fork
8499
        begin
8500
                if ( target_mem_image == 1 )
8501
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8502
                                pci_image_base, 32'h5555_5555, 4'h0,
8503
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8504
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8505
                else
8506
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8507
 
8508
                do_pause( 1 ) ;
8509
                end
8510
                begin
8511
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8512
                end
8513
                join
8514
 
8515
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8516
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8517
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8518
        begin
8519
            $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) ;
8520
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8521
            ok = 0 ;
8522
        end
8523
 
8524
        fork
8525
        begin
8526
        // now complete a read from PCI Target
8527
            if ( target_mem_image == 1 )
8528
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8529
                            pci_image_base, 32'h5555_5555,
8530
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8531
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8532
            else
8533
                PCIU_IO_READ
8534
                (
8535
                    `Test_Master_1,
8536
                    pci_image_base,
8537
                    32'h5555_5555,
8538
                    4'h0,
8539
                    1,
8540
                    `Test_Target_Normal_Completion
8541
                );
8542
 
8543
            do_pause( 1 ) ;
8544
        end
8545
        begin
8546
            if ( target_mem_image == 1 )
8547
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8548
            else
8549
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8550
        end
8551
        join
8552
 
8553
        @(posedge pci_clock) ;
8554
        repeat( 4 )
8555
            @(posedge wb_clock) ;
8556
 
8557
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8558
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8559
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8560
        begin
8561
            $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) ;
8562
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8563
            ok = 0 ;
8564
        end
8565
 
8566
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8567
        if ( ok !== 1 )
8568
        begin
8569
            $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) ;
8570
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8571
            ok = 0 ;
8572
        end
8573
 
8574
        // finish a read on WISHBONE also
8575
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8576
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8577
        begin
8578
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8579
            test_fail("WB Slave didn't process single delayed read as expected") ;
8580
        end
8581
 
8582
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8583
        begin
8584
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8585
            ok = 0 ;
8586
        end
8587
 
8588
 
8589
        error_monitor_done = 1 ;
8590
    end
8591
    join
8592
 
8593
    if ( ok )
8594
        test_ok ;
8595
 
8596
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8597
 
8598
    // put wishbone slave in retry and pci target in completion mode
8599
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8600
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8601
 
8602
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8603
 
8604
    master1_check_received_data = 1 ;
8605
 
8606
    error_monitor_done = 0 ;
8607
    fork
8608
    begin:error_monitor_6
8609
        @(error_event_int or error_monitor_done) ;
8610
        if ( !error_monitor_done )
8611
        begin
8612
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8613
            ok = 0 ;
8614
        end
8615
    end
8616
    begin
8617
 
8618
        // do a write through Target
8619
        fork
8620
        begin
8621
            if ( target_mem_image == 1 )
8622
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8623
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8624
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8625
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8626
            else
8627
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8628
 
8629
            do_pause( 1 ) ;
8630
        end
8631
        begin
8632
            if ( target_mem_image == 1 )
8633
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8634
            else
8635
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8636
        end
8637
        join
8638
 
8639
        // start a read through WB slave
8640
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8641
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8642
        begin
8643
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8644
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8645
            ok = 0 ;
8646
        end
8647
 
8648
        // now wait for this read to finish on pci
8649
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8650
        if ( ok !== 1 )
8651
        begin
8652
            $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) ;
8653
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8654
            ok = 0 ;
8655
        end
8656
 
8657
        // repeat the read four times - it should be retried
8658
        for ( i = 0 ; i < 4 ; i = i + 1 )
8659
        begin
8660
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8661
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8662
            begin
8663
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8664
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8665
                ok = 0 ;
8666
            end
8667
        end
8668
 
8669
        // posted write through WB Slave - must go through
8670
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8671
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8672
        begin
8673
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8674
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8675
            ok = 0 ;
8676
        end
8677
 
8678
        // write must come through
8679
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8680
        if ( ok !== 1 )
8681
        begin
8682
            $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) ;
8683
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8684
            ok = 0 ;
8685
        end
8686
 
8687
        // do a read through pci target
8688
        if ( target_mem_image == 1 )
8689
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8690
                          pci_image_base + 12, 32'hDEAD_BEAF,
8691
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8692
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8693
        else
8694
            PCIU_IO_READ
8695
             (
8696
                `Test_Master_1,
8697
                pci_image_base + 12,
8698
                32'hDEAD_BEAF,
8699
                4'h0,
8700
                1,
8701
                `Test_Target_Retry_On
8702
             );
8703
 
8704
         do_pause( 1 ) ;
8705
 
8706
        // wait for current cycle to finish on WB
8707 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8708
//        @(posedge wb_clock) ;
8709
//        while( CYC_O === 1 )
8710
//            @(posedge wb_clock) ;
8711 15 mihad
 
8712
        // set slave response to acknowledge
8713
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8714
 
8715
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8716
        if ( ok !== 1 )
8717
        begin
8718
            $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) ;
8719
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8720
        end
8721
 
8722
        // check the read to finish on wb
8723
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8724
        if ( ok !== 1 )
8725
        begin
8726
            $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) ;
8727
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8728
        end
8729
 
8730
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8731
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8732
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8733
        begin
8734
            $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) ;
8735
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8736
            ok = 0 ;
8737
        end
8738
 
8739
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8740
        fork
8741
        begin
8742
            if ( target_mem_image == 1 )
8743
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8744
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8745
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8746
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8747
            else
8748
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8749
        end
8750
        begin
8751
            if ( target_mem_image == 1 )
8752
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8753
            else
8754
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8755
        end
8756
        join
8757
 
8758
        do_pause( 1 ) ;
8759
 
8760
        // complete a read in WB Slave Unit
8761
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8762
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8763
        begin
8764
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8765
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8766
            ok = 0 ;
8767
        end
8768
 
8769
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8770
        begin
8771
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8772
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8773
            ok = 0 ;
8774
        end
8775
 
8776
        // wait for statuses to be propagated from one side of bridge to another
8777
        repeat( 4 )
8778
            @(posedge pci_clock) ;
8779
 
8780
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8781
        fork
8782
        begin
8783
            if ( target_mem_image == 1 )
8784
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8785
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8786
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8787
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8788
            else
8789
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8790
 
8791
            do_pause( 1 ) ;
8792
        end
8793
        begin
8794
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8795
            if ( ok !== 1 )
8796
            begin
8797
                $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) ;
8798
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8799
            end
8800
        end
8801
        join
8802
 
8803
        // finish the last read in PCI Target Unit
8804
        if ( target_mem_image == 1 )
8805
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8806
                          pci_image_base + 12, 32'hDEAD_BEAF,
8807
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8808
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8809
        else
8810
            PCIU_IO_READ
8811
             (
8812
                `Test_Master_1,
8813
                pci_image_base + 12,
8814
                32'hDEAD_BEAF,
8815
                4'h0,
8816
                1,
8817
                `Test_Target_Normal_Completion
8818
             );
8819
 
8820
         do_pause( 1 ) ;
8821
 
8822
         error_monitor_done = 1 ;
8823
    end
8824
    join
8825
 
8826
    if ( ok )
8827
        test_ok ;
8828
 
8829
end
8830
endtask // transaction_ordering
8831
 
8832
task pci_transaction_progress_monitor ;
8833
    input [31:0] address ;
8834
    input [3:0]  bus_command ;
8835
    input [31:0] num_of_transfers ;
8836
    input [31:0] num_of_cycles ;
8837
    input check_transfers ;
8838
    input check_cycles ;
8839
    input doing_fast_back_to_back ;
8840
    output ok ;
8841
    reg in_use ;
8842
    integer deadlock_counter ;
8843
    integer transfer_counter ;
8844
    integer cycle_counter ;
8845
    integer deadlock_max_val ;
8846
begin:main
8847
 
8848
    if ( in_use === 1 )
8849
    begin
8850
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8851
        ok = 0 ;
8852
        disable main ;
8853
    end
8854
 
8855
    // approximate number of cycles on WB bus for maximum transaction length
8856
    deadlock_max_val = tb_init_waits + 100 +
8857
                       `WBW_DEPTH *
8858
                       (tb_subseq_waits + 1 +
8859
                       `ifdef REGISTER_WBS_OUTPUTS
8860
                       1) ;
8861
                       `else
8862
                       0) ;
8863
                       `endif
8864
 
8865
    // time used for maximum transaction length on WB
8866
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8867
 
8868
    // maximum pci clock cycles
8869
    `ifdef PCI33
8870
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8871
    `else
8872
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8873
    `endif
8874
 
8875
    in_use = 1 ;
8876
    ok     = 1 ;
8877
 
8878
    fork
8879
    begin:wait_start
8880
 
8881
        deadlock_counter = 0 ;
8882
 
8883
        @(posedge pci_clock) ;
8884
 
8885
        if ( doing_fast_back_to_back !== 1 )
8886
        begin
8887
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8888
            begin
8889 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8890
                    deadlock_counter = 0 ;
8891
                else
8892
                    deadlock_counter = deadlock_counter + 1 ;
8893 15 mihad
                @(posedge pci_clock) ;
8894
            end
8895
            if ( FRAME !== 1 )
8896
            begin
8897
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8898
                in_use = 0 ;
8899
                ok     = 0 ;
8900
                disable main ;
8901
            end
8902
        end
8903
 
8904
        deadlock_counter = 0 ;
8905
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8906
        begin
8907
            deadlock_counter = deadlock_counter + 1 ;
8908
            @(posedge pci_clock) ;
8909
        end
8910
 
8911
        if ( FRAME !== 0 )
8912
        begin
8913
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8914
            in_use = 0 ;
8915
            ok     = 0 ;
8916
            disable main ;
8917
        end
8918
    end //wait_start
8919
 
8920
    begin:addr_bc_monitor
8921
 
8922
        @(posedge pci_clock) ;
8923
 
8924
        if ( doing_fast_back_to_back !== 1 )
8925
        begin
8926
            while ( FRAME !== 1 )
8927
                @(posedge pci_clock) ;
8928
        end
8929
 
8930
        while( FRAME !== 0 )
8931
            @(posedge pci_clock) ;
8932
 
8933
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8934
        if ( bus_command !== `BC_IACK )
8935
        begin
8936
            if ( AD !== address )
8937
            begin
8938
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8939
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8940
                ok = 0 ;
8941
            end
8942
        end
8943
 
8944
        if ( CBE !== bus_command )
8945
        begin
8946
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8947
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8948
            ok = 0 ;
8949
        end
8950
    end //addr_bc_monitor
8951
 
8952
    begin:transfer_checker
8953
        transfer_counter = 0 ;
8954
 
8955
        @(posedge pci_clock) ;
8956
 
8957
        if ( doing_fast_back_to_back !== 1 )
8958
        begin
8959
            while ( FRAME !== 1 )
8960
                @(posedge pci_clock) ;
8961
        end
8962
 
8963
        while( FRAME !== 0 )
8964
            @(posedge pci_clock) ;
8965
 
8966
        while( FRAME === 0 )
8967
        begin
8968
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
8969
                transfer_counter = transfer_counter + 1 ;
8970
            @(posedge pci_clock) ;
8971
        end
8972
 
8973
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
8974
        begin
8975
            @(posedge pci_clock) ;
8976
        end
8977
 
8978
        if ( (TRDY === 0) && (DEVSEL === 0) )
8979
                transfer_counter = transfer_counter + 1 ;
8980
 
8981
        if ( check_transfers === 1 )
8982
        begin
8983
            if ( transfer_counter !== num_of_transfers )
8984
            begin
8985
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
8986
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
8987
                ok = 0 ;
8988
            end
8989
        end
8990
    end //transfer_checker
8991
    begin:cycle_checker
8992
        if ( check_cycles )
8993
        begin
8994
            cycle_counter = 0 ;
8995
            @(posedge pci_clock) ;
8996
 
8997
            if ( doing_fast_back_to_back !== 1)
8998
            begin
8999
                while ( FRAME !== 1 )
9000
                    @(posedge pci_clock) ;
9001
            end
9002
 
9003
            while( FRAME !== 0 )
9004
                @(posedge pci_clock) ;
9005
 
9006
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9007
            begin
9008
                cycle_counter = cycle_counter + 1 ;
9009
                @(posedge pci_clock) ;
9010
            end
9011
 
9012
            if ( FRAME !== 1 )
9013
            begin
9014
                while ((FRAME === 0) && (MAS0_GNT === 0))
9015
                    @(posedge pci_clock) ;
9016
 
9017
                if ( FRAME !== 1 )
9018
                begin
9019
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9020
                        @(posedge pci_clock) ;
9021
 
9022
                    @(posedge pci_clock) ;
9023
 
9024
                    if ( FRAME !== 1 )
9025
                    begin
9026
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9027
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9028
                        ok = 0 ;
9029
                    end
9030
                end
9031
            end
9032
        end
9033
    end // cycle_checker
9034
    join
9035
 
9036
    in_use = 0 ;
9037
end
9038
endtask //pci_transaction_progress_monitor
9039
 
9040
reg CYC_O_previous ;
9041
always@(posedge wb_clock or posedge reset)
9042
begin
9043
    if ( reset )
9044
        CYC_O_previous <= #1 1'b0 ;
9045
    else
9046
        CYC_O_previous <= #1 CYC_O ;
9047
end
9048
 
9049
task wb_transaction_progress_monitor ;
9050
    input [31:0] address ;
9051
    input        write ;
9052
    input [31:0] num_of_transfers ;
9053
    input check_transfers ;
9054
    output ok ;
9055
    reg in_use ;
9056
    integer deadlock_counter ;
9057
    integer transfer_counter ;
9058
    integer deadlock_max_val ;
9059
begin:main
9060
    if ( in_use === 1 )
9061
    begin
9062
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9063
        ok = 0 ;
9064
        disable main ;
9065
    end
9066
 
9067
    // number of cycles on WB bus for maximum transaction length
9068
    deadlock_max_val = 4 - tb_init_waits + 100 +
9069
                       `PCIW_DEPTH *
9070
                       (4 - tb_subseq_waits + 1) ;
9071
 
9072
    // time used for maximum transaction length on PCI
9073
    `ifdef PCI33
9074
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9075
    `else
9076
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9077
    `endif
9078
 
9079
    // maximum wb clock cycles
9080
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9081
 
9082
    in_use = 1 ;
9083
    ok     = 1 ;
9084
 
9085
    fork
9086
    begin:wait_start
9087
        deadlock_counter = 0 ;
9088
        @(posedge wb_clock) ;
9089
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9090
        begin
9091 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9092
                deadlock_counter = deadlock_counter + 1 ;
9093
            else
9094
                deadlock_counter = 0;
9095 15 mihad
            @(posedge wb_clock) ;
9096
        end
9097
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9098
        begin
9099
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9100
            in_use = 0 ;
9101
            ok     = 0 ;
9102
            disable main ;
9103
        end
9104
 
9105
        deadlock_counter = 0 ;
9106
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9107
        begin
9108
            deadlock_counter = deadlock_counter + 1 ;
9109
            @(posedge wb_clock) ;
9110
        end
9111
 
9112
        if ( CYC_O !== 1 )
9113
        begin
9114
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9115
            in_use = 0 ;
9116
            ok     = 0 ;
9117
            disable main ;
9118
        end
9119
    end //wait_start
9120
    begin:addr_monitor
9121
        @(posedge wb_clock) ;
9122
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9123
            @(posedge wb_clock) ;
9124
 
9125
        while( CYC_O !== 1 )
9126
            @(posedge wb_clock) ;
9127
 
9128
        while (STB_O !== 1 )
9129
            @(posedge wb_clock) ;
9130
 
9131
        if ( WE_O !== write )
9132
        begin
9133
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9134
            if ( write !== 1 )
9135
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9136
            else
9137
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9138
        end
9139
 
9140
        if ( ADR_O !== address )
9141
        begin
9142
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9143
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9144
            ok = 0 ;
9145
        end
9146
    end
9147
    begin:transfer_checker
9148
        transfer_counter = 0 ;
9149
        @(posedge wb_clock) ;
9150
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9151
            @(posedge wb_clock) ;
9152
 
9153
        while( CYC_O !== 1 )
9154
            @(posedge wb_clock) ;
9155
 
9156
        while( CYC_O === 1 )
9157
        begin
9158
            if ( (STB_O === 1) && (ACK_I === 1) )
9159
                transfer_counter = transfer_counter + 1 ;
9160
            @(posedge wb_clock) ;
9161
        end
9162
 
9163
        if ( check_transfers === 1 )
9164
        begin
9165
            if ( transfer_counter !== num_of_transfers )
9166
            begin
9167
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9168
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9169
                ok = 0 ;
9170
            end
9171
        end
9172
    end //transfer_checker
9173
    join
9174
 
9175
    in_use = 0 ;
9176
end
9177
endtask // wb_transaction_progress_monitor
9178
 
9179
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9180
// so they are not re-entered
9181
task wb_transaction_progress_monitor_backup ;
9182
    input [31:0] address ;
9183
    input        write ;
9184
    input [31:0] num_of_transfers ;
9185
    input check_transfers ;
9186
    output ok ;
9187
    reg in_use ;
9188
    integer deadlock_counter ;
9189
    integer transfer_counter ;
9190
    integer deadlock_max_val ;
9191
begin:main
9192
    if ( in_use === 1 )
9193
    begin
9194
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9195
        ok = 0 ;
9196
        disable main ;
9197
    end
9198
 
9199
    // number of cycles on WB bus for maximum transaction length
9200
    deadlock_max_val = 4 - tb_init_waits + 100 +
9201
                       `PCIW_DEPTH *
9202
                       (4 - tb_subseq_waits + 1) ;
9203
 
9204
    // time used for maximum transaction length on PCI
9205
    `ifdef PCI33
9206
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9207
    `else
9208
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9209
    `endif
9210
 
9211
    // maximum wb clock cycles
9212
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9213
 
9214
    in_use = 1 ;
9215
    ok     = 1 ;
9216
 
9217
    fork
9218
    begin:wait_start
9219
        deadlock_counter = 0 ;
9220
        @(posedge wb_clock) ;
9221
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9222
        begin
9223 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9224
                deadlock_counter = deadlock_counter + 1 ;
9225
            else
9226
                deadlock_counter = 0;
9227 15 mihad
            @(posedge wb_clock) ;
9228
        end
9229
        if ( CYC_O !== 0 )
9230
        begin
9231
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9232
            in_use = 0 ;
9233
            ok     = 0 ;
9234
            disable main ;
9235
        end
9236
 
9237
        deadlock_counter = 0 ;
9238
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9239
        begin
9240
            deadlock_counter = deadlock_counter + 1 ;
9241
            @(posedge wb_clock) ;
9242
        end
9243
 
9244
        if ( CYC_O !== 1 )
9245
        begin
9246
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9247
            in_use = 0 ;
9248
            ok     = 0 ;
9249
            disable main ;
9250
        end
9251
    end //wait_start
9252
    begin:addr_monitor
9253
        @(posedge wb_clock) ;
9254
        while ( CYC_O !== 0 )
9255
            @(posedge wb_clock) ;
9256
 
9257
        while( CYC_O !== 1 )
9258
            @(posedge wb_clock) ;
9259
 
9260
        while (STB_O !== 1 )
9261
            @(posedge wb_clock) ;
9262
 
9263
        if ( WE_O !== write )
9264
        begin
9265
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9266
            if ( write !== 1 )
9267
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9268
            else
9269
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9270
        end
9271
 
9272
        if ( ADR_O !== address )
9273
        begin
9274
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9275
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9276
            ok = 0 ;
9277
        end
9278
    end
9279
    begin:transfer_checker
9280
        transfer_counter = 0 ;
9281
        @(posedge wb_clock) ;
9282
        while ( CYC_O !== 0 )
9283
            @(posedge wb_clock) ;
9284
 
9285
        while( CYC_O !== 1 )
9286
            @(posedge wb_clock) ;
9287
 
9288
        while( CYC_O === 1 )
9289
        begin
9290
            if ( (STB_O === 1) && (ACK_I === 1) )
9291
                transfer_counter = transfer_counter + 1 ;
9292
            @(posedge wb_clock) ;
9293
        end
9294
 
9295
        if ( check_transfers === 1 )
9296
        begin
9297
            if ( transfer_counter !== num_of_transfers )
9298
            begin
9299
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9300
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9301
                ok = 0 ;
9302
            end
9303
        end
9304
    end //transfer_checker
9305
    join
9306
 
9307
    in_use = 0 ;
9308
end
9309
endtask // wb_transaction_progress_monitor_backup
9310
 
9311
task wb_transaction_stop ;
9312
    input [31:0] num_of_transfers ;
9313
    integer transfer_counter ;
9314
begin:main
9315
    begin:transfer_checker
9316
        transfer_counter = 0 ;
9317
        @(posedge wb_clock) ;
9318
        while ( CYC_O !== 0 )
9319
            @(posedge wb_clock) ;
9320
 
9321
        while( CYC_O !== 1 )
9322
            @(posedge wb_clock) ;
9323
 
9324
        if ( (STB_O === 1) && (ACK_I === 1) )
9325
            transfer_counter = transfer_counter + 1 ;
9326
 
9327
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9328
        begin
9329
            @(posedge wb_clock) ;
9330
            if ( (STB_O === 1) && (ACK_I === 1) )
9331
                transfer_counter = transfer_counter + 1 ;
9332
        end
9333
    end //transfer_checker
9334
end
9335
endtask // wb_transaction_stop
9336
 
9337
task musnt_respond ;
9338
    output ok ;
9339
    reg in_use ;
9340
    integer i ;
9341
begin:main
9342
    if ( in_use === 1 )
9343
    begin
9344
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9345
        #20 $stop ;
9346
        ok = 0 ;
9347
        disable main ;
9348
    end
9349
 
9350
    in_use = 1 ;
9351
    ok = 1 ;
9352
 
9353
    fork
9354
    begin:wait_start
9355
        @(negedge FRAME) ;
9356
        disable count ;
9357
    end
9358
    begin:count
9359
        i = 0 ;
9360
        while ( i < 1000 )
9361
        begin
9362
            @(posedge pci_clock) ;
9363
            i = i + 1 ;
9364
        end
9365
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9366
        ok = 0 ;
9367
        disable wait_start ;
9368
    end
9369
    join
9370
 
9371
    @(posedge pci_clock) ;
9372
    while ( FRAME === 0 && ok )
9373
    begin
9374
        if ( DEVSEL !== 1 )
9375
        begin
9376
            ok = 0 ;
9377
        end
9378
        @(posedge pci_clock) ;
9379
    end
9380
 
9381
    while ( IRDY === 0 && ok )
9382
    begin
9383
        if ( DEVSEL !== 1 )
9384
        begin
9385
            ok = 0 ;
9386
        end
9387
        @(posedge pci_clock) ;
9388
    end
9389
    in_use = 0 ;
9390
end
9391
endtask
9392
 
9393
function [31:0] wb_to_pci_addr_convert ;
9394
    input [31:0] wb_address ;
9395
    input [31:0] translation_address ;
9396
    input [31:0] translate ;
9397
 
9398
    reg   [31:0] temp_address ;
9399
begin
9400
    if ( translate !== 1 )
9401
    begin
9402
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9403
    end
9404
    else
9405
    begin
9406
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9407
    end
9408
 
9409
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9410
    wb_to_pci_addr_convert = temp_address ;
9411
end
9412
endfunction //wb_to_pci_addr_convert
9413
 
9414 45 mihad
`ifdef HOST
9415 15 mihad
task find_pci_devices ;
9416
    integer device_num ;
9417
    reg     found ;
9418
    reg [11:0] pci_ctrl_offset ;
9419
    reg ok ;
9420
    reg [31:0] data ;
9421 45 mihad
    reg [31:0] expected_data ;
9422
 
9423
    reg [5:0]  reg_num ;
9424 15 mihad
begin:main
9425 45 mihad
 
9426
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9427 15 mihad
    pci_ctrl_offset = 12'h004 ;
9428
 
9429
    // enable master & target operation
9430
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9431
 
9432
    if ( ok !== 1 )
9433
    begin
9434
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9435 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9436 15 mihad
        disable main ;
9437
    end
9438
    // find all possible devices on pci bus by performing configuration cycles
9439 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9440 15 mihad
    begin
9441
        find_device ( device_num, found ) ;
9442
 
9443
        // check pci status register - if device is not present, Received Master Abort bit must be set
9444
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9445
 
9446
        if ( (data[29] !== 0) && (found !== 0) )
9447 45 mihad
        begin
9448 15 mihad
            $display( "Time %t ", $time ) ;
9449
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9450
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9451 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9452
            ok = 0 ;
9453 15 mihad
        end
9454
 
9455
        if ( (data[29] !== 1) && (found !== 1) )
9456
        begin
9457
            $display( "Time %t ", $time ) ;
9458
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9459
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9460 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9461
            ok = 0 ;
9462 15 mihad
        end
9463
 
9464
        // clear Master Abort status if set
9465
        if ( data[29] !== 0 )
9466
        begin
9467
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9468
        end
9469 45 mihad
 
9470
        if (found === 1)
9471
        begin
9472
            // first check if found target is supposed to exist
9473
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9474
            begin
9475
                $display("Time %t", $time) ;
9476
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9477
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9478
                ok = 0 ;
9479
            end
9480
            else
9481
            begin
9482
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9483
                begin
9484
 
9485
                    data = 32'hFFFF_FFFF ;
9486
 
9487
                    expected_data = 0 ;
9488
 
9489
                    if (reg_num == 4)
9490
                    begin
9491
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9492
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9493
                    end
9494
                    else if (reg_num == 5)
9495
                    begin
9496
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9497
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9498
                    end
9499
 
9500
                    // write base address 0
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'b1            //read0_write1
9511
                    );
9512
 
9513
                    // read data back
9514
                    generate_configuration_cycle
9515
                    (
9516
                        'h0,            //bus_num
9517
                        device_num,     //device_num
9518
                        'h0,            //func_num
9519
                        reg_num,        //reg_num
9520
                        'h0,            //type
9521
                        4'hF,           // byte_enables
9522
                        data,           //data
9523
                        1'b0            //read0_write1
9524
                    );
9525
 
9526
                    if (data !== expected_data)
9527
                    begin
9528
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9529
                        $display("Data read back not as expected!");
9530
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9531
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9532
                        ok = 0 ;
9533
                    end
9534
                end
9535
            end
9536
        end
9537 15 mihad
    end
9538 45 mihad
 
9539
    if (ok)
9540
        test_ok ;
9541 15 mihad
end //main
9542
endtask //find_pci_devices
9543
 
9544
task find_device ;
9545
    input [31:0] device_num ;
9546
    output  found ;
9547
 
9548
    reg [31:0] read_data ;
9549
begin
9550
    found = 1'b0 ;
9551
 
9552
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9553 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9554 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9555
    else
9556
    begin
9557
        $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]) ;
9558
        found = 1'b1 ;
9559
    end
9560
end
9561
endtask //find_device
9562 45 mihad
`endif
9563 15 mihad
 
9564
/*task set_bridge_parameters ;
9565
    reg [11:0] current_offset ;
9566
    reg [2:0] result ;
9567
    reg [31:0] write_data ;
9568
begin
9569
    // set burst size
9570
    // set latency timer
9571
    current_offset = 12'h00C ;
9572
    // set burst size to 16 and latency timer to 8
9573
    write_data     = {24'h0000_08, system_burst_size} ;
9574
    config_write(current_offset, write_data, 4'b1111) ;
9575
 
9576
    // set io image
9577
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9578
    write_data = 32'h0000_000_3 ;
9579
    config_write(current_offset, write_data, 4'b1111) ;
9580
 
9581
 
9582
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9583
    write_data = 32'h0001_000_1 ;
9584
    config_write(current_offset, write_data, 4'b1111) ;
9585
 
9586
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9587
    write_data = 32'hFFFF_0000 ;
9588
    config_write(current_offset, write_data, 4'b1111) ;
9589
 
9590
    // set memory image
9591
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9592
    write_data = 32'h0000_000_7 ;
9593
    config_write(current_offset, write_data, 4'b1111) ;
9594
 
9595
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9596
    write_data = 32'h0002_000_0 ;
9597
    config_write(current_offset, write_data, 4'b1111) ;
9598
 
9599
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9600
    write_data = 32'h0001_0000 ;
9601
    config_write(current_offset, write_data, 4'b1111) ;
9602
 
9603
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9604
    write_data = 32'hFFFF_0000 ;
9605
    config_write(current_offset, write_data, 4'b1111) ;
9606
 
9607
    // set parameters for bridge's target unit
9608
    // image control 0
9609
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9610
    write_data     = 32'h0000_0002 ;
9611
    config_write(current_offset, write_data, 4'b0001) ;
9612
 
9613
    // base_address 0
9614
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9615
    write_data      = 32'h2000_0000 ;
9616
    config_write(current_offset, write_data, 4'b1111) ;
9617
 
9618
    // address mask 0
9619
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9620
    write_data     = 32'hFFFF_F000 ;
9621
    config_write(current_offset, write_data, 4'b1111) ;
9622
 
9623
    // command register - enable response to io and mem space and PCI master
9624
    current_offset = 12'h004 ;
9625
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9626
    config_write(current_offset, write_data, 4'b1111) ;
9627
end
9628
endtask // set_bridge_parameters
9629
*/
9630
 
9631
task configuration_cycle_write ;
9632
    input [7:0]  bus_num ;
9633
    input [4:0]  device_num ;
9634
    input [2:0]  func_num ;
9635
    input [5:0]  reg_num ;
9636
    input [1:0]  type ;
9637
    input [3:0]  byte_enables ;
9638
    input [31:0] data ;
9639
 
9640
    reg [31:0] write_address ;
9641
    reg in_use ;
9642
    reg ok ;
9643
begin:main
9644
 
9645
    if ( in_use === 1 )
9646
    begin
9647 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9648 15 mihad
        disable main ;
9649
    end
9650
 
9651 45 mihad
    if ( (device_num > 20) && (type === 0) )
9652 15 mihad
    begin
9653
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9654
        disable main ;
9655
    end
9656
 
9657
    in_use = 1 ;
9658
 
9659 45 mihad
 
9660
`ifdef HOST
9661
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9662
`else
9663
`ifdef GUEST
9664
 
9665 15 mihad
    if ( type )
9666
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9667
    else
9668
    begin
9669
        write_address = 0 ;
9670
        write_address[10:0] = { func_num, reg_num, type } ;
9671
        write_address[11 + device_num] = 1'b1 ;
9672
    end
9673 45 mihad
 
9674
    fork
9675 15 mihad
    begin
9676 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9677
                            write_address,
9678
                            data, ~byte_enables,
9679
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9680
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9681
        do_pause(1) ;
9682 15 mihad
    end
9683 45 mihad
    begin
9684
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9685
    end
9686
    join
9687
`endif
9688
`endif
9689
 
9690
    in_use = 0 ;
9691
end
9692
endtask // configuration_cycle_write
9693 15 mihad
 
9694 45 mihad
task configuration_cycle_read ;
9695
    input [7:0]  bus_num ;
9696
    input [4:0]  device_num ;
9697
    input [2:0]  func_num ;
9698
    input [5:0]  reg_num ;
9699
    input [1:0]  type ;
9700
    input [3:0]  byte_enables ;
9701
    output [31:0] data ;
9702 15 mihad
 
9703 45 mihad
    reg [31:0] read_address ;
9704
    reg in_use ;
9705 15 mihad
 
9706 45 mihad
    reg master_check_data_prev ;
9707
begin:main
9708 15 mihad
 
9709 45 mihad
    if ( in_use === 1 )
9710 15 mihad
    begin
9711 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9712
        data = 32'hxxxx_xxxx ;
9713
        disable main ;
9714 15 mihad
    end
9715
 
9716 45 mihad
    in_use = 1 ;
9717 15 mihad
 
9718 45 mihad
`ifdef HOST
9719
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9720
`else
9721
`ifdef GUEST
9722
     master_check_data_prev = master1_check_received_data ;
9723 15 mihad
     if ( type )
9724 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9725 15 mihad
     else
9726
     begin
9727 45 mihad
         read_address = 0 ;
9728
         read_address[10:0] = { func_num, reg_num, type } ;
9729
         read_address[11 + device_num] = 1'b1 ;
9730 15 mihad
     end
9731 45 mihad
 
9732
     fork
9733
     begin
9734
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9735
                 read_address,
9736 15 mihad
                 data, ~byte_enables,
9737
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9738
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9739 45 mihad
         do_pause(1) ;
9740
     end
9741
     begin
9742
         @(master1_received_data_valid) ;
9743
         data = master1_received_data ;
9744
     end
9745
     join
9746 15 mihad
 
9747 45 mihad
    master1_check_received_data = master_check_data_prev ;
9748
`endif
9749
`endif
9750
 
9751 15 mihad
    in_use = 0 ;
9752
 
9753 45 mihad
end //main
9754
endtask // configuration_cycle_read
9755
 
9756 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9757
task test_conf_cycle_type1_reference ;
9758
    reg [31:0] address ;
9759
    reg in_use ;
9760
 
9761
    reg master_check_data_prev ;
9762
    reg [31:0] data ;
9763
    reg monitor_ok ;
9764
    reg master_ok ;
9765
begin:main
9766
 
9767
    if ( in_use === 1 )
9768
    begin
9769
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9770
        disable main ;
9771
    end
9772
 
9773
    in_use = 1 ;
9774
 
9775
    master_check_data_prev = master1_check_received_data ;
9776
 
9777
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9778
    address = `TAR0_IDSEL_ADDR ;
9779
 
9780
    address[1:0] = 2'b01 ;
9781
 
9782
    `ifdef HOST
9783
        conf_cyc_type1_target_bus_num = 255 ;
9784
    `endif
9785
    master_ok = 1 ;
9786
    fork
9787
    begin
9788
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9789
        do_pause(1) ;
9790
    end
9791
    begin:error_monitor1
9792
        @(error_event_int) ;
9793
        master_ok = 0 ;
9794
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9795
    end
9796
    begin
9797
        pci_transaction_progress_monitor
9798
        (
9799
            address,                                                // expected address on PCI bus
9800
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9801
            0,                                                      // expected number of succesfull data phases
9802
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9803
            1'b1,                                                   // monitor checking/not checking number of transfers
9804
            1'b0,                                                   // monitor checking/not checking number of cycles
9805
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9806
            monitor_ok                                              // status - 1 success, 0 failure
9807
        ) ;
9808
 
9809
        @(posedge pci_clock);
9810
        #1 ;
9811
 
9812
        if (master_ok)
9813
            disable error_monitor1 ;
9814
 
9815
        if (!monitor_ok)
9816
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9817
    end
9818
    join
9819
 
9820
    if (monitor_ok && master_ok)
9821
        test_ok ;
9822
 
9823
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9824
    master_ok = 1 ;
9825
    fork
9826
    begin
9827
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9828
        do_pause(1) ;
9829
    end
9830
    begin:error_monitor2
9831
        @(error_event_int) ;
9832
        master_ok = 0 ;
9833
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9834
    end
9835
    begin
9836
        pci_transaction_progress_monitor
9837
        (
9838
            address,                                                // expected address on PCI bus
9839
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9840
            0,                                                      // expected number of succesfull data phases
9841
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9842
            1'b1,                                                   // monitor checking/not checking number of transfers
9843
            1'b0,                                                   // monitor checking/not checking number of cycles
9844
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9845
            monitor_ok                                              // status - 1 success, 0 failure
9846
        ) ;
9847
 
9848
        @(posedge pci_clock);
9849
        #1 ;
9850
 
9851
        if (master_ok)
9852
            disable error_monitor2 ;
9853
 
9854
        if (!monitor_ok)
9855
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9856
    end
9857
    join
9858
 
9859
    master1_check_received_data = master_check_data_prev ;
9860
 
9861
    if (monitor_ok && master_ok)
9862
        test_ok ;
9863
 
9864
    in_use = 0 ;
9865
 
9866
end //main
9867
endtask // test_conf_cycle_type1_reference
9868
`endif
9869
 
9870 45 mihad
`ifdef HOST
9871
task generate_configuration_cycle ;
9872 15 mihad
    input [7:0]  bus_num ;
9873
    input [4:0]  device_num ;
9874
    input [2:0]  func_num ;
9875
    input [5:0]  reg_num ;
9876
    input [1:0]  type ;
9877
    input [3:0]  byte_enables ;
9878 45 mihad
    inout [31:0] data ;
9879
    input        read0_write1 ;
9880 15 mihad
 
9881
    reg `READ_STIM_TYPE read_data ;
9882
    reg `WB_TRANSFER_FLAGS  flags ;
9883
    reg `READ_RETURN_TYPE   read_status ;
9884
 
9885
    reg `WRITE_STIM_TYPE   write_data ;
9886
    reg `WRITE_RETURN_TYPE write_status ;
9887
 
9888 45 mihad
    reg [31:0] pci_address ;
9889 15 mihad
    reg in_use ;
9890 45 mihad
    reg ok ;
9891 15 mihad
 
9892
    reg [31:0] temp_var ;
9893
begin:main
9894
 
9895
    if ( in_use === 1 )
9896
    begin
9897 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
9898 15 mihad
        data = 32'hxxxx_xxxx ;
9899
        disable main ;
9900
    end
9901
 
9902 45 mihad
    in_use = 1 ;
9903
 
9904
    if ( type )
9905
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9906
    else
9907 15 mihad
    begin
9908 45 mihad
        pci_address = 0 ;
9909
        pci_address[10:0] = { func_num, reg_num, type } ;
9910
        if (device_num <= 20)
9911
            pci_address[11 + device_num] = 1'b1 ;
9912
    end
9913
 
9914
    // setup flags
9915
    flags = 0 ;
9916
    flags`INIT_WAITS   = tb_init_waits ;
9917
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
9918
 
9919
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9920
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9921
 
9922
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9923
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9924
    write_data`WRITE_SEL      = 4'hF ;
9925
    write_data`WRITE_TAG_STIM = 0 ;
9926
 
9927
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9928
 
9929
    // check if write succeeded
9930
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9931
    begin
9932
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9933 15 mihad
        data = 32'hxxxx_xxxx ;
9934 45 mihad
        in_use = 0 ;
9935 15 mihad
        disable main ;
9936
    end
9937
 
9938 45 mihad
    // setup flags for wb master to handle retries and read and write data
9939
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9940
 
9941
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9942
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
9943
    read_data`READ_SEL          = byte_enables ;
9944
    write_data`WRITE_SEL        = byte_enables ;
9945
    read_data`READ_TAG_STIM     = 0 ;
9946
    write_data`WRITE_TAG_STIM   = 0 ;
9947
    write_data`WRITE_DATA       = data ;
9948
 
9949
    ok = 0 ;
9950
 
9951
    fork
9952
    begin
9953
        if (read0_write1 === 0)
9954
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
9955
        else
9956
        if (read0_write1 === 1)
9957
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
9958
    end
9959
    begin
9960
        pci_transaction_progress_monitor
9961
        (
9962
            pci_address,                                            // expected address on PCI bus
9963
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
9964
            1,                                                      // expected number of succesfull data phases
9965
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9966
            1'b0,                                                   // monitor checking/not checking number of transfers
9967
            1'b0,                                                   // monitor checking/not checking number of cycles
9968
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9969
            ok                                                      // status - 1 success, 0 failure
9970
        ) ;
9971
    end
9972
    join
9973
 
9974
    // check if transfer succeeded
9975
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
9976
    begin
9977
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
9978
        data = 32'hxxxx_xxxx ;
9979
        in_use = 0 ;
9980
        disable main ;
9981
    end
9982
 
9983
    if (!ok)
9984
    begin
9985
        data = 32'hxxxx_xxxx ;
9986
        in_use = 0 ;
9987
        disable main ;
9988
    end
9989
 
9990
    if (read0_write1 === 0)
9991
        data = read_status`READ_DATA ;
9992
 
9993
    in_use = 0 ;
9994
end
9995
endtask // generate_configuration_cycle
9996
 
9997
task test_configuration_cycle_target_abort ;
9998
    reg `READ_STIM_TYPE read_data ;
9999
    reg `WB_TRANSFER_FLAGS  flags ;
10000
    reg `READ_RETURN_TYPE   read_status ;
10001
 
10002
    reg `WRITE_STIM_TYPE   write_data ;
10003
    reg `WRITE_RETURN_TYPE write_status ;
10004
 
10005
    reg [31:0] pci_address ;
10006
    reg in_use ;
10007
    reg ok_pci ;
10008
    reg ok_wb  ;
10009
    reg ok     ;
10010
 
10011
    reg [31:0] temp_var ;
10012
 
10013
begin:main
10014
 
10015
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10016
 
10017
    if ( in_use === 1 )
10018
    begin
10019
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10020
        disable main ;
10021
    end
10022
 
10023 15 mihad
    in_use = 1 ;
10024
 
10025 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10026
 
10027 15 mihad
    // setup flags
10028
    flags = 0 ;
10029 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10030
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10031 15 mihad
 
10032
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10033
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10034
 
10035
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10036 45 mihad
    temp_var                  = 0 ;
10037
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10038
    write_data`WRITE_DATA     = temp_var ;
10039 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10040
    write_data`WRITE_TAG_STIM = 0 ;
10041
 
10042
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10043
 
10044
    // check if write succeeded
10045
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10046
    begin
10047
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10048 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10049
        in_use = 0 ;
10050 15 mihad
        disable main ;
10051
    end
10052
 
10053 45 mihad
    // setup flags for wb master to handle retries and read and write data
10054 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10055
 
10056 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10057
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10058 15 mihad
 
10059 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10060
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10061
    read_data`READ_SEL          = 4'hF ;
10062
    write_data`WRITE_SEL        = 4'hF ;
10063
    read_data`READ_TAG_STIM     = 0 ;
10064
    write_data`WRITE_TAG_STIM   = 0 ;
10065
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10066
 
10067
    ok_pci = 0 ;
10068
    ok_wb  = 1 ;
10069
 
10070
    // set target to terminate with target abort
10071
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10072
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10073
    fork
10074
    begin
10075
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10076
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10077
        begin
10078
            $display("Time %t", $time) ;
10079
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10080
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10081
            ok_wb = 0 ;
10082
        end
10083
 
10084
        config_read( 12'h4, 4'hF, temp_var ) ;
10085
        if ( temp_var[29] !== 0 )
10086
        begin
10087
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10088
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10089
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10090
            ok_wb = 0 ;
10091
        end
10092
 
10093
        if ( temp_var[28] !== 1 )
10094
        begin
10095
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10096
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10097
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10098
            ok_wb = 0 ;
10099
        end
10100
 
10101
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10102
 
10103
        if (ok !== 1)
10104
        begin
10105
            ok_wb = 0 ;
10106
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10107
            $display("Write to PCI Device Status Register failed") ;
10108
            test_fail("Write to PCI Device Status Register failed") ;
10109
        end
10110
 
10111
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10112
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10113
        begin
10114
            $display("Time %t", $time) ;
10115
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10116
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10117
            ok_wb = 0 ;
10118
        end
10119
 
10120
        config_read( 12'h4, 4'hF, temp_var ) ;
10121
        if ( temp_var[29] !== 0 )
10122
        begin
10123
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10124
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10125
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10126
            ok_wb = 0 ;
10127
        end
10128
 
10129
        if ( temp_var[28] !== 1 )
10130
        begin
10131
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10132
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10133
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10134
            ok_wb = 0 ;
10135
        end
10136
 
10137
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10138
 
10139
        if (ok !== 1)
10140
        begin
10141
            ok_wb = 0 ;
10142
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10143
            $display("Write to PCI Device Status Register failed") ;
10144
            test_fail("Write to PCI Device Status Register failed") ;
10145
        end
10146
    end
10147
    begin
10148
        pci_transaction_progress_monitor
10149
        (
10150
            pci_address,                                            // expected address on PCI bus
10151
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10152
            0,                                                      // expected number of succesfull data phases
10153
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10154
            1'b1,                                                   // monitor checking/not checking number of transfers
10155
            1'b0,                                                   // monitor checking/not checking number of cycles
10156
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10157
            ok_pci                                                  // status - 1 success, 0 failure
10158
        ) ;
10159
 
10160
        if (ok_pci)
10161
        begin
10162
            pci_transaction_progress_monitor
10163
            (
10164
                pci_address,                                            // expected address on PCI bus
10165
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10166
                0,                                                      // expected number of succesfull data phases
10167
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10168
                1'b1,                                                   // monitor checking/not checking number of transfers
10169
                1'b0,                                                   // monitor checking/not checking number of cycles
10170
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10171
                ok_pci                                                  // status - 1 success, 0 failure
10172
            ) ;
10173
        end
10174
 
10175
        if (!ok_pci)
10176
        begin
10177
            $display("Time %t", $time) ;
10178
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10179
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10180
        end
10181
    end
10182
    join
10183
 
10184
    if (ok_pci && ok_wb)
10185
    begin
10186
        test_ok ;
10187
    end
10188
 
10189
    in_use = 0 ;
10190
 
10191
    // set target to terminate normally
10192
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10193
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10194
end
10195
endtask // test_configuration_cycle_target_abort
10196
 
10197
task test_configuration_cycle_type1_generation ;
10198
    reg `READ_STIM_TYPE read_data ;
10199
    reg `WB_TRANSFER_FLAGS  flags ;
10200
    reg `READ_RETURN_TYPE   read_status ;
10201
 
10202
    reg `WRITE_STIM_TYPE   write_data ;
10203
    reg `WRITE_RETURN_TYPE write_status ;
10204
 
10205
    reg [31:0] pci_address ;
10206
    reg in_use ;
10207
    reg ok_pci ;
10208
    reg ok_wb  ;
10209
    reg ok     ;
10210
 
10211
    reg [31:0] temp_var ;
10212
 
10213
begin:main
10214
 
10215
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10216
    conf_cyc_type1_target_data = 0 ;
10217
    conf_cyc_type1_target_bus_num = 0;
10218
 
10219
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10220
 
10221
    if ( in_use === 1 )
10222
    begin
10223
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10224
        disable main ;
10225
    end
10226
 
10227
    in_use = 1 ;
10228
 
10229
    pci_address        = 32'hAAAA_AAAA ;
10230
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10231
 
10232
    // setup flags
10233
    flags = 0 ;
10234
    flags`INIT_WAITS   = tb_init_waits ;
10235
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10236
 
10237
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10238
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10239
 
10240
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10241
    write_data`WRITE_DATA     = pci_address ;
10242
    write_data`WRITE_SEL      = 4'hF ;
10243
    write_data`WRITE_TAG_STIM = 0 ;
10244
 
10245
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10246
 
10247
    // check if write succeeded
10248
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10249
    begin
10250
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10251
        test_fail("write to configuration cycle address register was not possible") ;
10252
        in_use = 0 ;
10253
        disable main ;
10254
    end
10255
 
10256
    // setup flags for wb master to handle retries and read and write data
10257
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10258
 
10259
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10260
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10261
 
10262
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10263
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10264
    read_data`READ_SEL          = 4'hF ;
10265
    write_data`WRITE_SEL        = 4'hF ;
10266
    read_data`READ_TAG_STIM     = 0 ;
10267
    write_data`WRITE_TAG_STIM   = 0 ;
10268
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10269
 
10270
    ok_pci = 0 ;
10271
    ok_wb  = 1 ;
10272
 
10273
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10274
    pci_address[31:24] = 0 ;
10275
    fork
10276
    begin
10277
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10278
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10279
        begin
10280
            $display("Time %t", $time) ;
10281
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10282
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10283
            ok_wb = 0 ;
10284
        end
10285
 
10286
        config_read( 12'h4, 4'hF, temp_var ) ;
10287
        if ( temp_var[29] !== 1 )
10288
        begin
10289
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10290
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10291
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10292
            ok_wb = 0 ;
10293
        end
10294
 
10295
        if ( temp_var[28] !== 0 )
10296
        begin
10297
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10298
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10299
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10300
            ok_wb = 0 ;
10301
        end
10302
 
10303
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10304
 
10305
        if (ok !== 1)
10306
        begin
10307
            ok_wb = 0 ;
10308
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10309
            $display("Write to PCI Device Status Register failed") ;
10310
            test_fail("Write to PCI Device Status Register failed") ;
10311
        end
10312
 
10313
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10314
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10315
        begin
10316
            $display("Time %t", $time) ;
10317
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10318
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10319
            ok_wb = 0 ;
10320
        end
10321
 
10322
        config_read( 12'h4, 4'hF, temp_var ) ;
10323
        if ( temp_var[29] !== 1 )
10324
        begin
10325
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10326
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10327
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10328
            ok_wb = 0 ;
10329
        end
10330
 
10331
        if ( temp_var[28] !== 0 )
10332
        begin
10333
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10334
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10335
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master 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("Master 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
    end
10349
    begin
10350
        pci_transaction_progress_monitor
10351
        (
10352
            pci_address,                                            // expected address on PCI bus
10353
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10354
            0,                                                      // expected number of succesfull data phases
10355
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10356
            1'b1,                                                   // monitor checking/not checking number of transfers
10357
            1'b0,                                                   // monitor checking/not checking number of cycles
10358
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10359
            ok_pci                                                  // status - 1 success, 0 failure
10360
        ) ;
10361
 
10362
        if (ok_pci)
10363
        begin
10364
            pci_transaction_progress_monitor
10365
            (
10366
                pci_address,                                            // expected address on PCI bus
10367
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10368
                0,                                                      // expected number of succesfull data phases
10369
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10370
                1'b1,                                                   // monitor checking/not checking number of transfers
10371
                1'b0,                                                   // monitor checking/not checking number of cycles
10372
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10373
                ok_pci                                                  // status - 1 success, 0 failure
10374
            ) ;
10375
        end
10376
 
10377
        if (!ok_pci)
10378
        begin
10379
            $display("Time %t", $time) ;
10380
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10381
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10382
        end
10383
    end
10384
    join
10385
 
10386
    if (ok_pci && ok_wb)
10387
    begin
10388
        test_ok ;
10389
    end
10390
 
10391
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10392
    conf_cyc_type1_target_data = 0 ;
10393
    conf_cyc_type1_target_bus_num = 8'h55;
10394
 
10395
    pci_address      = 32'h5555_5555 ;
10396
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10397
 
10398
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10399
 
10400
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10401
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10402
 
10403
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10404
    write_data`WRITE_DATA     = pci_address ;
10405
    write_data`WRITE_SEL      = 4'hF ;
10406
    write_data`WRITE_TAG_STIM = 0 ;
10407
 
10408
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10409
 
10410
    // check if write succeeded
10411
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10412
    begin
10413
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10414
        test_fail("write to configuration cycle address register was not possible") ;
10415
        in_use = 0 ;
10416
        disable main ;
10417
    end
10418
 
10419
    // setup flags for wb master to handle retries and read and write data
10420
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10421
 
10422
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10423
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10424
 
10425
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10426
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10427
    read_data`READ_SEL          = 4'hF ;
10428
    write_data`WRITE_SEL        = 4'hF ;
10429
    read_data`READ_TAG_STIM     = 0 ;
10430
    write_data`WRITE_TAG_STIM   = 0 ;
10431
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10432
 
10433
    ok_pci = 0 ;
10434
    ok_wb  = 1 ;
10435
 
10436
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10437
    pci_address[31:24] = 0 ;
10438
    fork
10439
    begin
10440
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10441
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10442
        begin
10443
            $display("Time %t", $time) ;
10444
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10445
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10446
            ok_wb = 0 ;
10447
        end
10448
 
10449
        config_read( 12'h4, 4'hF, temp_var ) ;
10450
        if ( temp_var[29] !== 0 )
10451
        begin
10452
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10453
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10454
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10455
            ok_wb = 0 ;
10456
        end
10457
 
10458
        if ( temp_var[28] !== 1 )
10459
        begin
10460
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10461
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10462
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10463
            ok_wb = 0 ;
10464
        end
10465
 
10466
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10467
 
10468
        if (ok !== 1)
10469
        begin
10470
            ok_wb = 0 ;
10471
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10472
            $display("Write to PCI Device Status Register failed") ;
10473
            test_fail("Write to PCI Device Status Register failed") ;
10474
        end
10475
 
10476
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10477
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10478
        begin
10479
            $display("Time %t", $time) ;
10480
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10481
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10482
            ok_wb = 0 ;
10483
        end
10484
 
10485
        config_read( 12'h4, 4'hF, temp_var ) ;
10486
        if ( temp_var[29] !== 0 )
10487
        begin
10488
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10489
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10490
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10491
            ok_wb = 0 ;
10492
        end
10493
 
10494
        if ( temp_var[28] !== 1 )
10495
        begin
10496
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10497
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10498
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10499
            ok_wb = 0 ;
10500
        end
10501
 
10502
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10503
 
10504
        if (ok !== 1)
10505
        begin
10506
            ok_wb = 0 ;
10507
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10508
            $display("Write to PCI Device Status Register failed") ;
10509
            test_fail("Write to PCI Device Status Register failed") ;
10510
        end
10511
    end
10512
    begin
10513
        pci_transaction_progress_monitor
10514
        (
10515
            pci_address,                                            // expected address on PCI bus
10516
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10517
            0,                                                      // expected number of succesfull data phases
10518
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10519
            1'b1,                                                   // monitor checking/not checking number of transfers
10520
            1'b0,                                                   // monitor checking/not checking number of cycles
10521
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10522
            ok_pci                                                  // status - 1 success, 0 failure
10523
        ) ;
10524
 
10525
        if (ok_pci)
10526
        begin
10527
            pci_transaction_progress_monitor
10528
            (
10529
                pci_address,                                            // expected address on PCI bus
10530
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10531
                0,                                                      // expected number of succesfull data phases
10532
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10533
                1'b1,                                                   // monitor checking/not checking number of transfers
10534
                1'b0,                                                   // monitor checking/not checking number of cycles
10535
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10536
                ok_pci                                                  // status - 1 success, 0 failure
10537
            ) ;
10538
        end
10539
 
10540
        if (!ok_pci)
10541
        begin
10542
            $display("Time %t", $time) ;
10543
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10544
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10545
        end
10546
    end
10547
    join
10548
 
10549
    if (ok_pci && ok_wb)
10550
    begin
10551
        test_ok ;
10552
    end
10553
 
10554
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10555
 
10556
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10557
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10558
    conf_cyc_type1_target_bus_num = 8'hAA;
10559
 
10560
    pci_address      = 32'hAAAA_AAAA ;
10561
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10562
 
10563
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10564
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10565
 
10566
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10567
    write_data`WRITE_DATA     = pci_address ;
10568
    write_data`WRITE_SEL      = 4'hF ;
10569
    write_data`WRITE_TAG_STIM = 0 ;
10570
 
10571
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10572
 
10573
    // check if write succeeded
10574
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10575
    begin
10576
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10577
        test_fail("write to configuration cycle address register was not possible") ;
10578
        in_use = 0 ;
10579
        disable main ;
10580
    end
10581
 
10582
    // setup flags for wb master to handle retries and read and write data
10583
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10584
 
10585
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10586
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10587
 
10588
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10589
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10590
    read_data`READ_SEL          = 4'b0101 ;
10591
    write_data`WRITE_SEL        = 4'b1010 ;
10592
    read_data`READ_TAG_STIM     = 0 ;
10593
    write_data`WRITE_TAG_STIM   = 0 ;
10594
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10595
 
10596
    ok_pci = 0 ;
10597
    ok_wb  = 1 ;
10598
 
10599
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10600
    pci_address[31:24] = 0 ;
10601
 
10602
    fork
10603
    begin
10604
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10605
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10606
        begin
10607
            $display("Time %t", $time) ;
10608
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10609
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10610
            ok_wb = 0 ;
10611
        end
10612
 
10613
        config_read( 12'h4, 4'hF, temp_var ) ;
10614
        if ( temp_var[29] !== 0 )
10615
        begin
10616
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10617
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10618
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10619
            ok_wb = 0 ;
10620
        end
10621
 
10622
        if ( temp_var[28] !== 0 )
10623
        begin
10624
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10625
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10626
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10627
            ok_wb = 0 ;
10628
        end
10629
 
10630
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10631
 
10632
        if (ok !== 1)
10633
        begin
10634
            ok_wb = 0 ;
10635
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10636
            $display("Write to PCI Device Status Register failed") ;
10637
            test_fail("Write to PCI Device Status Register failed") ;
10638
        end
10639
 
10640
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10641
        begin
10642
            ok_wb = 0 ;
10643
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10644
            $display("Read Data provided by the bridge was not as expected!") ;
10645
            test_fail("Read Data provided by the bridge was not as expected") ;
10646
        end
10647
 
10648
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10649
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10650
        begin
10651
            $display("Time %t", $time) ;
10652
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10653
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10654
            ok_wb = 0 ;
10655
        end
10656
 
10657
        config_read( 12'h4, 4'hF, temp_var ) ;
10658
        if ( temp_var[29] !== 0 )
10659
        begin
10660
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10661
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10662
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10663
            ok_wb = 0 ;
10664
        end
10665
 
10666
        if ( temp_var[28] !== 0 )
10667
        begin
10668
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10669
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10670
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10671
            ok_wb = 0 ;
10672
        end
10673
 
10674
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10675
 
10676
        if (ok !== 1)
10677
        begin
10678
            ok_wb = 0 ;
10679
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10680
            $display("Write to PCI Device Status Register failed") ;
10681
            test_fail("Write to PCI Device Status Register failed") ;
10682
        end
10683
 
10684
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10685
        begin
10686
            ok_wb = 0 ;
10687
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10688
            $display("Data written by the bridge was not as expected!") ;
10689
            test_fail("Data written by the bridge was not as expected") ;
10690
        end
10691
 
10692
    end
10693
    begin
10694
        ok = 1 ;
10695
        repeat(8)
10696
        begin
10697
            pci_transaction_progress_monitor
10698
            (
10699
                pci_address,                                            // expected address on PCI bus
10700
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10701
                0,                                                      // expected number of succesfull data phases
10702
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10703
                1'b1,                                                   // monitor checking/not checking number of transfers
10704
                1'b0,                                                   // monitor checking/not checking number of cycles
10705
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10706
                ok_pci                                                  // status - 1 success, 0 failure
10707
            ) ;
10708
 
10709
            if (!ok_pci)
10710
            begin
10711
                ok = 0 ;
10712
                $display("Time %t", $time) ;
10713
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10714
            end
10715
        end
10716
 
10717
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10718
 
10719
        pci_transaction_progress_monitor
10720
        (
10721
            pci_address,                                            // expected address on PCI bus
10722
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10723
            1,                                                      // expected number of succesfull data phases
10724
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10725
            1'b1,                                                   // monitor checking/not checking number of transfers
10726
            1'b0,                                                   // monitor checking/not checking number of cycles
10727
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10728
            ok_pci                                                  // status - 1 success, 0 failure
10729
        ) ;
10730
 
10731
        if (!ok_pci)
10732
        begin
10733
            ok = 0 ;
10734
            $display("Time %t", $time) ;
10735
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10736
        end
10737
 
10738
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10739
        repeat(8)
10740
        begin
10741
            pci_transaction_progress_monitor
10742
            (
10743
                pci_address,                                            // expected address on PCI bus
10744
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10745
                0,                                                      // expected number of succesfull data phases
10746
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10747
                1'b1,                                                   // monitor checking/not checking number of transfers
10748
                1'b0,                                                   // monitor checking/not checking number of cycles
10749
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10750
                ok_pci                                                  // status - 1 success, 0 failure
10751
            ) ;
10752
 
10753
            if (!ok_pci)
10754
            begin
10755
                ok = 0 ;
10756
                $display("Time %t", $time) ;
10757
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10758
            end
10759
        end
10760
 
10761
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10762
        pci_transaction_progress_monitor
10763
        (
10764
            pci_address,                                            // expected address on PCI bus
10765
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10766
            1,                                                      // expected number of succesfull data phases
10767
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10768
            1'b1,                                                   // monitor checking/not checking number of transfers
10769
            1'b0,                                                   // monitor checking/not checking number of cycles
10770
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10771
            ok_pci                                                  // status - 1 success, 0 failure
10772
        ) ;
10773
 
10774
        if (!ok_pci)
10775
        begin
10776
            ok = 0 ;
10777
            $display("Time %t", $time) ;
10778
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10779
        end
10780
 
10781
        if (!ok)
10782
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10783
    end
10784
    join
10785
 
10786
    if (ok_pci && ok_wb)
10787
    begin
10788
        test_ok ;
10789
    end
10790
 
10791
    in_use = 0 ;
10792
end
10793
endtask // test_configuration_cycle_type1_generation
10794
`endif
10795
 
10796
task test_initial_conf_values ;
10797
    reg [11:0] register_offset ;
10798
    reg [31:0] expected_value ;
10799
    reg        failed ;
10800
`ifdef HOST
10801
    reg `READ_STIM_TYPE    read_data ;
10802
    reg `WB_TRANSFER_FLAGS flags ;
10803
    reg `READ_RETURN_TYPE  read_status ;
10804
 
10805
    reg `WRITE_STIM_TYPE   write_data ;
10806
    reg `WRITE_RETURN_TYPE write_status ;
10807
begin
10808
    failed     = 0 ;
10809
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10810
    flags      = 0 ;
10811
    read_data  = 0 ;
10812
    write_data = 0 ;
10813
 
10814
    read_data`READ_SEL = 4'hF ;
10815
 
10816
    flags`INIT_WAITS           = tb_init_waits ;
10817
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10818
 
10819
    // test MEM/IO map bit initial value in each PCI BAR
10820
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10821
 
10822
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10823
 
10824 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10825
 
10826 45 mihad
    `ifdef NO_CNF_IMAGE
10827
        `ifdef PCI_IMAGE0
10828
            if (`PCI_AM0)
10829
                expected_value = `PCI_BA0_MEM_IO ;
10830
            else
10831
                expected_value = 32'h0000_0000 ;
10832
        `else
10833
            expected_value = 32'h0000_0000 ;
10834
        `endif
10835
    `else
10836
        expected_value = 32'h0000_0000 ;
10837
    `endif
10838
 
10839 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10840
    begin
10841 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10842
        failed = 1 ;
10843 15 mihad
    end
10844 45 mihad
    else
10845
    begin
10846
        if (read_status`READ_DATA !== expected_value)
10847
        begin
10848
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10849
            failed = 1 ;
10850
        end
10851
    end
10852 15 mihad
 
10853 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10854 15 mihad
 
10855 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10856
 
10857
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10858
 
10859
    if (`PCI_AM1)
10860
        expected_value = `PCI_BA1_MEM_IO ;
10861
    else
10862
        expected_value = 32'h0000_0000 ;
10863
 
10864
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10865
    begin
10866
        test_fail("read from P_BA1 register didn't succeede") ;
10867
        failed = 1 ;
10868
    end
10869
    else
10870
    begin
10871
        if (read_status`READ_DATA !== expected_value)
10872
        begin
10873
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
10874
            failed = 1 ;
10875
        end
10876
    end
10877
 
10878
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
10879
 
10880
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10881
 
10882
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10883
 
10884
    `ifdef PCI_IMAGE2
10885
        if (`PCI_AM2)
10886
            expected_value = `PCI_BA2_MEM_IO ;
10887
        else
10888
            expected_value = 32'h0000_0000 ;
10889 15 mihad
    `else
10890 45 mihad
        expected_value = 32'h0000_0000 ;
10891
    `endif
10892 15 mihad
 
10893 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10894
    begin
10895
        test_fail("read from P_BA2 register didn't succeede") ;
10896
        failed = 1 ;
10897
    end
10898
    else
10899
    begin
10900
        if (read_status`READ_DATA !== expected_value)
10901
        begin
10902
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
10903
            failed = 1 ;
10904
        end
10905
    end
10906 15 mihad
 
10907 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
10908
 
10909
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10910
 
10911
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10912
 
10913
    `ifdef PCI_IMAGE3
10914
        if (`PCI_AM3)
10915
            expected_value = `PCI_BA3_MEM_IO ;
10916
        else
10917
            expected_value = 32'h0000_0000 ;
10918
    `else
10919
        expected_value = 32'h0000_0000 ;
10920 15 mihad
    `endif
10921 45 mihad
 
10922
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10923
    begin
10924
        test_fail("read from P_BA3 register didn't succeede") ;
10925
        failed = 1 ;
10926
    end
10927
    else
10928
    begin
10929
        if (read_status`READ_DATA !== expected_value)
10930
        begin
10931
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
10932
            failed = 1 ;
10933
        end
10934
    end
10935
 
10936
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
10937
 
10938
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10939
 
10940
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10941
 
10942
    `ifdef PCI_IMAGE4
10943
        if (`PCI_AM4)
10944
            expected_value = `PCI_BA4_MEM_IO ;
10945
        else
10946
            expected_value = 32'h0000_0000 ;
10947
    `else
10948
        expected_value = 32'h0000_0000 ;
10949 15 mihad
    `endif
10950
 
10951 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10952
    begin
10953
        test_fail("read from P_BA4 register didn't succeede") ;
10954
        failed = 1 ;
10955
    end
10956
    else
10957
    begin
10958
        if (read_status`READ_DATA !== expected_value)
10959
        begin
10960
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
10961
            failed = 1 ;
10962
        end
10963
    end
10964 15 mihad
 
10965 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
10966 15 mihad
 
10967 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10968
 
10969
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10970
 
10971
    `ifdef PCI_IMAGE5
10972
        if(`PCI_AM5)
10973
            expected_value = `PCI_BA5_MEM_IO ;
10974
        else
10975
            expected_value = 32'h0000_0000 ;
10976
    `else
10977
        expected_value = 32'h0000_0000 ;
10978
    `endif
10979
 
10980
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10981
    begin
10982
        test_fail("read from P_BA5 register didn't succeede") ;
10983
        failed = 1 ;
10984
    end
10985
    else
10986
    begin
10987
        if (read_status`READ_DATA !== expected_value)
10988
        begin
10989
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
10990
            failed = 1 ;
10991
        end
10992
    end
10993
 
10994
    // test Address Mask initial values
10995
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
10996
 
10997
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10998
 
10999
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11000
 
11001
    `ifdef NO_CNF_IMAGE
11002
        `ifdef PCI_IMAGE0
11003
            expected_value = {`PCI_AM0, 12'h000};
11004
 
11005
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11006
        `else
11007
            expected_value = 32'h0000_0000 ;
11008
        `endif
11009
    `else
11010
        expected_value = 32'hFFFF_FFFF ;
11011
 
11012
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11013
    `endif
11014
 
11015
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11016
    begin
11017
        test_fail("read from P_AM0 register didn't succeede") ;
11018
        failed = 1 ;
11019
    end
11020
    else
11021
    begin
11022
        if (read_status`READ_DATA !== expected_value)
11023
        begin
11024
            test_fail("AM0 initial value was not set as defined");
11025
            failed = 1 ;
11026
        end
11027
    end
11028
 
11029
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11030
 
11031
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11032
 
11033
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11034
 
11035
    expected_value = {`PCI_AM1, 12'h000};
11036
 
11037
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11038
 
11039
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11040
    begin
11041
        test_fail("read from P_AM1 register didn't succeede") ;
11042
        failed = 1 ;
11043
    end
11044
    else
11045
    begin
11046
        if (read_status`READ_DATA !== expected_value)
11047
        begin
11048
            test_fail("AM1 initial value was not set as defined");
11049
            failed = 1 ;
11050
        end
11051
    end
11052
 
11053
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11054
 
11055
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11056
 
11057
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11058
 
11059
    `ifdef PCI_IMAGE2
11060
        expected_value = {`PCI_AM2, 12'h000};
11061
 
11062
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11063
    `else
11064
        expected_value = 32'h0000_0000 ;
11065
    `endif
11066
 
11067
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11068
    begin
11069
        test_fail("read from P_AM2 register didn't succeede") ;
11070
        failed = 1 ;
11071
    end
11072
    else
11073
    begin
11074
        if (read_status`READ_DATA !== expected_value)
11075
        begin
11076
            test_fail("AM2 initial value was not set as defined");
11077
            failed = 1 ;
11078
        end
11079
    end
11080
 
11081
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11082
 
11083
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11084
 
11085
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11086
 
11087
    `ifdef PCI_IMAGE3
11088
        expected_value = {`PCI_AM3, 12'h000};
11089
 
11090
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11091
    `else
11092
        expected_value = 32'h0000_0000 ;
11093
    `endif
11094
 
11095
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11096
    begin
11097
        test_fail("read from P_AM3 register didn't succeede") ;
11098
        failed = 1 ;
11099
    end
11100
    else
11101
    begin
11102
        if (read_status`READ_DATA !== expected_value)
11103
        begin
11104
            test_fail("AM3 initial value was not set as defined");
11105
            failed = 1 ;
11106
        end
11107
    end
11108
 
11109
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11110
 
11111
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11112
 
11113
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11114
 
11115
    `ifdef PCI_IMAGE4
11116
        expected_value = {`PCI_AM4, 12'h000};
11117
 
11118
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11119
    `else
11120
        expected_value = 32'h0000_0000 ;
11121
    `endif
11122
 
11123
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11124
    begin
11125
        test_fail("read from P_AM4 register didn't succeede") ;
11126
        failed = 1 ;
11127
    end
11128
    else
11129
    begin
11130
        if (read_status`READ_DATA !== expected_value)
11131
        begin
11132
            test_fail("AM4 initial value was not set as defined");
11133
            failed = 1 ;
11134
        end
11135
    end
11136
 
11137
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11138
 
11139
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11140
 
11141
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11142
 
11143
    `ifdef PCI_IMAGE5
11144
        expected_value = {`PCI_AM5, 12'h000};
11145
 
11146
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11147
    `else
11148
        expected_value = 32'h0000_0000 ;
11149
    `endif
11150
 
11151
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11152
    begin
11153
        test_fail("read from P_AM5 register didn't succeede") ;
11154
        failed = 1 ;
11155
    end
11156
    else
11157
    begin
11158
        if (read_status`READ_DATA !== expected_value)
11159
        begin
11160
            test_fail("AM5 initial value was not set as defined");
11161
            failed = 1 ;
11162
        end
11163
    end
11164
 
11165
`endif
11166
 
11167
`ifdef GUEST
11168
    reg [31:0] read_data ;
11169
begin
11170
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11171
    failed    = 0 ;
11172
 
11173
    // check all images' BARs
11174
 
11175
    // BAR0
11176
    configuration_cycle_read
11177
    (
11178
        8'h00,                          // bus number [7:0]
11179
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11180
        3'h0,                           // function number [2:0]
11181
        6'h4,                           // register number [5:0]
11182
        2'h0,                           // type [1:0]
11183
        4'hF,                           // byte enables [3:0]
11184
        read_data                       // data returned from configuration read [31:0]
11185
    ) ;
11186
 
11187
    expected_value = 32'h0000_0000 ;
11188
 
11189
    if( read_data !== expected_value)
11190
    begin
11191
        test_fail("initial value of BAR0 register not as expected") ;
11192
        failed = 1 ;
11193
    end
11194
 
11195
    // BAR1
11196
    configuration_cycle_read
11197
    (
11198
        8'h00,                          // bus number [7:0]
11199
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11200
        3'h0,                           // function number [2:0]
11201
        6'h5,                           // register number [5:0]
11202
        2'h0,                           // type [1:0]
11203
        4'hF,                           // byte enables [3:0]
11204
        read_data                       // data returned from configuration read [31:0]
11205
    ) ;
11206
 
11207
    if (`PCI_AM1)
11208
        expected_value = `PCI_BA1_MEM_IO ;
11209
    else
11210
        expected_value = 32'h0000_0000 ;
11211
 
11212
    if( read_data !== expected_value)
11213
    begin
11214
        test_fail("initial value of BAR1 register not as expected") ;
11215
        failed = 1 ;
11216
    end
11217
 
11218
    // BAR2
11219
    configuration_cycle_read
11220
    (
11221
        8'h00,                          // bus number [7:0]
11222
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11223
        3'h0,                           // function number [2:0]
11224
        6'h6,                           // register number [5:0]
11225
        2'h0,                           // type [1:0]
11226
        4'hF,                           // byte enables [3:0]
11227
        read_data                       // data returned from configuration read [31:0]
11228
    ) ;
11229
 
11230
    `ifdef PCI_IMAGE2
11231
    if (`PCI_AM2)
11232
        expected_value = `PCI_BA2_MEM_IO ;
11233
    else
11234
        expected_value = 32'h0000_0000 ;
11235
    `else
11236
    expected_value = 32'h0 ;
11237
    `endif
11238
 
11239
    if( read_data !== expected_value)
11240
    begin
11241
        test_fail("initial value of BAR2 register not as expected") ;
11242
        failed = 1 ;
11243
    end
11244
 
11245
    // BAR3
11246
    configuration_cycle_read
11247
    (
11248
        8'h00,                          // bus number [7:0]
11249
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11250
        3'h0,                           // function number [2:0]
11251
        6'h7,                           // register number [5:0]
11252
        2'h0,                           // type [1:0]
11253
        4'hF,                           // byte enables [3:0]
11254
        read_data                       // data returned from configuration read [31:0]
11255
    ) ;
11256
 
11257
    `ifdef PCI_IMAGE3
11258
    if(`PCI_AM3)
11259
        expected_value = `PCI_BA3_MEM_IO ;
11260
    else
11261
        expected_value = 32'h0000_0000 ;
11262
    `else
11263
    expected_value = 32'h0 ;
11264
    `endif
11265
 
11266
    if( read_data !== expected_value)
11267
    begin
11268
        test_fail("initial value of BAR3 register not as expected") ;
11269
        failed = 1 ;
11270
    end
11271
 
11272
    // BAR4
11273
    configuration_cycle_read
11274
    (
11275
        8'h00,                          // bus number [7:0]
11276
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11277
        3'h0,                           // function number [2:0]
11278
        6'h8,                           // register number [5:0]
11279
        2'h0,                           // type [1:0]
11280
        4'hF,                           // byte enables [3:0]
11281
        read_data                       // data returned from configuration read [31:0]
11282
    ) ;
11283
 
11284
    `ifdef PCI_IMAGE4
11285
    if (`PCI_AM4)
11286
        expected_value = `PCI_BA4_MEM_IO ;
11287
    else
11288
        expected_value = 32'h0000_0000 ;
11289
    `else
11290
    expected_value = 32'h0 ;
11291
    `endif
11292
 
11293
    if( read_data !== expected_value)
11294
    begin
11295
        test_fail("initial value of BAR4 register not as expected") ;
11296
        failed = 1 ;
11297
    end
11298
 
11299
    // BAR5
11300
    configuration_cycle_read
11301
    (
11302
        8'h00,                          // bus number [7:0]
11303
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11304
        3'h0,                           // function number [2:0]
11305
        6'h9,                           // register number [5:0]
11306
        2'h0,                           // type [1:0]
11307
        4'hF,                           // byte enables [3:0]
11308
        read_data                       // data returned from configuration read [31:0]
11309
    ) ;
11310
 
11311
    `ifdef PCI_IMAGE5
11312
    if(`PCI_AM5)
11313
        expected_value = `PCI_BA5_MEM_IO ;
11314
    else
11315
        expected_value = 32'h0000_0000 ;
11316
    `else
11317
    expected_value = 32'h0 ;
11318
    `endif
11319
 
11320
    if( read_data !== expected_value)
11321
    begin
11322
        test_fail("initial value of BAR5 register not as expected") ;
11323
        failed = 1 ;
11324
    end
11325
 
11326
    // write all 1s to BAR0
11327
    read_data = 32'hFFFF_FFFF ;
11328
 
11329
    // BAR0
11330
    configuration_cycle_write
11331
    (
11332
        8'h00,                          // bus number [7:0]
11333
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11334
        3'h0,                           // function number [2:0]
11335
        6'h4,                           // register number [5:0]
11336
        2'h0,                           // type [1:0]
11337
        4'hF,                           // byte enables [3:0]
11338
        read_data                       // data to write [31:0]
11339
    ) ;
11340
 
11341
    expected_value = 32'hFFFF_FFFF ;
11342
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11343
 
11344
    configuration_cycle_read
11345
    (
11346
        8'h00,                          // bus number [7:0]
11347
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11348
        3'h0,                           // function number [2:0]
11349
        6'h4,                           // register number [5:0]
11350
        2'h0,                           // type [1:0]
11351
        4'hF,                           // byte enables [3:0]
11352
        read_data                       // data to write [31:0]
11353
    ) ;
11354
 
11355
    if ( read_data !== expected_value )
11356
    begin
11357
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11358
        failed = 1 ;
11359
    end
11360
 
11361
    // write all 1s to BAR1
11362
    read_data = 32'hFFFF_FFFF ;
11363
 
11364
    // BAR1
11365
    configuration_cycle_write
11366
    (
11367
        8'h00,                          // bus number [7:0]
11368
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11369
        3'h0,                           // function number [2:0]
11370
        6'h5,                           // register number [5:0]
11371
        2'h0,                           // type [1:0]
11372
        4'hF,                           // byte enables [3:0]
11373
        read_data                       // data to write [31:0]
11374
    ) ;
11375
 
11376
    expected_value = {`PCI_AM1, 12'h000} ;
11377
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11378
    if (`PCI_AM1)
11379
        expected_value[0] = `PCI_BA1_MEM_IO ;
11380
 
11381
    configuration_cycle_read
11382
    (
11383
        8'h00,                          // bus number [7:0]
11384
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11385
        3'h0,                           // function number [2:0]
11386
        6'h5,                           // register number [5:0]
11387
        2'h0,                           // type [1:0]
11388
        4'hF,                           // byte enables [3:0]
11389
        read_data                       // data to write [31:0]
11390
    ) ;
11391
 
11392
    if ( read_data !== expected_value )
11393
    begin
11394
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11395
        failed = 1 ;
11396
    end
11397
 
11398
    // write all 1s to BAR2
11399
    read_data = 32'hFFFF_FFFF ;
11400
 
11401
    // BAR2
11402
    configuration_cycle_write
11403
    (
11404
        8'h00,                          // bus number [7:0]
11405
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11406
        3'h0,                           // function number [2:0]
11407
        6'h6,                           // register number [5:0]
11408
        2'h0,                           // type [1:0]
11409
        4'hF,                           // byte enables [3:0]
11410
        read_data                       // data to write [31:0]
11411
    ) ;
11412
 
11413
`ifdef PCI_IMAGE2
11414
    expected_value = {`PCI_AM2, 12'h000} ;
11415
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11416
    if (`PCI_AM2)
11417
        expected_value[0] = `PCI_BA2_MEM_IO ;
11418
`else
11419
    expected_value = 0 ;
11420
`endif
11421
 
11422
    configuration_cycle_read
11423
    (
11424
        8'h00,                          // bus number [7:0]
11425
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11426
        3'h0,                           // function number [2:0]
11427
        6'h6,                           // register number [5:0]
11428
        2'h0,                           // type [1:0]
11429
        4'hF,                           // byte enables [3:0]
11430
        read_data                       // data to write [31:0]
11431
    ) ;
11432
 
11433
    if ( read_data !== expected_value )
11434
    begin
11435
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11436
        failed = 1 ;
11437
    end
11438
 
11439
    // write all 1s to BAR3
11440
    read_data = 32'hFFFF_FFFF ;
11441
 
11442
    // BAR3
11443
    configuration_cycle_write
11444
    (
11445
        8'h00,                          // bus number [7:0]
11446
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11447
        3'h0,                           // function number [2:0]
11448
        6'h7,                           // register number [5:0]
11449
        2'h0,                           // type [1:0]
11450
        4'hF,                           // byte enables [3:0]
11451
        read_data                       // data to write [31:0]
11452
    ) ;
11453
 
11454
`ifdef PCI_IMAGE3
11455
    expected_value = {`PCI_AM3, 12'h000} ;
11456
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11457
    if(`PCI_AM3)
11458
        expected_value[0] = `PCI_BA3_MEM_IO ;
11459
`else
11460
    expected_value = 0 ;
11461
`endif
11462
 
11463
    configuration_cycle_read
11464
    (
11465
        8'h00,                          // bus number [7:0]
11466
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11467
        3'h0,                           // function number [2:0]
11468
        6'h7,                           // register number [5:0]
11469
        2'h0,                           // type [1:0]
11470
        4'hF,                           // byte enables [3:0]
11471
        read_data                       // data to write [31:0]
11472
    ) ;
11473
 
11474
    if ( read_data !== expected_value )
11475
    begin
11476
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11477
        failed = 1 ;
11478
    end
11479
 
11480
    // write all 1s to BAR4
11481
    read_data = 32'hFFFF_FFFF ;
11482
 
11483
    // BAR4
11484
    configuration_cycle_write
11485
    (
11486
        8'h00,                          // bus number [7:0]
11487
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11488
        3'h0,                           // function number [2:0]
11489
        6'h8,                           // register number [5:0]
11490
        2'h0,                           // type [1:0]
11491
        4'hF,                           // byte enables [3:0]
11492
        read_data                       // data to write [31:0]
11493
    ) ;
11494
 
11495
`ifdef PCI_IMAGE4
11496
    expected_value = {`PCI_AM4, 12'h000} ;
11497
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11498
    if(`PCI_AM4)
11499
        expected_value[0] = `PCI_BA4_MEM_IO ;
11500
`else
11501
    expected_value = 0 ;
11502
`endif
11503
 
11504
    configuration_cycle_read
11505
    (
11506
        8'h00,                          // bus number [7:0]
11507
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11508
        3'h0,                           // function number [2:0]
11509
        6'h8,                           // register number [5:0]
11510
        2'h0,                           // type [1:0]
11511
        4'hF,                           // byte enables [3:0]
11512
        read_data                       // data to write [31:0]
11513
    ) ;
11514
 
11515
    if ( read_data !== expected_value )
11516
    begin
11517
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11518
        failed = 1 ;
11519
    end
11520
 
11521
    // write all 1s to BAR5
11522
    read_data = 32'hFFFF_FFFF ;
11523
 
11524
    // BAR5
11525
    configuration_cycle_write
11526
    (
11527
        8'h00,                          // bus number [7:0]
11528
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11529
        3'h0,                           // function number [2:0]
11530
        6'h9,                           // register number [5:0]
11531
        2'h0,                           // type [1:0]
11532
        4'hF,                           // byte enables [3:0]
11533
        read_data                       // data to write [31:0]
11534
    ) ;
11535
 
11536
`ifdef PCI_IMAGE5
11537
    expected_value = {`PCI_AM5, 12'h000} ;
11538
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11539
    if(`PCI_AM5)
11540
        expected_value[0] = `PCI_BA5_MEM_IO ;
11541
`else
11542
    expected_value = 0 ;
11543
`endif
11544
 
11545
    configuration_cycle_read
11546
    (
11547
        8'h00,                          // bus number [7:0]
11548
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11549
        3'h0,                           // function number [2:0]
11550
        6'h9,                           // register number [5:0]
11551
        2'h0,                           // type [1:0]
11552
        4'hF,                           // byte enables [3:0]
11553
        read_data                       // data to write [31:0]
11554
    ) ;
11555
 
11556
    if ( read_data !== expected_value )
11557
    begin
11558
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11559
        failed = 1 ;
11560
    end
11561
`endif
11562
 
11563
    if (!failed)
11564
        test_ok ;
11565
end
11566
endtask
11567
 
11568 15 mihad
task display_warning;
11569
    input [31:0] error_address ;
11570
    input [31:0] expected_data ;
11571
    input [31:0] actual ;
11572
begin
11573
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11574
end
11575
endtask // display warning
11576
 
11577
/*############################################################################
11578
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11579
=====================
11580
############################################################################*/
11581
 
11582
// Task reslease the PCI bus for 'delay' clocks
11583
task do_pause;
11584
  input  [15:0] delay;
11585
  reg    [15:0] cnt;
11586
  begin
11587
    test_start <= 1'b0;  // no device is allowed to take this
11588
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11589
    begin
11590
      if (~pci_reset_comb)
11591
      begin
11592
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11593
      end
11594
      `NO_ELSE;
11595
    end
11596
  end
11597
endtask // do_pause
11598
 
11599
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11600
task DO_REF;
11601
  input  [79:0] name;
11602
  input  [2:0] master_number;
11603
  input  [PCI_BUS_DATA_RANGE:0] address;
11604
  input  [3:0] command;
11605
  input  [PCI_BUS_DATA_RANGE:0] data;
11606
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11607
  input  [9:0] size;
11608
  input   make_addr_par_error, make_data_par_error;
11609
  input  [7:0] master_wait_states;
11610
  input  [7:0] target_wait_states;
11611
  input  [1:0] target_devsel_speed;
11612
  input   fast_back_to_back;
11613
  input  [2:0] target_termination;
11614
  input   expect_master_abort;
11615
  reg     waiting;
11616
  begin
11617
// Cautiously wait for previous command to be done
11618
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11619
    begin
11620
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11621
      begin
11622
        if (~pci_reset_comb)
11623
        begin
11624
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11625
        end
11626
        `NO_ELSE;
11627
      end
11628
      else
11629
      begin
11630
        waiting = 1'b0;  // ready to do next command
11631
      end
11632
    end
11633
    next_test_name[79:0] <= name[79:0];
11634
    test_master_number <= master_number[2:0];
11635
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11636
    test_command[3:0] <= command[3:0] ;
11637
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11638
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11639
    test_size <= size;
11640
    test_make_addr_par_error <= make_addr_par_error;
11641
    test_make_data_par_error <= make_data_par_error;
11642
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11643
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11644
    test_target_initial_wait_states <= target_wait_states[7:4];
11645
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11646
    test_target_devsel_speed <= target_devsel_speed[1:0];
11647
    test_fast_back_to_back <= fast_back_to_back;
11648
    test_target_termination <= target_termination[2:0];
11649
    test_expect_master_abort <= expect_master_abort;
11650
    test_start <= 1'b1;
11651
    if (~pci_reset_comb)
11652
    begin
11653
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11654
    end
11655
    `NO_ELSE;
11656
// wait for new command to start
11657
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11658
    begin
11659
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11660
      begin
11661
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11662
      end
11663
      else
11664
      begin
11665
        waiting = 1'b0;  // ready to do next command
11666
      end
11667
    end
11668
  end
11669
endtask // DO_REF
11670
 
11671
// Use Macros defined in pci_defines.vh as paramaters
11672
 
11673
// DO_REF (name[79:0], master_number[2:0],
11674
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11675
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11676
//          make_addr_par_error, make_data_par_error,
11677
//          master_wait_states[8:0], target_wait_states[8:0],
11678
//          target_devsel_speed[1:0], fast_back_to_back,
11679
//          target_termination[2:0],
11680
//          expect_master_abort);
11681
//
11682
// Example:
11683
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11684
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11685
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11686
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11687
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11688
 
11689
// Access a location with no high-order bits set, assuring that no device responds
11690
task PCIU_CONFIG_READ_MASTER_ABORT;
11691
  input  [79:0] name;
11692
  input  [2:0] master_number;
11693 51 mihad
  input  [31:0] address ;
11694
  input  [3:0] be ;
11695 15 mihad
  begin
11696 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11697
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11698
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11699 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11700
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11701
  end
11702
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11703
 
11704
// Access a location with no high-order bits set, assuring that no device responds
11705
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11706
  input  [79:0] name;
11707
  input  [2:0] master_number;
11708 51 mihad
  input  [31:0] address ;
11709
  input  [3:0] be ;
11710 15 mihad
  begin
11711 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11712
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11713
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11714 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11715
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11716
  end
11717
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11718
 
11719
// Access a location with no high-order bits set, assuring that no device responds
11720
task PCIU_MEM_READ_MASTER_ABORT;
11721
  input  [79:0] name;
11722
  input  [2:0] master_number;
11723
  input  [9:0] size;
11724
  begin
11725
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11726
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11727
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11728
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11729
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11730
  end
11731
endtask // PCIU_MEM_READ_MASTER_ABORT
11732
 
11733
// Access a location with no high-order bits set, assuring that no device responds
11734
task PCIU_MEM_WRITE_MASTER_ABORT;
11735
  input  [79:0] name;
11736
  input  [2:0] master_number;
11737
  input  [9:0] size;
11738
  begin
11739
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11740
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11741
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11742
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11743
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11744
  end
11745
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11746
 
11747
// Do variable length transfers with various paramaters
11748
task PCIU_CONFIG_READ;
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  [3:0] be ;
11754
  input  [9:0] size;
11755
  input  [7:0] master_wait_states;
11756
  input  [7:0] target_wait_states;
11757
  input  [1:0] target_devsel_speed;
11758
  input  [2:0] target_termination;
11759
  begin
11760
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11761
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11762
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11763
              8'h0_0, target_wait_states[7:0],
11764
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11765
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11766
  end
11767
endtask // PCIU_CONFIG_READ
11768
 
11769
task PCIU_CONFIG_WRITE;
11770
  input  [79:0] name;
11771
  input  [2:0] master_number;
11772
  input  [PCI_BUS_DATA_RANGE:0] address;
11773
  input  [PCI_BUS_DATA_RANGE:0] data;
11774
  input  [3:0] be ;
11775
  input  [9:0] size;
11776
  input  [7:0] master_wait_states;
11777
  input  [7:0] target_wait_states;
11778
  input  [1:0] target_devsel_speed;
11779
  input  [2:0] target_termination;
11780
  begin
11781
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11782
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11783
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11784
              8'h0_0, target_wait_states[7:0],
11785
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11786
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11787
  end
11788
endtask // PCIU_CONFIG_WRITE
11789
 
11790
task PCIU_READ;
11791
  input  [2:0] master_number;
11792
  input  [PCI_BUS_DATA_RANGE:0] address;
11793
  input  [3:0] command;
11794
  input  [PCI_BUS_DATA_RANGE:0] data;
11795
  input  [3:0] byte_en;
11796
  input  [9:0] size;
11797
  input  [7:0] master_wait_states;
11798
  input  [7:0] target_wait_states;
11799
  input  [1:0] target_devsel_speed;
11800
  input  [2:0] target_termination;
11801
  reg    [79:0] name;
11802
  begin
11803
    if (command == `BC_MEM_READ)
11804
        name = "MEM_READ  " ;
11805
    else if (command == `BC_MEM_READ_LN)
11806
        name = "MEM_RD_LN " ;
11807
    else if (command == `BC_MEM_READ_MUL )
11808
        name = "MEM_RD_MUL" ;
11809
    else
11810
        name = "WRONG_READ" ;
11811
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11812
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11813
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11814
              8'h0_0, target_wait_states[7:0],
11815
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11816
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11817
  end
11818
endtask // PCIU_READ
11819
 
11820
task PCIU_MEM_READ;
11821
  input  [79:0] name;
11822
  input  [2:0] master_number;
11823
  input  [PCI_BUS_DATA_RANGE:0] address;
11824
  input  [PCI_BUS_DATA_RANGE:0] data;
11825
  input  [9:0] size;
11826
  input  [7:0] master_wait_states;
11827
  input  [7:0] target_wait_states;
11828
  input  [1:0] target_devsel_speed;
11829
  input  [2:0] target_termination;
11830
  begin
11831
 
11832
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11833
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11834
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11835
              8'h0_0, target_wait_states[7:0],
11836
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11837
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11838
  end
11839
endtask // PCIU_MEM_READ
11840
 
11841
task PCIU_IO_READ;
11842
  input  [2:0] master_number;
11843
  input  [PCI_BUS_DATA_RANGE:0] address;
11844
  input  [PCI_BUS_DATA_RANGE:0] data;
11845
  input  [3:0] byte_en ;
11846
  input  [9:0] size;
11847
  input  [2:0] target_termination ;
11848
  begin
11849
 
11850
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11851
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11852
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11853
              8'h0_0, `Test_One_Zero_Target_WS,
11854
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11855
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11856
  end
11857
endtask // PCIU_IO_READ
11858
 
11859
task PCIU_IO_READ_MAKE_PERR;
11860
  input  [2:0] master_number;
11861
  input  [PCI_BUS_DATA_RANGE:0] address;
11862
  input  [PCI_BUS_DATA_RANGE:0] data;
11863
  input  [3:0] byte_en ;
11864
  input  [9:0] size;
11865
  input  [2:0] target_termination ;
11866
  begin
11867
 
11868
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11869
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11870
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11871
              8'h0_0, `Test_One_Zero_Target_WS,
11872
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11873
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11874
  end
11875
endtask // PCIU_IO_READ_MAKE_PERR
11876
 
11877
task PCIU_MEM_READ_LN;
11878
  input  [79:0] name;
11879
  input  [2:0] master_number;
11880
  input  [PCI_BUS_DATA_RANGE:0] address;
11881
  input  [PCI_BUS_DATA_RANGE:0] data;
11882
  input  [9:0] size;
11883
  input  [7:0] master_wait_states;
11884
  input  [7:0] target_wait_states;
11885
  input  [1:0] target_devsel_speed;
11886
  input  [2:0] target_termination;
11887
  begin
11888
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11889
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11890
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11891
              8'h0_0, target_wait_states[7:0],
11892
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11893
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11894
  end
11895
endtask // PCIU_MEM_READ_LN
11896
 
11897
task PCIU_MEM_READ_MUL;
11898
  input  [79:0] name;
11899
  input  [2:0] master_number;
11900
  input  [PCI_BUS_DATA_RANGE:0] address;
11901
  input  [PCI_BUS_DATA_RANGE:0] data;
11902
  input  [9:0] size;
11903
  input  [7:0] master_wait_states;
11904
  input  [7:0] target_wait_states;
11905
  input  [1:0] target_devsel_speed;
11906
  input  [2:0] target_termination;
11907
  begin
11908
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11909
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11910
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11911
              8'h0_0, target_wait_states[7:0],
11912
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11913
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11914
  end
11915
endtask // PCIU_MEM_READ_MUL
11916
 
11917
task PCIU_MEM_READ_MAKE_PERR;
11918
  input  [79:0] name;
11919
  input  [2:0] master_number;
11920
  input  [PCI_BUS_DATA_RANGE:0] address;
11921
  input  [PCI_BUS_DATA_RANGE:0] data;
11922
  input  [9:0] size;
11923
  input  [7:0] master_wait_states;
11924
  input  [7:0] target_wait_states;
11925
  input  [1:0] target_devsel_speed;
11926
  input  [2:0] target_termination;
11927
  begin
11928
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11929
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11930
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11931
              8'h0_0, target_wait_states[7:0],
11932
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11933
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11934
  end
11935
endtask // PCIU_MEM_READ_MAKE_PERR
11936
 
11937
task PCIU_MEM_WRITE;
11938
  input  [79:0] name;
11939
  input  [2:0] master_number;
11940
  input  [PCI_BUS_DATA_RANGE:0] address;
11941
  input  [PCI_BUS_DATA_RANGE:0] data;
11942
  input  [3:0] byte_en;
11943
  input  [9:0] size;
11944
  input  [7:0] master_wait_states;
11945
  input  [7:0] target_wait_states;
11946
  input  [1:0] target_devsel_speed;
11947
  input  [2:0] target_termination;
11948
  begin
11949
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11950
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11951
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11952
              8'h0_0, target_wait_states[7:0],
11953
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11954
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11955
  end
11956
endtask // PCIU_MEM_WRITE
11957
 
11958
task PCIU_IO_WRITE;
11959
  input  [2:0] master_number;
11960
  input  [PCI_BUS_DATA_RANGE:0] address;
11961
  input  [PCI_BUS_DATA_RANGE:0] data;
11962
  input  [3:0] byte_en;
11963
  input  [9:0] size;
11964
  input  [2:0] target_termination ;
11965
  begin
11966
 
11967
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11968
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11969
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11970
              8'h0_0, `Test_One_Zero_Target_WS,
11971
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11972
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11973
  end
11974
endtask // PCIU_IO_WRITE
11975
 
11976
task PCIU_IO_WRITE_MAKE_PERR ;
11977
  input  [2:0] master_number;
11978
  input  [PCI_BUS_DATA_RANGE:0] address;
11979
  input  [PCI_BUS_DATA_RANGE:0] data;
11980
  input  [3:0] byte_en;
11981
  input  [9:0] size;
11982
  input  [2:0] target_termination ;
11983
  begin
11984
 
11985
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11986
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11987
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11988
              8'h0_0, `Test_One_Zero_Target_WS,
11989
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11990
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11991
  end
11992
endtask // PCIU_IO_WRITE
11993
 
11994
task PCIU_MEM_WRITE_MAKE_SERR;
11995
  input  [79:0] name;
11996
  input  [2:0] master_number;
11997
  input  [PCI_BUS_DATA_RANGE:0] address;
11998
  input  [PCI_BUS_DATA_RANGE:0] data;
11999
  input  [9:0] size;
12000
  input  [7:0] master_wait_states;
12001
  input  [7:0] target_wait_states;
12002
  input  [1:0] target_devsel_speed;
12003
  input  [2:0] target_termination;
12004
  begin
12005
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12006
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12007
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12008
              8'h0_0, target_wait_states[7:0],
12009
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12010
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12011
  end
12012
endtask // PCIU_MEM_WRITE_MAKE_SERR
12013
 
12014
task PCIU_MEM_WRITE_MAKE_PERR;
12015
  input  [79:0] name;
12016
  input  [2:0] master_number;
12017
  input  [PCI_BUS_DATA_RANGE:0] address;
12018
  input  [PCI_BUS_DATA_RANGE:0] data;
12019
  input  [9:0] size;
12020
  input  [7:0] master_wait_states;
12021
  input  [7:0] target_wait_states;
12022
  input  [1:0] target_devsel_speed;
12023
  input  [2:0] target_termination;
12024
  begin
12025
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12026
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12027
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12028
              8'h0_0, target_wait_states[7:0],
12029
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12030
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12031
  end
12032
endtask // PCIU_MEM_WRITE
12033
 
12034
/*--------------------------------------------------------------------------
12035
Initialization CASES
12036
--------------------------------------------------------------------------*/
12037
 
12038
// Initialize the basic Config Registers of the PCI bridge target device
12039
task configure_bridge_target;
12040
    reg [11:0] offset ;
12041
    reg [31:0] data ;
12042
    `ifdef HOST
12043
    reg `WRITE_STIM_TYPE   write_data ;
12044
    reg `WB_TRANSFER_FLAGS write_flags ;
12045
    reg `WRITE_RETURN_TYPE write_status ;
12046
    `else
12047
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12048
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12049
    `endif
12050
 
12051
    reg [31:0] temp_var ;
12052
begin
12053
`ifdef HOST //  set Header
12054
    offset  = 12'h4 ; // PCI Header Command register
12055
    data    = 32'h0000_0007 ; // enable master & target operation
12056
 
12057
    write_flags                      = 0 ;
12058
    write_flags`INIT_WAITS           = tb_init_waits ;
12059
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12060
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12061
 
12062
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12063
    write_data`WRITE_SEL      = 4'h1 ;
12064
    write_data`WRITE_TAG_STIM = 0 ;
12065
    write_data`WRITE_DATA     = data ;
12066
 
12067
    next_test_name[79:0] <= "Init_Tar_R";
12068
 
12069
    $display(" bridge target - Enabling master and target operation!");
12070
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12071
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12072
    begin
12073
        $display("Write to configuration space failed! Time %t ", $time) ;
12074
    end
12075
 
12076
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12077
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12078
 
12079
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12080
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12081
 
12082
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12083
    write_data`WRITE_SEL      = 4'hf ;
12084
    write_data`WRITE_TAG_STIM = 0 ;
12085
    write_data`WRITE_DATA     = data ;
12086
 
12087
 `ifdef  NO_CNF_IMAGE
12088
  `ifdef PCI_IMAGE0 //      set P_BA0
12089
 
12090
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12091
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12092
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12093
    begin
12094
        $display("Write to configuration space failed! Time %t ", $time) ;
12095
    end
12096
  `endif
12097
 `else //      set P_BA0
12098
 
12099
    $display(" bridge target - Setting base address P_BA0 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
 
12107
`else // GUEST, set Header, set P_BA0
12108
    data            = 32'h0000_0007 ; // enable master & target operation
12109
    byte_enables    = 4'hF ;
12110
    $display(" bridge target - Enabling master and target operation!");
12111 45 mihad
    configuration_cycle_write(0,                        // bus number
12112
                              `TAR0_IDSEL_INDEX - 11,   // device number
12113
                              0,                        // function number
12114
                              1,                        // register number
12115
                              0,                        // type of configuration cycle
12116
                              byte_enables,             // byte enables
12117
                              data                      // data
12118 15 mihad
                             ) ;
12119
 
12120
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12121
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12122
    byte_enables = 4'hf ;
12123 45 mihad
    configuration_cycle_write(0,                        // bus number
12124
                              `TAR0_IDSEL_INDEX - 11,   // device number
12125
                              0,                        // function number
12126
                              4,                        // register number
12127
                              0,                        // type of configuration cycle
12128
                              byte_enables,             // byte enables
12129
                              data                      // data
12130 15 mihad
                             ) ;
12131
 
12132
`endif
12133
end
12134
endtask // configure_bridge_target
12135
 
12136
// Initialize the basic Config Registers of the PCI bridge target device
12137
task configure_bridge_target_base_addresses;
12138
    reg [11:0] offset ;
12139
    reg [31:0] data ;
12140
    `ifdef HOST
12141
    reg `WRITE_STIM_TYPE   write_data ;
12142
    reg `WB_TRANSFER_FLAGS write_flags ;
12143
    reg `WRITE_RETURN_TYPE write_status ;
12144
    `else
12145
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12146
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12147
    `endif
12148
 
12149
    reg [31:0] temp_var ;
12150
begin
12151
`ifdef HOST //  set Header
12152
    offset  = 12'h4 ; // PCI Header Command register
12153
    data    = 32'h0000_0007 ; // enable master & target operation
12154
 
12155
    write_flags                    = 0 ;
12156
    write_flags`INIT_WAITS         = tb_init_waits ;
12157
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12158
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12159
 
12160
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12161
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12162
 
12163
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12164
    write_data`WRITE_SEL      = 4'h1 ;
12165
    write_data`WRITE_TAG_STIM = 0 ;
12166
    write_data`WRITE_DATA     = data ;
12167
 
12168
    next_test_name[79:0] <= "Init_Tar_R";
12169
 
12170
    $display(" bridge target - Enabling master and target operation!");
12171
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12172
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12173
    begin
12174
        $display("Write to configuration space failed! Time %t ", $time) ;
12175
    end
12176
 
12177
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12178
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12179
 
12180
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12181
    write_data`WRITE_SEL      = 4'hf ;
12182
    write_data`WRITE_TAG_STIM = 0 ;
12183
    write_data`WRITE_DATA     = data ;
12184
 
12185
 `ifdef  NO_CNF_IMAGE
12186
  `ifdef PCI_IMAGE0 //      set P_BA0
12187
 
12188
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12189
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12190
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12191
    begin
12192
        $display("Write to configuration space failed! Time %t ", $time) ;
12193
    end
12194
  `endif
12195
 `else //      set P_BA0
12196
 
12197
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12198
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12199
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12200
    begin
12201
        $display("Write to configuration space failed! Time %t ", $time) ;
12202
    end
12203
 `endif
12204
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12205
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12206
 
12207
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12208
    write_data`WRITE_SEL      = 4'hf ;
12209
    write_data`WRITE_TAG_STIM = 0 ;
12210
    write_data`WRITE_DATA     = data ;
12211
 
12212
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12213
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12214
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12215
    begin
12216
        $display("Write to configuration space failed! Time %t ", $time) ;
12217
    end
12218
 `ifdef PCI_IMAGE2
12219
 
12220
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12221
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12222
 
12223
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12224
    write_data`WRITE_SEL      = 4'hf ;
12225
    write_data`WRITE_TAG_STIM = 0 ;
12226
    write_data`WRITE_DATA     = data ;
12227
 
12228
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12229
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12230
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12231
    begin
12232
        $display("Write to configuration space failed! Time %t ", $time) ;
12233
    end
12234
 `endif
12235
 `ifdef PCI_IMAGE3
12236
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12237
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12238
 
12239
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12240
    write_data`WRITE_SEL      = 4'hf ;
12241
    write_data`WRITE_TAG_STIM = 0 ;
12242
    write_data`WRITE_DATA     = data ;
12243
 
12244
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12245
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12246
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12247
    begin
12248
        $display("Write to configuration space failed! Time %t ", $time) ;
12249
    end
12250
 `endif
12251
 `ifdef PCI_IMAGE4
12252
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12253
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12254
 
12255
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12256
    write_data`WRITE_SEL      = 4'hf ;
12257
    write_data`WRITE_TAG_STIM = 0 ;
12258
    write_data`WRITE_DATA     = data ;
12259
 
12260
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12261
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12262
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12263
    begin
12264
        $display("Write to configuration space failed! Time %t ", $time) ;
12265
    end
12266
 `endif
12267
 `ifdef PCI_IMAGE5
12268
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12269
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12270
 
12271
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12272
    write_data`WRITE_SEL      = 4'hf ;
12273
    write_data`WRITE_TAG_STIM = 0 ;
12274
    write_data`WRITE_DATA     = data ;
12275
 
12276
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12277
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12278
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12279
    begin
12280
        $display("Write to configuration space failed! Time %t ", $time) ;
12281
    end
12282
 `endif
12283
 
12284
`else // GUEST, set Header, set P_BA0
12285
    data            = 32'h0000_0007 ; // enable master & target operation
12286
    byte_enables    = 4'hF ;
12287
    $display(" bridge target - Enabling master and target operation!");
12288 45 mihad
    configuration_cycle_write(0,                        // bus number
12289
                              `TAR0_IDSEL_INDEX - 11,   // device number
12290
                              0,                        // function number
12291
                              1,                        // register number
12292
                              0,                        // type of configuration cycle
12293
                              byte_enables,             // byte enables
12294
                              data                      // data
12295 15 mihad
                             ) ;
12296
 
12297
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12298
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12299
    byte_enables = 4'hf ;
12300 45 mihad
    configuration_cycle_write(0,                        // bus number
12301
                              `TAR0_IDSEL_INDEX - 11,   // device number
12302
                              0,                        // function number
12303
                              4,                        // register number
12304
                              0,                        // type of configuration cycle
12305
                              byte_enables,             // byte enables
12306
                              data                      // data
12307 15 mihad
                             ) ;
12308
 
12309
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12310
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12311
    byte_enables = 4'hf ;
12312 45 mihad
    configuration_cycle_write(0,                        // bus number
12313
                              `TAR0_IDSEL_INDEX - 11,   // device number
12314
                              0,                        // function number
12315
                              5,                        // register number
12316
                              0,                        // type of configuration cycle
12317
                              byte_enables,             // byte enables
12318
                              data                      // data
12319 15 mihad
                             ) ;
12320
 `ifdef PCI_IMAGE2
12321
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12322
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12323
    byte_enables = 4'hf ;
12324 45 mihad
    configuration_cycle_write(0,                        // bus number
12325
                              `TAR0_IDSEL_INDEX - 11,   // device number
12326
                              0,                        // function number
12327
                              6,                        // register number
12328
                              0,                        // type of configuration cycle
12329
                              byte_enables,             // byte enables
12330
                              data                      // data
12331 15 mihad
                             ) ;
12332
 `endif
12333
 `ifdef PCI_IMAGE3
12334
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12335
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12336
    byte_enables = 4'hf ;
12337 45 mihad
    configuration_cycle_write(0,                        // bus number
12338
                              `TAR0_IDSEL_INDEX - 11,   // device number
12339
                              0,                        // function number
12340
                              7,                        // register number
12341
                              0,                        // type of configuration cycle
12342
                              byte_enables,             // byte enables
12343
                              data                      // data
12344 15 mihad
                             ) ;
12345
 `endif
12346
 `ifdef PCI_IMAGE4
12347
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12348
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12349
    byte_enables = 4'hf ;
12350 45 mihad
    configuration_cycle_write(0,                        // bus number
12351
                              `TAR0_IDSEL_INDEX - 11,   // device number
12352
                              0,                        // function number
12353
                              8,                        // register number
12354
                              0,                        // type of configuration cycle
12355
                              byte_enables,             // byte enables
12356
                              data                      // data
12357 15 mihad
                             ) ;
12358
 `endif
12359
 `ifdef PCI_IMAGE5
12360
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12361
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12362
    byte_enables = 4'hf ;
12363 45 mihad
    configuration_cycle_write(0,                        // bus number
12364
                              `TAR0_IDSEL_INDEX - 11,   // device number
12365
                              0,                        // function number
12366
                              9,                        // register number
12367
                              0,                        // type of configuration cycle
12368
                              byte_enables,             // byte enables
12369
                              data                      // data
12370 15 mihad
                             ) ;
12371
 `endif
12372
`endif
12373
end
12374
endtask // configure_bridge_target_base_addresses
12375
 
12376
/*--------------------------------------------------------------------------
12377
Test CASES
12378
--------------------------------------------------------------------------*/
12379
 
12380
// function converts PCI address to WB with the same data as the pci_decoder does
12381
function [31:0] pci_to_wb_addr_convert ;
12382
 
12383
    input [31:0] pci_address ;
12384
    input [31:0] translation_address ;
12385
    input [31:0] translate ;
12386
 
12387
    reg   [31:0] temp_address ;
12388
begin
12389
    if ( translate !== 1 )
12390
    begin
12391
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12392
    end
12393
    else
12394
    begin
12395
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12396
    end
12397
 
12398
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12399
    pci_to_wb_addr_convert = temp_address ;
12400
end
12401
endfunction // pci_to_wb_addr_convert
12402
 
12403
// Test normal write and read to WB slave
12404
task test_normal_wr_rd;
12405
  input  [2:0]  Master_ID;
12406
  input  [PCI_BUS_DATA_RANGE:0] Address;
12407
  input  [PCI_BUS_DATA_RANGE:0] Data;
12408
  input  [3:0]  Be;
12409
  input  [2:0]  Image_num;
12410
  input  [9:0]  Set_size;
12411
  input         Set_addr_translation;
12412
  input         Set_prefetch_enable;
12413
  input  [7:0]  Cache_lsize;
12414
  input         Set_wb_wait_states;
12415
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12416
 
12417
  reg    [31:0] rd_address;
12418
  reg    [31:0] rd_data;
12419
  reg    [3:0]  rd_be;
12420
  reg    [11:0] addr_offset;
12421
  reg    [31:0] read_data;
12422
  reg           continue ;
12423
  reg           ok   ;
12424
  reg    [31:0] expect_address ;
12425
  reg    [31:0] expect_rd_address ;
12426
  reg           expect_we ;
12427
  reg    [9:0]  expect_length_wr ;
12428
  reg    [9:0]  expect_length_rd ;
12429
  reg    [9:0]  expect_length_rd1 ;
12430
  reg    [9:0]  expect_length_rd2 ;
12431
  reg    [3:0]  use_rd_cmd ;
12432
  integer       i ;
12433 35 mihad
  reg           error_monitor_done ;
12434 15 mihad
begin:main
12435
 
12436
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12437
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12438
    $display(" - errors will be reported, but they should not occur!");
12439
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12440
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12441
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12442
    if ( ok !== 1 )
12443
    begin
12444
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12445
        test_fail("write to P_ERR_CS register didn't succeede") ;
12446
        disable main;
12447
    end
12448
 
12449
    `ifdef  ADDR_TRAN_IMPL
12450
 
12451
    // set or clear address translation
12452
    if (Set_addr_translation)
12453
    begin
12454
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12455
        $display(" - address translation will be performed!");
12456
    end
12457
    else
12458
    begin
12459
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12460
        $display(" - address translation will not be performed!");
12461
    end
12462
    // set or clear pre-fetch enable
12463
    if (Set_prefetch_enable)
12464
    begin
12465
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12466
        $display(" - bursts can be performed!");
12467
    end
12468
    else
12469
    begin
12470
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12471
        $display(" - bursts can not be performed!");
12472
    end
12473
 
12474
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12475
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12476
    if ( ok !== 1 )
12477
    begin
12478
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12479
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12480
        disable main;
12481
    end
12482
 
12483
    // predict the address and control signals on WB bus
12484
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12485
    expect_we      = 1'b1 ; // WRITE
12486
 
12487
    `else
12488
 
12489
    // address translation is not implemented
12490
    $display("Address translation is NOT implemented for PCI images!");
12491
    // set or clear pre-fetch enable
12492
    if (Set_prefetch_enable)
12493
    begin
12494
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12495
        $display(" - bursts can be performed!");
12496
    end
12497
    else
12498
    begin
12499
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12500
        $display(" - bursts can not be performed!");
12501
    end
12502
 
12503
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12504
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12505
    if ( ok !== 1 )
12506
    begin
12507
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12508
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12509
        disable main;
12510
    end
12511
 
12512
    // predict the address and control signals on WB bus
12513
    expect_address = Address ;
12514
    expect_we      = 1'b1 ; // WRITE
12515
 
12516
    `endif
12517
 
12518
    // set WB SLAVE parameters
12519
    if (Set_wb_wait_states)
12520
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12521
    else
12522
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12523
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12524
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12525
 
12526
    if ( Set_size > (`PCIW_DEPTH - 2) )
12527
    begin
12528
        expect_length_wr = `PCIW_DEPTH - 2 ;
12529
    end
12530
    else
12531
    begin
12532
        expect_length_wr = Set_size ;
12533
    end
12534
    // write through the PCI bridge to WB slave
12535
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12536
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12537
 
12538
    fork
12539
    begin
12540
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12541
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12542
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12543
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12544
        do_pause( 1 ) ;
12545
    end
12546
    begin
12547
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12548
       if ( ok !== 1 )
12549
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12550
       else
12551
           test_ok ;
12552
    end
12553
    join
12554
 
12555
    // predict the address and control signals on WB bus
12556
    expect_we      = 1'b0 ; // READ
12557
 
12558
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12559
    $display("Memory read through PCI bridge to WB slave!");
12560
 
12561
    if ( expect_length_wr == 1 )
12562
    begin
12563
        if (Set_prefetch_enable)
12564
        begin
12565
            expect_length_rd1 = Cache_lsize ;
12566
            expect_length_rd2 = 0 ;
12567
                // If PCI behavioral master must check received DATA
12568
                master2_check_received_data = 0 ;
12569
                    master1_check_received_data = 0 ;
12570
        end
12571
        else
12572
        begin
12573
            expect_length_rd1 = 1 ;
12574
            expect_length_rd2 = 0 ;
12575
                // If PCI behavioral master must check received DATA
12576
                master2_check_received_data = 1 ;
12577
                    master1_check_received_data = 1 ;
12578
        end
12579
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12580
        expect_length_rd  = expect_length_rd1 ;
12581
    end
12582
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12583
    begin
12584
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12585
        expect_length_rd2 = 0 ;
12586
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12587
        expect_length_rd  = expect_length_rd1 ;
12588
                // If PCI behavioral master must check received DATA
12589
        master2_check_received_data = 1 ;
12590
            master1_check_received_data = 1 ;
12591
    end
12592
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12593
    begin
12594
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12595
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12596
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12597
        expect_length_rd  = expect_length_rd1 ;
12598
                // If PCI behavioral master must check received DATA
12599
                master2_check_received_data = 1 ;
12600
            master1_check_received_data = 1 ;
12601
    end
12602
    else
12603
    begin
12604
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12605
        begin
12606
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12607
            expect_length_rd2 = 0 ;
12608
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12609
            expect_length_rd  = expect_length_rd1 ;
12610
                // If PCI behavioral master must check received DATA
12611
                master2_check_received_data = 0 ;
12612
                    master1_check_received_data = 0 ;
12613
        end
12614
        else
12615
        begin
12616
            if ( expect_length_wr > Cache_lsize )
12617
            begin
12618
                expect_length_rd1 = Cache_lsize ;
12619
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12620
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12621
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12622
                else
12623
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12624
                expect_length_rd  = expect_length_rd1 ;
12625
                        // If PCI behavioral master must check received DATA
12626
                        master2_check_received_data = 1 ;
12627
                            master1_check_received_data = 1 ;
12628
            end
12629
            else
12630
            begin
12631
                expect_length_rd1 = Cache_lsize ;
12632
                expect_length_rd2 = 0 ;
12633
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12634
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12635
                else
12636
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12637
                expect_length_rd  = expect_length_wr ;
12638
                                if ( expect_length_wr == Cache_lsize )
12639
                        begin
12640
                                // If PCI behavioral master must check received DATA
12641
                                master2_check_received_data = 1 ;
12642
                                    master1_check_received_data = 1 ;
12643
                                end
12644
                                else
12645
                                begin
12646
                                // If PCI behavioral master must check received DATA
12647
                                master2_check_received_data = 0 ;
12648
                                    master1_check_received_data = 0 ;
12649
                end
12650
            end
12651
        end
12652
    end
12653
 
12654
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12655
    expect_rd_address = expect_address ;
12656
    rd_data[31:0] = Data[31:0];
12657
    rd_be[3:0] = Be[3:0];
12658
 
12659
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12660
    while (expect_length_rd2 > 0)
12661
    begin
12662
        // do read
12663
        $display("Read %d words!", expect_length_rd);
12664
 
12665
        fork
12666
        begin
12667
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12668
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12669
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12670
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12671
 
12672
            wb_transaction_stop( expect_length_rd - 1) ;
12673
 
12674
            do_pause( 1 ) ;
12675
        end
12676
        begin
12677
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12678
            if ( ok !== 1 )
12679
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12680
 
12681
            repeat( 3 )
12682
                @(posedge pci_clock) ;
12683
 
12684
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12685
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12686
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12687
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12688
 
12689
            do_pause( 1 ) ;
12690
            while ( FRAME === 0 )
12691
                @(posedge pci_clock) ;
12692
 
12693
            while ( IRDY === 0 )
12694
                @(posedge pci_clock) ;
12695
 
12696 35 mihad
            #1 ;
12697
            if ( !error_monitor_done )
12698
                disable monitor_error_event1 ;
12699 15 mihad
        end
12700
        begin:monitor_error_event1
12701 35 mihad
            error_monitor_done = 0 ;
12702 15 mihad
            @(error_event_int) ;
12703
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12704
            ok = 0 ;
12705 35 mihad
            error_monitor_done = 1 ;
12706 15 mihad
        end
12707
        join
12708
 
12709
        // increasing the starting address for PCI master and for WB transaction monitor
12710
        rd_address = rd_address + (4 * expect_length_rd) ;
12711
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12712
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12713
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12714
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12715
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12716
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12717
        for (i=0; i<expect_length_rd; i=i+1)
12718
            rd_be[3:0] = {Be[2:0], Be[3]};
12719
 
12720
        // set parameters for next read
12721
        if ( expect_length_rd2 == 1 )
12722
        begin
12723
                if (Set_prefetch_enable)
12724
                begin
12725
                    expect_length_rd1 = Cache_lsize ;
12726
                    expect_length_rd2 = 0 ;
12727
                        // If PCI behavioral master must check received DATA
12728
                        master2_check_received_data = 0 ;
12729
                            master1_check_received_data = 0 ;
12730
                end
12731
                else
12732
                begin
12733
                    expect_length_rd1 = 1 ;
12734
                    expect_length_rd2 = 0 ;
12735
                        // If PCI behavioral master must check received DATA
12736
                        master2_check_received_data = 1 ;
12737
                            master1_check_received_data = 1 ;
12738
                end
12739
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12740
            expect_length_rd  = expect_length_rd1 ;
12741
        end
12742
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12743
        begin
12744
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12745
            expect_length_rd2 = 0 ;
12746
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12747
            expect_length_rd  = expect_length_rd1 ;
12748
                        // If PCI behavioral master must check received DATA
12749
                        master2_check_received_data = 1 ;
12750
                    master1_check_received_data = 1 ;
12751
        end
12752
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12753
        begin
12754
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12755
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12756
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12757
            expect_length_rd  = expect_length_rd1 ;
12758
                        // If PCI behavioral master must check received DATA
12759
                        master2_check_received_data = 1 ;
12760
                    master1_check_received_data = 1 ;
12761
        end
12762
        else
12763
        begin
12764
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12765
            begin
12766
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12767
                expect_length_rd2 = 0 ;
12768
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12769
                expect_length_rd  = expect_length_rd1 ;
12770
                        // If PCI behavioral master must check received DATA
12771
                        master2_check_received_data = 0 ;
12772
                            master1_check_received_data = 0 ;
12773
            end
12774
            else
12775
            begin
12776
                if ( expect_length_rd2 > Cache_lsize )
12777
                begin
12778
                    expect_length_rd1 = Cache_lsize ;
12779
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12780
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12781
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12782
                    else
12783
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12784
                    expect_length_rd  = expect_length_rd1 ;
12785
                                // If PCI behavioral master must check received DATA
12786
                                master2_check_received_data = 1 ;
12787
                                    master1_check_received_data = 1 ;
12788
                end
12789
                else
12790
                begin
12791
                    expect_length_rd  = expect_length_rd2 ;
12792
                    expect_length_rd1 = Cache_lsize ;
12793
                    expect_length_rd2 = 0 ;
12794
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12795
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12796
                    else
12797
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12798
                                        if ( expect_length_rd2 == Cache_lsize )
12799
                                begin
12800
                                        // If PCI behavioral master must check received DATA
12801
                                        master2_check_received_data = 1 ;
12802
                                            master1_check_received_data = 1 ;
12803
                                        end
12804
                                        else
12805
                                        begin
12806
                                        // If PCI behavioral master must check received DATA
12807
                                        master2_check_received_data = 0 ;
12808
                                            master1_check_received_data = 0 ;
12809
                        end
12810
                end
12811
            end
12812
        end
12813
    end
12814
    // do last read
12815
    $display("Read %d words!", expect_length_rd);
12816
 
12817
    fork
12818
    begin
12819
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12820
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12821
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12822
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12823
 
12824
        wb_transaction_stop(expect_length_rd - 1) ;
12825
        do_pause( 1 ) ;
12826
    end
12827
    begin
12828
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12829
 
12830
        do_pause(3) ;
12831
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12832
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12833
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12834
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12835
        do_pause(1) ;
12836
 
12837
        while ( FRAME === 0 )
12838
            @(posedge pci_clock) ;
12839
 
12840
        while ( IRDY === 0 )
12841
            @(posedge pci_clock) ;
12842
 
12843 35 mihad
        #1 ;
12844
        if ( !error_monitor_done )
12845
            disable monitor_error_event2 ;
12846 15 mihad
    end
12847
    begin:monitor_error_event2
12848 35 mihad
        error_monitor_done = 0 ;
12849 15 mihad
        @(error_event_int) ;
12850
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12851
        ok = 0 ;
12852 35 mihad
        error_monitor_done = 1 ;
12853 15 mihad
    end
12854
    join
12855
 
12856
    if ( ok )
12857
        test_ok ;
12858
 
12859
    // Check that no ERRORs were reported
12860
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12861
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
12862
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12863
    config_read( addr_offset, 4'hF, read_data ) ;
12864
    if ( read_data[8] !== 0 )
12865
    begin
12866
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
12867
        test_fail("error status was set even though no errors occured on WB bus") ;
12868
    end
12869
    else
12870
    begin
12871
        $display("No error was signaled, as expected!");
12872
        test_ok ;
12873
    end
12874
 
12875
end // main
12876
endtask // test_normal_wr_rd
12877
 
12878
// Test erroneous write to WB slave
12879
task test_wb_error_wr;
12880
  input  [2:0]  Master_ID;
12881
  input  [PCI_BUS_DATA_RANGE:0] Address;
12882
  input  [PCI_BUS_DATA_RANGE:0] Data;
12883
  input  [3:0]  Be;
12884
  input  [2:0]  Image_num;
12885
  input  [9:0]  Set_size;
12886
  input         Set_err_and_int_report;
12887
  input         Set_wb_wait_states;
12888
  input  [1:0]  Imm_BefLast_Last_error;
12889
 
12890
  reg    [11:0] addr_offset;
12891
  reg    [31:0] read_data;
12892
  reg           continue ;
12893
  reg           ok   ;
12894
  reg    [9:0]  expect_length ;
12895
  reg    [31:0] expect_address ;
12896
  reg    [0:0]  expect_we ;
12897
  reg    [31:0] rd_address;
12898
  reg    [31:0] rd_data;
12899
  reg    [3:0]  rd_be;
12900
  integer       i ;
12901
begin:main
12902
    if (Set_err_and_int_report)
12903
    begin
12904
        // enable ERROR reporting, because error must be reported and interrupt if required!
12905
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12906
        $display(" - errors will be reported when they will occur!");
12907
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
12908
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12909
        $display(" - interrupt will be reported when error will occur!");
12910
    end
12911
    else
12912
    begin
12913
        // disable ERROR reporting, because error and interrupt must not be reported!
12914
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12915
        $display(" - errors will NOT be reported when they will occur!");
12916
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
12917
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12918
        $display(" - interrupt will NOT be reported when error will occur!");
12919
    end
12920
    // enable/disable ERROR reporting
12921
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
12922
 
12923
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12924
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
12925
    if ( ok !== 1 )
12926
    begin
12927
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12928
        test_fail("PCI Error Control and Status register could not be written") ;
12929
        disable main;
12930
    end
12931
    // enable/disable INTERRUPT reporting
12932
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12933
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
12934
    if ( ok !== 1 )
12935
    begin
12936
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
12937
        test_fail("Interrupt Control register could not be written") ;
12938
        disable main;
12939
    end
12940
 
12941
    `ifdef  ADDR_TRAN_IMPL
12942
 
12943
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
12944
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12945
    config_read( addr_offset, 4'hF, read_data ) ;
12946
    if ( read_data[2] !== 0 )
12947
    begin
12948
        $display("Address translation is set for PCI image%d!", Image_num);
12949
        // predict the address and control signals on WB bus
12950
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
12951
        expect_we      = 1'b1 ; // WRITE
12952
    end
12953
    else
12954
    begin
12955
        $display("Address translation is NOT set for PCI image%d!", Image_num);
12956
        // predict the address and control signals on WB bus
12957
        expect_address = Address ;
12958
        expect_we      = 1'b1 ; // WRITE
12959
    end
12960
 
12961
    `else
12962
 
12963
    // address translation is not implemented
12964
    $display("Address translation is NOT implemented for PCI images!");
12965
    // predict the address and control signals on WB bus
12966
    expect_address = Address ;
12967
    expect_we      = 1'b1 ; // WRITE
12968
 
12969
    `endif
12970
 
12971
    if ( Set_size > (`PCIW_DEPTH - 2) )
12972
    begin
12973
        expect_length = `PCIW_DEPTH - 2 ;
12974
    end
12975
    else
12976
    begin
12977
        expect_length = Set_size ;
12978
    end
12979
 
12980
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
12981
    begin
12982
        $display("ERR termination with first data!");
12983
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
12984
    end
12985
    else if (Imm_BefLast_Last_error == 1)
12986
    begin
12987
        $display("ERR termination before last data!");
12988
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
12989
    end
12990
    else
12991
    begin
12992
        $display("ERR termination with last data!");
12993
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
12994
    end
12995
 
12996
    // write through the PCI bridge to WB slave
12997
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
12998
    fork
12999
    begin
13000
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13001
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13002
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13003
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13004
        do_pause( 1 ) ;
13005
    end
13006
    begin
13007
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13008
        begin
13009
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13010
            if ( ok !== 1 )
13011
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13012
        end
13013
        else if (Imm_BefLast_Last_error == 1)
13014
        begin
13015
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13016
            if ( ok !== 1 )
13017
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13018
        end
13019
        else
13020
        begin
13021
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13022
            if ( ok !== 1 )
13023
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13024
        end
13025
    end
13026
    begin
13027
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13028
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13029
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13030
        else if (Imm_BefLast_Last_error == 1)
13031
        begin
13032
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13033
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13034
            wb_transaction_stop(expect_length-2) ;
13035
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13036
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13037
        end
13038
        else
13039
        begin
13040
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13041
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13042
            wb_transaction_stop(expect_length-1) ;
13043
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13044
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13045
        end
13046
    end
13047
    join
13048
 
13049
    if ( ok )
13050
        test_ok ;
13051
 
13052
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13053
    begin
13054
        rd_data[31:0] = Data[31:0];
13055
        rd_address[31:0] = expect_address;
13056
        rd_be[3:0] = Be[3:0];
13057
    end
13058
    else if (Imm_BefLast_Last_error == 1)
13059
    begin
13060
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13061
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13062
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13063
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13064
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13065
        rd_be[3:0] = Be[3:0];
13066
        for (i=0; i<(expect_length-2); i=i+1)
13067
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13068
    end
13069
    else
13070
    begin
13071
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13072
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13073
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13074
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13075
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13076
        rd_be[3:0] = Be[3:0];
13077
        for (i=0; i<(expect_length-1); i=i+1)
13078
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13079
    end
13080
 
13081
    master2_check_received_data = 0 ;
13082
    master1_check_received_data = 0 ;
13083
 
13084
    // Check if ERRORs were reported
13085
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13086
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13087
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13088
 
13089
    ok = 1 ;
13090
    config_read( addr_offset, 4'hF, read_data ) ;
13091
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13092
    begin
13093
        $display("Error was signaled and reported, as expected!");
13094
        if (read_data[31:28] === rd_be)
13095
            $display("Byte enables written into P_ERR_CS register are as expected!");
13096
        else
13097
        begin
13098
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13099
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13100
            ok = 0 ;
13101
        end
13102
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13103
            $display("Bus command written into P_ERR_CS register is as expected!");
13104
        else
13105
        begin
13106
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13107
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13108
            ok = 0 ;
13109
        end
13110
 
13111
        if ( ok )
13112
            test_ok ;
13113
 
13114
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13115
 
13116
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13117
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13118
        config_read( addr_offset, 4'hF, read_data ) ;
13119
        if (read_data === rd_data)
13120
        begin
13121
            $display("Data written into P_ERR_DATA register is as expected!");
13122
            test_ok ;
13123
        end
13124
        else
13125
        begin
13126
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13127
            test_fail("PCI Erroneous Data register value was wrong") ;
13128
        end
13129
 
13130
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13131
 
13132
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13133
 
13134
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13135
        config_read( addr_offset, 4'hF, read_data ) ;
13136
        if (read_data === rd_address)
13137
        begin
13138
            $display("Address written into P_ERR_ADDR register is as expected!");
13139
            test_ok ;
13140
        end
13141
        else
13142
        begin
13143
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13144
            test_fail("PCI Erroneous Address register value was wrong") ;
13145
        end
13146
    end
13147
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13148
    begin
13149
        $display("Error was signaled and not reported, as expected!");
13150
        test_ok ;
13151
    end
13152
    else
13153
    begin
13154
        $display("Error was signaled and reported, as NOT expected!");
13155
        test_fail("Error status bit was set event though error reporting was disabled") ;
13156
    end
13157
 
13158
    // Check if Interrupts were reported
13159
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13160
 
13161
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13162
    ok = 1 ;
13163
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13164
    config_read( addr_offset, 4'hF, read_data ) ;
13165
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13166
    begin
13167
        $display("Interrupts was signaled and reported, as expected!");
13168
    end
13169
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13170
    begin
13171
        $display("Interrupts was signaled and not reported, as expected!");
13172
    end
13173
    else
13174
    begin
13175
        $display("Interrupt was signaled and reported, as NOT expected!");
13176
        test_fail("PCI Error Interrupt status was set when not expected") ;
13177
        ok = 0 ;
13178
    end
13179
 
13180
    `ifdef HOST
13181
    repeat( 4 )
13182
        @(posedge wb_clock) ;
13183
 
13184
    if ( INT_O === Set_err_and_int_report )
13185
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13186
    else
13187
    begin
13188
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13189
        test_fail("Interrupt request didn't have expected value") ;
13190
        ok = 0 ;
13191
    end
13192
 
13193
    `else // GUEST
13194
    repeat( 4 )
13195
        @(posedge pci_clock) ;
13196
 
13197
    if ( INTA === !Set_err_and_int_report )
13198
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13199
    else
13200
    begin
13201
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13202
        test_fail("Interrupt request didn't have expected value") ;
13203
        ok = 0 ;
13204
    end
13205
 
13206
    `endif
13207
 
13208
    if ( ok )
13209
        test_ok ;
13210
 
13211
    if (Set_err_and_int_report)
13212
    begin
13213
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13214
        $display("Error and Interrupt must be cleared!");
13215
        // clear  ERROR reporting bit
13216
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13217
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13218
        if ( ok !== 1 )
13219
        begin
13220
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13221
            test_fail("PCI Error Control and Status register could not be written to") ;
13222
            disable main;
13223
        end
13224
 
13225
        // clear INTERRUPT reporting bit
13226
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13227
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13228
        if ( ok !== 1 )
13229
        begin
13230
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13231
            test_fail("Interrupt Status register could not be written to") ;
13232
            disable main;
13233
        end
13234
 
13235
        test_ok ;
13236
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13237
        `ifdef HOST
13238
 
13239
        repeat(4)
13240
            @(posedge wb_clock) ;
13241
        if ( INT_O === 1'b0 )
13242
        begin
13243
            $display("Interrupt pin INT_O was correctly cleared!");
13244
            test_ok ;
13245
        end
13246
        else
13247
        begin
13248
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13249
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13250
            disable main;
13251
        end
13252
 
13253
        `else // GUEST
13254
 
13255
        repeat(4)
13256
            @(posedge pci_clock) ;
13257
        if ( INTA === 1'b1 )
13258
        begin
13259
            $display("Interrupt pin INTA was correctly cleared!");
13260
            test_ok ;
13261
        end
13262
        else
13263
        begin
13264
            $display("Interrupt pin INTA was NOT correctly cleared!");
13265
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13266
            disable main;
13267
        end
13268
 
13269
        `endif
13270
 
13271
    end
13272
    else
13273
    begin
13274
        $display("Error and Interrupt don't need to be cleared!");
13275
    end
13276
end // main
13277
endtask // test_wb_error_wr
13278
 
13279
task test_wb_error_rd;
13280
    reg    [11:0] addr_offset ;
13281
    reg    [11:0] ctrl_offset ;
13282
    reg    [11:0] ba_offset ;
13283
    reg    [11:0] am_offset ;
13284
    reg    [11:0] ta_offset ;
13285
    reg    [31:0] read_data;
13286
    reg           ok   ;
13287
    reg    [9:0]  expect_length ;
13288
    reg    [31:0] expect_address ;
13289
    reg    [0:0]  expect_we ;
13290
    reg    [31:0] rd_address;
13291
    reg    [31:0] rd_data;
13292
    reg    [3:0]  rd_be;
13293
    integer       i ;
13294
    reg           do_mem_aborts ;
13295
    reg           do_io_aborts ;
13296 35 mihad
    reg           error_monitor_done ;
13297 15 mihad
begin:main
13298
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13299
 
13300
    if ( target_mem_image !== -1 )
13301
    begin
13302
        do_mem_aborts = 1 ;
13303
 
13304
        if (target_mem_image === 1)
13305
        begin
13306
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13307
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13308
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13309
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13310
        end
13311
        else if (target_mem_image === 2)
13312
        begin
13313
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13314
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13315
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13316
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13317
        end
13318
        else if (target_mem_image === 3)
13319
        begin
13320
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13321
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13322
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13323
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13324
        end
13325
        else if (target_mem_image === 4)
13326
        begin
13327
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13328
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13329
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13330
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13331
        end
13332
        else if (target_mem_image === 5)
13333
        begin
13334
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13335
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13336
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13337
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13338
        end
13339
    end
13340
    else
13341
        do_mem_aborts = 0 ;
13342
 
13343
    if ( do_mem_aborts )
13344
    begin
13345
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13346
 
13347
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13348
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13349
        if ( ok !== 1 )
13350
        begin
13351
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13352
            test_fail("PCI Error Control and Status register could not be written") ;
13353
            disable main;
13354
        end
13355
 
13356
        // enable INTERRUPT reporting
13357
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13358
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13359
        if ( ok !== 1 )
13360
        begin
13361
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13362
            test_fail("Interrupt Control register could not be written") ;
13363
            disable main;
13364
        end
13365
 
13366
        addr_offset = 12'h010 + (4*target_mem_image) ;
13367
 
13368
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13369
        if ( ok !== 1 )
13370
        begin
13371
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13372
            test_fail("PCI Base Address register could not be written") ;
13373
            disable main;
13374
        end
13375
 
13376
        // disable address translation and enable prefetch so read bursts can be performed
13377
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13378
        if ( ok !== 1 )
13379
        begin
13380
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13381
            test_fail("PCI Image Control register could not be written") ;
13382
            disable main;
13383
        end
13384
 
13385
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13386
        if ( ok !== 1 )
13387
        begin
13388
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13389
            test_fail("PCI Address Mask register could not be written") ;
13390
            disable main;
13391
        end
13392
 
13393
        addr_offset = 12'h00C ;
13394
 
13395
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13396
        if ( ok !== 1 )
13397
        begin
13398
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13399
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13400
            disable main;
13401
        end
13402
 
13403
        // disable PCI master data checking
13404
        master1_check_received_data = 0 ;
13405
 
13406
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13407
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13408
 
13409
 
13410
        // do a single read error terminated on WB bus
13411
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13412
 
13413
        fork
13414
        begin
13415
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13416
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13417
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13418
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13419
 
13420
            do_pause( 1 ) ;
13421
        end
13422
        begin
13423
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13424
 
13425
            if ( ok !== 1 )
13426
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13427
 
13428
            do_pause(3) ;
13429
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13430
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13431
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13432
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13433
            do_pause(1) ;
13434
 
13435
            while ( FRAME === 0 )
13436
                @(posedge pci_clock) ;
13437
 
13438
            while ( IRDY === 0 )
13439
                @(posedge pci_clock) ;
13440
 
13441 35 mihad
            #1 ;
13442
            if ( !error_monitor_done )
13443
                disable monitor_error_event1 ;
13444 15 mihad
        end
13445
        begin:monitor_error_event1
13446 35 mihad
            error_monitor_done = 0 ;
13447 15 mihad
            @(error_event_int) ;
13448
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13449
            ok = 0 ;
13450 35 mihad
            error_monitor_done = 1 ;
13451 15 mihad
        end
13452
        join
13453
 
13454
        if ( ok )
13455
            test_ok ;
13456 26 mihad
 
13457
        @(posedge pci_clock) ;
13458
        @(posedge pci_clock) ;
13459
        @(posedge wb_clock) ;
13460
        @(posedge wb_clock) ;
13461 15 mihad
 
13462
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13463
        addr_offset = 12'h004 ;
13464
        config_read(addr_offset, 4'hF, read_data) ;
13465
        ok = 1 ;
13466
        if ( read_data[27] !== 1 )
13467
        begin
13468
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13469
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13470
            ok = 0 ;
13471
        end
13472
        if ( read_data[28] !== 0 )
13473
        begin
13474
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13475
            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") ;
13476
            ok = 0 ;
13477
        end
13478
        if ( read_data[29] !== 0 )
13479
        begin
13480
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13481
            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") ;
13482
            ok = 0 ;
13483
        end
13484
 
13485
        // clear statuses
13486
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13487
        if ( !ok )
13488
        begin
13489
            test_fail("write to PCI Device Status register failed") ;
13490
            $display("Couldn't write PCI Device Status register") ;
13491
            disable main ;
13492
        end
13493
 
13494
        if ( ok )
13495
            test_ok ;
13496
 
13497
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13498
 
13499
        ok = 1 ;
13500
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13501
 
13502
        config_read(addr_offset, 4'hF, read_data) ;
13503
        if (read_data[8] !== 0)
13504
        begin
13505
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13506
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13507
            ok = 0 ;
13508
        end
13509
        else
13510
            test_ok ;
13511
 
13512
        if ( ok !== 1 )
13513
        begin
13514
            config_write(addr_offset, read_data, 4'hF, ok) ;
13515
            if ( !ok )
13516
            begin
13517
                test_fail("PCI Error Control and Status register could not be written") ;
13518
                disable main ;
13519
            end
13520
        end
13521
 
13522
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13523
        fork
13524
        begin
13525
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13526
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13527
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13528
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13529
 
13530
            do_pause( 1 ) ;
13531
        end
13532
        begin
13533
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13534
 
13535
            if ( ok !== 1 )
13536
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13537
 
13538
            do_pause(3) ;
13539
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13540
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13541
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13542
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13543
            do_pause(1) ;
13544
 
13545
            while ( FRAME === 0 )
13546
                @(posedge pci_clock) ;
13547
 
13548
            while ( IRDY === 0 )
13549
                @(posedge pci_clock) ;
13550
 
13551 35 mihad
            #1 ;
13552
            if ( !error_monitor_done )
13553
                disable monitor_error_event2 ;
13554 15 mihad
        end
13555
        begin:monitor_error_event2
13556 35 mihad
            error_monitor_done = 0 ;
13557 15 mihad
            @(error_event_int) ;
13558
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13559
            ok = 0 ;
13560 35 mihad
            error_monitor_done = 1 ;
13561 15 mihad
        end
13562
        join
13563
 
13564
        if ( ok )
13565
            test_ok ;
13566
 
13567 26 mihad
        @(posedge pci_clock) ;
13568
        @(posedge pci_clock) ;
13569
        @(posedge wb_clock) ;
13570
        @(posedge wb_clock) ;
13571
 
13572 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13573
        addr_offset = 12'h004 ;
13574
        config_read(addr_offset, 4'hF, read_data) ;
13575
        ok = 1 ;
13576
        if ( read_data[27] !== 1 )
13577
        begin
13578
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13579
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13580
            ok = 0 ;
13581
        end
13582
        if ( read_data[28] !== 0 )
13583
        begin
13584
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13585
            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") ;
13586
            ok = 0 ;
13587
        end
13588
        if ( read_data[29] !== 0 )
13589
        begin
13590
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13591
            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") ;
13592
            ok = 0 ;
13593
        end
13594
 
13595
        // clear statuses
13596
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13597
        if ( !ok )
13598
        begin
13599
            test_fail("write to PCI Device Status register failed") ;
13600
            $display("Couldn't write PCI Device Status register") ;
13601
            disable main ;
13602
        end
13603
 
13604
        if ( ok )
13605
            test_ok ;
13606
 
13607
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13608
 
13609
        ok = 1 ;
13610
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13611
 
13612
        config_read(addr_offset, 4'hF, read_data) ;
13613
        if (read_data[8] !== 0)
13614
        begin
13615
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13616
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13617
            ok = 0 ;
13618
        end
13619
        else
13620
            test_ok ;
13621
 
13622
        if ( ok !== 1 )
13623
        begin
13624
            config_write(addr_offset, read_data, 4'hF, ok) ;
13625
            if ( !ok )
13626
            begin
13627
                test_fail("PCI Error Control and Status register could not be written") ;
13628
                disable main ;
13629
            end
13630
        end
13631
 
13632
        // do a single read error terminated on WB bus
13633
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13634
 
13635
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13636
 
13637
        fork
13638
        begin
13639
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13640
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13641
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13642
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13643
 
13644
            do_pause( 1 ) ;
13645
        end
13646
        begin
13647
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13648
 
13649
            if ( ok !== 1 )
13650
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13651
 
13652
            do_pause(3) ;
13653
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13654
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13655
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13656
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13657
            do_pause(1) ;
13658
 
13659
            while ( FRAME === 0 )
13660
                @(posedge pci_clock) ;
13661
 
13662
            while ( IRDY === 0 )
13663
                @(posedge pci_clock) ;
13664
 
13665 35 mihad
            if ( !error_monitor_done )
13666
                disable monitor_error_event3 ;
13667 15 mihad
        end
13668
        begin:monitor_error_event3
13669 35 mihad
            error_monitor_done = 0 ;
13670 15 mihad
            @(error_event_int) ;
13671
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13672
            ok = 0 ;
13673 35 mihad
            error_monitor_done = 1 ;
13674 15 mihad
        end
13675
        join
13676
 
13677
        if ( ok )
13678
            test_ok ;
13679
 
13680 26 mihad
        @(posedge pci_clock) ;
13681
        @(posedge pci_clock) ;
13682
        @(posedge wb_clock) ;
13683
        @(posedge wb_clock) ;
13684
 
13685 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13686
        addr_offset = 12'h004 ;
13687
        config_read(addr_offset, 4'hF, read_data) ;
13688
        ok = 1 ;
13689
        if ( read_data[27] !== 1 )
13690
        begin
13691
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13692
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13693
            ok = 0 ;
13694
        end
13695
        if ( read_data[28] !== 0 )
13696
        begin
13697
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13698
            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") ;
13699
            ok = 0 ;
13700
        end
13701
        if ( read_data[29] !== 0 )
13702
        begin
13703
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13704
            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") ;
13705
            ok = 0 ;
13706
        end
13707
 
13708
        // clear statuses
13709
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13710
        if ( !ok )
13711
        begin
13712
            test_fail("write to PCI Device Status register failed") ;
13713
            $display("Couldn't write PCI Device Status register") ;
13714
            disable main ;
13715
        end
13716
 
13717
        if ( ok )
13718
            test_ok ;
13719
 
13720
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13721
 
13722
        ok = 1 ;
13723
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13724
 
13725
        config_read(addr_offset, 4'hF, read_data) ;
13726
        if (read_data[8] !== 0)
13727
        begin
13728
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13729
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13730
            ok = 0 ;
13731
        end
13732
        else
13733
            test_ok ;
13734
 
13735
        if ( ok !== 1 )
13736
        begin
13737
            config_write(addr_offset, read_data, 4'hF, ok) ;
13738
            if ( !ok )
13739
            begin
13740
                test_fail("PCI Error Control and Status register could not be written") ;
13741
                disable main ;
13742
            end
13743
        end
13744
 
13745
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13746
 
13747
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13748
 
13749
        fork
13750
        begin
13751
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13752
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13753
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13754
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13755
 
13756
            do_pause( 1 ) ;
13757
        end
13758
        begin
13759
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13760
 
13761
            if ( ok !== 1 )
13762
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13763
 
13764
            do_pause(3) ;
13765
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13766
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13767
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13768
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13769
            do_pause(1) ;
13770
 
13771
            while ( FRAME === 0 )
13772
                @(posedge pci_clock) ;
13773
 
13774
            while ( IRDY === 0 )
13775
                @(posedge pci_clock) ;
13776
 
13777 35 mihad
            #1 ;
13778
            if ( !error_monitor_done )
13779
                disable monitor_error_event4 ;
13780 15 mihad
        end
13781
        begin:monitor_error_event4
13782 35 mihad
            error_monitor_done = 0 ;
13783 15 mihad
            @(error_event_int) ;
13784
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13785
            ok = 0 ;
13786 35 mihad
            error_monitor_done = 1 ;
13787 15 mihad
        end
13788
        begin
13789
            wb_transaction_stop( 1 ) ;
13790
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13791
        end
13792
        join
13793
 
13794
        if ( ok )
13795
            test_ok ;
13796
 
13797 26 mihad
        @(posedge pci_clock) ;
13798
        @(posedge pci_clock) ;
13799
        @(posedge wb_clock) ;
13800
        @(posedge wb_clock) ;
13801
 
13802 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13803
        addr_offset = 12'h004 ;
13804
        config_read(addr_offset, 4'hF, read_data) ;
13805
        ok = 1 ;
13806
        if ( read_data[27] !== 1 )
13807
        begin
13808
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13809
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13810
            ok = 0 ;
13811
        end
13812
        if ( read_data[28] !== 0 )
13813
        begin
13814
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13815
            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") ;
13816
            ok = 0 ;
13817
        end
13818
        if ( read_data[29] !== 0 )
13819
        begin
13820
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13821
            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") ;
13822
            ok = 0 ;
13823
        end
13824
 
13825
        // clear statuses
13826
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13827
        if ( !ok )
13828
        begin
13829
            test_fail("write to PCI Device Status register failed") ;
13830
            $display("Couldn't write PCI Device Status register") ;
13831
            disable main ;
13832
        end
13833
 
13834
        if ( ok )
13835
            test_ok ;
13836
 
13837
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13838
 
13839
        ok = 1 ;
13840
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13841
 
13842
        config_read(addr_offset, 4'hF, read_data) ;
13843
        if (read_data[8] !== 0)
13844
        begin
13845
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13846
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13847
            ok = 0 ;
13848
        end
13849
        else
13850
            test_ok ;
13851
 
13852
        if ( ok !== 1 )
13853
        begin
13854
            config_write(addr_offset, read_data, 4'hF, ok) ;
13855
            if ( !ok )
13856
            begin
13857
                test_fail("PCI Error Control and Status register could not be written") ;
13858
                disable main ;
13859
            end
13860
        end
13861
 
13862
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13863
 
13864
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13865
 
13866
        fork
13867
        begin
13868
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13869
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13870
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13871
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13872
 
13873
            do_pause( 1 ) ;
13874
        end
13875
        begin
13876
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13877
 
13878
            if ( ok !== 1 )
13879
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13880
 
13881
            do_pause(3) ;
13882
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13883
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13884
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13885
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13886
            do_pause(1) ;
13887
 
13888
            while ( FRAME === 0 )
13889
                @(posedge pci_clock) ;
13890
 
13891
            while ( IRDY === 0 )
13892
                @(posedge pci_clock) ;
13893
 
13894 35 mihad
            #1 ;
13895
            if ( !error_monitor_done )
13896
                disable monitor_error_event5 ;
13897 15 mihad
        end
13898
        begin:monitor_error_event5
13899 35 mihad
            error_monitor_done = 0 ;
13900 15 mihad
            @(error_event_int) ;
13901
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13902
            ok = 0 ;
13903 35 mihad
            error_monitor_done = 1 ;
13904 15 mihad
        end
13905
        begin
13906
            wb_transaction_stop( 3 ) ;
13907
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13908
        end
13909
        join
13910
 
13911
        if ( ok )
13912
            test_ok ;
13913
 
13914 26 mihad
        @(posedge pci_clock) ;
13915
        @(posedge pci_clock) ;
13916
        @(posedge wb_clock) ;
13917
        @(posedge wb_clock) ;
13918
 
13919 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13920
        addr_offset = 12'h004 ;
13921
        config_read(addr_offset, 4'hF, read_data) ;
13922
        ok = 1 ;
13923
        if ( read_data[27] !== 1 )
13924
        begin
13925
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13926
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13927
            ok = 0 ;
13928
        end
13929
        if ( read_data[28] !== 0 )
13930
        begin
13931
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13932
            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") ;
13933
            ok = 0 ;
13934
        end
13935
        if ( read_data[29] !== 0 )
13936
        begin
13937
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13938
            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") ;
13939
            ok = 0 ;
13940
        end
13941
 
13942
        // clear statuses
13943
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13944
        if ( !ok )
13945
        begin
13946
            test_fail("write to PCI Device Status register failed") ;
13947
            $display("Couldn't write PCI Device Status register") ;
13948
            disable main ;
13949
        end
13950
 
13951
        if ( ok )
13952
            test_ok ;
13953
 
13954
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13955
 
13956
        ok = 1 ;
13957
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13958
 
13959
        config_read(addr_offset, 4'hF, read_data) ;
13960
        if (read_data[8] !== 0)
13961
        begin
13962
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13963
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13964
            ok = 0 ;
13965
        end
13966
        else
13967
            test_ok ;
13968
 
13969
        if ( ok !== 1 )
13970
        begin
13971
            config_write(addr_offset, read_data, 4'hF, ok) ;
13972
            if ( !ok )
13973
            begin
13974
                test_fail("PCI Error Control and Status register could not be written") ;
13975
                disable main ;
13976
            end
13977
        end
13978
 
13979
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
13980
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13981
        fork
13982
        begin
13983
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13984
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13985
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13986
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13987
 
13988
            do_pause( 1 ) ;
13989
        end
13990
        begin
13991
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13992
 
13993
            if ( ok !== 1 )
13994
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13995
 
13996
            do_pause(3) ;
13997
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13998
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13999
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14000
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14001
            do_pause(1) ;
14002
 
14003
            while ( FRAME === 0 )
14004
                @(posedge pci_clock) ;
14005
 
14006
            while ( IRDY === 0 )
14007
                @(posedge pci_clock) ;
14008
 
14009 35 mihad
            #1 ;
14010
            if ( !error_monitor_done )
14011
                disable monitor_error_event6 ;
14012 15 mihad
        end
14013
        begin:monitor_error_event6
14014 35 mihad
            error_monitor_done = 0 ;
14015 15 mihad
            @(error_event_int) ;
14016
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14017
            ok = 0 ;
14018 35 mihad
            error_monitor_done = 1 ;
14019 15 mihad
        end
14020
        begin
14021
            wb_transaction_stop( 3 ) ;
14022
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14023
        end
14024
        join
14025
 
14026
        if ( ok )
14027
            test_ok ;
14028
 
14029 26 mihad
        @(posedge pci_clock) ;
14030
        @(posedge pci_clock) ;
14031
        @(posedge wb_clock) ;
14032
        @(posedge wb_clock) ;
14033
 
14034 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14035
        addr_offset = 12'h004 ;
14036
        config_read(addr_offset, 4'hF, read_data) ;
14037
        ok = 1 ;
14038
        if ( read_data[27] !== 1 )
14039
        begin
14040
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14041
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14042
            ok = 0 ;
14043
        end
14044
        if ( read_data[28] !== 0 )
14045
        begin
14046
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14047
            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") ;
14048
            ok = 0 ;
14049
        end
14050
        if ( read_data[29] !== 0 )
14051
        begin
14052
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14053
            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") ;
14054
            ok = 0 ;
14055
        end
14056
 
14057
        // clear statuses
14058
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14059
        if ( !ok )
14060
        begin
14061
            test_fail("write to PCI Device Status register failed") ;
14062
            $display("Couldn't write PCI Device Status register") ;
14063
            disable main ;
14064
        end
14065
 
14066
        if ( ok )
14067
            test_ok ;
14068
 
14069
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14070
 
14071
        ok = 1 ;
14072
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14073
 
14074
        config_read(addr_offset, 4'hF, read_data) ;
14075
        if (read_data[8] !== 0)
14076
        begin
14077
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14078
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14079
            ok = 0 ;
14080
        end
14081
        else
14082
            test_ok ;
14083
 
14084
        if ( ok !== 1 )
14085
        begin
14086
            config_write(addr_offset, read_data, 4'hF, ok) ;
14087
            if ( !ok )
14088
            begin
14089
                test_fail("PCI Error Control and Status register could not be written") ;
14090
                disable main ;
14091
            end
14092
        end
14093
 
14094
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14095
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14096
        fork
14097
        begin
14098
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14099
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14100
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14101
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14102
 
14103
            do_pause( 1 ) ;
14104
        end
14105
        begin
14106
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14107
 
14108
            if ( ok !== 1 )
14109
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14110
 
14111
            do_pause(3) ;
14112
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14113
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14114
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14115
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14116
            do_pause(1) ;
14117
 
14118
            while ( FRAME === 0 )
14119
                @(posedge pci_clock) ;
14120
 
14121
            while ( IRDY === 0 )
14122
                @(posedge pci_clock) ;
14123
 
14124 35 mihad
            #1 ;
14125
            if ( !error_monitor_done )
14126
                disable monitor_error_event7 ;
14127 15 mihad
        end
14128
        begin:monitor_error_event7
14129 35 mihad
            error_monitor_done = 0 ;
14130 15 mihad
            @(error_event_int) ;
14131
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14132
            ok = 0 ;
14133 35 mihad
            error_monitor_done = 1 ;
14134 15 mihad
        end
14135
        begin
14136
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14137
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14138
        end
14139
        join
14140
 
14141
        if ( ok )
14142
            test_ok ;
14143
 
14144 26 mihad
        @(posedge pci_clock) ;
14145
        @(posedge pci_clock) ;
14146
        @(posedge wb_clock) ;
14147
        @(posedge wb_clock) ;
14148
 
14149 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14150
        addr_offset = 12'h004 ;
14151
        config_read(addr_offset, 4'hF, read_data) ;
14152
        ok = 1 ;
14153
        if ( read_data[27] !== 1 )
14154
        begin
14155
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14156
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14157
            ok = 0 ;
14158
        end
14159
        if ( read_data[28] !== 0 )
14160
        begin
14161
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14162
            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") ;
14163
            ok = 0 ;
14164
        end
14165
        if ( read_data[29] !== 0 )
14166
        begin
14167
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14168
            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") ;
14169
            ok = 0 ;
14170
        end
14171
 
14172
        // clear statuses
14173
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14174
        if ( !ok )
14175
        begin
14176
            test_fail("write to PCI Device Status register failed") ;
14177
            $display("Couldn't write PCI Device Status register") ;
14178
            disable main ;
14179
        end
14180
 
14181
        if ( ok )
14182
            test_ok ;
14183
 
14184
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14185
 
14186
        ok = 1 ;
14187
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14188
 
14189
        config_read(addr_offset, 4'hF, read_data) ;
14190
        if (read_data[8] !== 0)
14191
        begin
14192
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14193
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14194
            ok = 0 ;
14195
        end
14196
        else
14197
            test_ok ;
14198
 
14199
        if ( ok !== 1 )
14200
        begin
14201
            config_write(addr_offset, read_data, 4'hF, ok) ;
14202
            if ( !ok )
14203
            begin
14204
                test_fail("PCI Error Control and Status register could not be written") ;
14205
                disable main ;
14206
            end
14207
        end
14208
 
14209
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14210
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14211
        fork
14212
        begin
14213
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14214
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14215
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14216
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14217
 
14218
            do_pause( 1 ) ;
14219
        end
14220
        begin
14221
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14222
 
14223
            if ( ok !== 1 )
14224
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14225
 
14226
            do_pause(3) ;
14227
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14228
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14229
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14230
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14231
            do_pause(1) ;
14232
 
14233
            while ( FRAME === 0 )
14234
                @(posedge pci_clock) ;
14235
 
14236
            while ( IRDY === 0 )
14237
                @(posedge pci_clock) ;
14238
 
14239 35 mihad
            #1 ;
14240
            if ( !error_monitor_done )
14241
                disable monitor_error_event8 ;
14242 15 mihad
        end
14243
        begin:monitor_error_event8
14244 35 mihad
            error_monitor_done = 0 ;
14245 15 mihad
            @(error_event_int) ;
14246
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14247
            ok = 0 ;
14248 35 mihad
            error_monitor_done = 1 ;
14249 15 mihad
        end
14250
        begin
14251
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14252
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14253
        end
14254
        join
14255
 
14256
        if ( ok )
14257
            test_ok ;
14258
 
14259 26 mihad
        @(posedge pci_clock) ;
14260
        @(posedge pci_clock) ;
14261
        @(posedge wb_clock) ;
14262
        @(posedge wb_clock) ;
14263
 
14264 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14265
 
14266
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14267
        addr_offset = 12'h004 ;
14268
        config_read(addr_offset, 4'hF, read_data) ;
14269
        ok = 1 ;
14270
        if ( read_data[27] !== 1 )
14271
        begin
14272
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14273
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14274
            ok = 0 ;
14275
        end
14276
        if ( read_data[28] !== 0 )
14277
        begin
14278
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14279
            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") ;
14280
            ok = 0 ;
14281
        end
14282
        if ( read_data[29] !== 0 )
14283
        begin
14284
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14285
            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") ;
14286
            ok = 0 ;
14287
        end
14288
 
14289
        // clear statuses
14290
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14291
        if ( !ok )
14292
        begin
14293
            test_fail("write to PCI Device Status register failed") ;
14294
            $display("Couldn't write PCI Device Status register") ;
14295
            disable main ;
14296
        end
14297
 
14298
        if ( ok )
14299
            test_ok ;
14300
 
14301
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14302
 
14303
        ok = 1 ;
14304
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14305
 
14306
        config_read(addr_offset, 4'hF, read_data) ;
14307
        if (read_data[8] !== 0)
14308
        begin
14309
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14310
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14311
            ok = 0 ;
14312
        end
14313
        else
14314
            test_ok ;
14315
 
14316
        if ( ok !== 1 )
14317
        begin
14318
            config_write(addr_offset, read_data, 4'hF, ok) ;
14319
            if ( !ok )
14320
            begin
14321
                test_fail("PCI Error Control and Status register could not be written") ;
14322
                disable main ;
14323
            end
14324
        end
14325
 
14326
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14327
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14328
        fork
14329
        begin
14330
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14331
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14332
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14333
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14334
 
14335
            do_pause( 1 ) ;
14336
        end
14337
        begin
14338
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14339
 
14340
            if ( ok !== 1 )
14341
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14342
 
14343
            do_pause(3) ;
14344
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14345
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14346
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14347
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14348
            do_pause(1) ;
14349
 
14350
            while ( FRAME === 0 )
14351
                @(posedge pci_clock) ;
14352
 
14353
            while ( IRDY === 0 )
14354
                @(posedge pci_clock) ;
14355
 
14356 35 mihad
            #1 ;
14357
            if ( !error_monitor_done )
14358
                disable monitor_error_event9 ;
14359 15 mihad
        end
14360
        begin:monitor_error_event9
14361 35 mihad
            error_monitor_done = 0 ;
14362 15 mihad
            @(error_event_int) ;
14363
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14364
            ok = 0 ;
14365 35 mihad
            error_monitor_done = 1 ;
14366 15 mihad
        end
14367
        begin
14368
            wb_transaction_stop( 3 ) ;
14369
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14370
        end
14371
        join
14372
 
14373
        if ( ok )
14374
            test_ok ;
14375
 
14376
        // now check all other statuses too
14377
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14378
        ok = 1 ;
14379
 
14380
        addr_offset = 12'h004 ;
14381
        config_read(addr_offset, 4'hF, read_data) ;
14382
        if (read_data[31] !== 0)
14383
        begin
14384
            $display("Detected Parity Error bit set for no reason") ;
14385
            test_fail("Detected Parity Error bit was set for no reason") ;
14386
            ok = 0 ;
14387
        end
14388
 
14389
        if (read_data[30] !== 0)
14390
        begin
14391
            $display("Signaled System Error bit set for no reason") ;
14392
            test_fail("Signaled System Error bit was set for no reason") ;
14393
            ok = 0 ;
14394
        end
14395
 
14396
        if (read_data[29] !== 0)
14397
        begin
14398
            $display("Received Master Abort bit set for no reason") ;
14399
            test_fail("Received Master Abort bit was set for no reason") ;
14400
            ok = 0 ;
14401
        end
14402
 
14403
        if (read_data[28] !== 0)
14404
        begin
14405
            $display("Received Target Abort bit set for no reason");
14406
            test_fail("Received Target Abort bit was set for no reason") ;
14407
            ok = 0 ;
14408
        end
14409
 
14410
        if (read_data[27] !== 0)
14411
        begin
14412
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14413
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14414
            ok = 0 ;
14415
        end
14416
 
14417
        if (read_data[24] !== 0)
14418
        begin
14419
            $display("Master Data Parity Error bit set for no reason") ;
14420
            test_fail("Master Data Parity Error bit was set for no reason") ;
14421
            ok = 0 ;
14422
        end
14423
 
14424
        if ( ok )
14425
            test_ok ;
14426
 
14427
        test_name = "DISABLE IMAGE" ;
14428 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14429 15 mihad
        if ( ok !== 1 )
14430
        begin
14431
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14432
            test_fail("PCI Address Mask register could not be written") ;
14433
            disable main;
14434
        end
14435
    end
14436
 
14437
    if ( target_io_image !== -1 )
14438
    begin
14439
        do_io_aborts = 1 ;
14440
 
14441
        if (target_io_image === 1)
14442
        begin
14443
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14444
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14445
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14446
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14447
        end
14448
        else if (target_io_image === 2)
14449
        begin
14450
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14451
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14452
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14453
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14454
        end
14455
        else if (target_io_image === 3)
14456
        begin
14457
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14458
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14459
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14460
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14461
        end
14462
        else if (target_io_image === 4)
14463
        begin
14464
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14465
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14466
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14467
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14468
        end
14469
        else if (target_io_image === 5)
14470
        begin
14471
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14472
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14473
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14474
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14475
        end
14476
    end
14477
    else
14478
        do_io_aborts = 0 ;
14479
 
14480
    if ( do_io_aborts )
14481
    begin
14482
 
14483
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14484
 
14485
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14486
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14487
        if ( ok !== 1 )
14488
        begin
14489
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14490
            test_fail("PCI Error Control and Status register could not be written") ;
14491
            disable main;
14492
        end
14493
 
14494
        // enable INTERRUPT reporting
14495
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14496
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14497
        if ( ok !== 1 )
14498
        begin
14499
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14500
            test_fail("Interrupt Control register could not be written") ;
14501
            disable main;
14502
        end
14503
 
14504
        addr_offset = 12'h010 + (4*target_io_image) ;
14505
 
14506
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14507
        if ( ok !== 1 )
14508
        begin
14509
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14510
            test_fail("PCI Base Address register could not be written") ;
14511
            disable main;
14512
        end
14513
 
14514
        // disable address translation and enable prefetch so read bursts can be performed
14515
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14516
        if ( ok !== 1 )
14517
        begin
14518
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14519
            test_fail("PCI Image Control register could not be written") ;
14520
            disable main;
14521
        end
14522
 
14523
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14524
        if ( ok !== 1 )
14525
        begin
14526
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14527
            test_fail("PCI Address Mask register could not be written") ;
14528
            disable main;
14529
        end
14530
 
14531
        addr_offset = 12'h00C ;
14532
 
14533
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14534
        if ( ok !== 1 )
14535
        begin
14536
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14537
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14538
            disable main;
14539
        end
14540
 
14541
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14542
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14543
 
14544
        // do a single read error terminated on WB bus
14545
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14546
 
14547
        fork
14548
        begin
14549
            PCIU_IO_READ
14550
             (
14551
                `Test_Master_1,
14552
                Target_Base_Addr_R[target_io_image],
14553
                32'hAAAA_5555,
14554
                4'h0,
14555
                1,
14556
                `Test_Target_Retry_On
14557
             );
14558
 
14559
            do_pause( 1 ) ;
14560
        end
14561
        begin
14562
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14563
 
14564
            if ( ok !== 1 )
14565
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14566
 
14567
            do_pause(3) ;
14568
 
14569
            PCIU_IO_READ
14570
             (
14571
                `Test_Master_1,
14572
                Target_Base_Addr_R[target_io_image],
14573
                32'hAAAA_5555,
14574
                4'h0,
14575
                1,
14576
                `Test_Target_Abort_On
14577
             );
14578
 
14579
            do_pause( 1 ) ;
14580
 
14581
            while ( FRAME === 0 )
14582
                @(posedge pci_clock) ;
14583
 
14584
            while ( IRDY === 0 )
14585
                @(posedge pci_clock) ;
14586
 
14587 35 mihad
            #1 ;
14588
            if ( !error_monitor_done )
14589
                disable monitor_error_event10 ;
14590 15 mihad
        end
14591
        begin:monitor_error_event10
14592 35 mihad
            error_monitor_done = 0 ;
14593 15 mihad
            @(error_event_int) ;
14594
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14595
            ok = 0 ;
14596 35 mihad
            error_monitor_done = 1 ;
14597 15 mihad
        end
14598
        join
14599
 
14600
        if ( ok )
14601
            test_ok ;
14602
 
14603 26 mihad
        @(posedge pci_clock) ;
14604
        @(posedge pci_clock) ;
14605
        @(posedge wb_clock) ;
14606
        @(posedge wb_clock) ;
14607
 
14608 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14609
        addr_offset = 12'h004 ;
14610
        config_read(addr_offset, 4'hF, read_data) ;
14611
        ok = 1 ;
14612
        if ( read_data[27] !== 1 )
14613
        begin
14614
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14615
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14616
            ok = 0 ;
14617
        end
14618
        if ( read_data[28] !== 0 )
14619
        begin
14620
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14621
            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") ;
14622
            ok = 0 ;
14623
        end
14624
        if ( read_data[29] !== 0 )
14625
        begin
14626
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14627
            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") ;
14628
            ok = 0 ;
14629
        end
14630
 
14631
        // clear statuses
14632
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14633
        if ( !ok )
14634
        begin
14635
            test_fail("write to PCI Device Status register failed") ;
14636
            $display("Couldn't write PCI Device Status register") ;
14637
            disable main ;
14638
        end
14639
 
14640
        if ( ok )
14641
            test_ok ;
14642
 
14643
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14644
 
14645
        ok = 1 ;
14646
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14647
 
14648
        config_read(addr_offset, 4'hF, read_data) ;
14649
        if (read_data[8] !== 0)
14650
        begin
14651
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14652
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14653
            ok = 0 ;
14654
        end
14655
        else
14656
            test_ok ;
14657
 
14658
        if ( ok !== 1 )
14659
        begin
14660
            config_write(addr_offset, read_data, 4'hF, ok) ;
14661
            if ( !ok )
14662
            begin
14663
                test_fail("PCI Error Control and Status register could not be written") ;
14664
                disable main ;
14665
            end
14666
        end
14667
 
14668
        test_name = "DISABLE IMAGE" ;
14669 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14670 15 mihad
        if ( ok !== 1 )
14671
        begin
14672
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14673
            test_fail("PCI Address Mask register could not be written") ;
14674
            disable main;
14675
        end
14676
 
14677
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14678
 
14679
    end
14680
end // main
14681
endtask // test_wb_error_rd
14682
 
14683
task test_target_abort ;
14684
    input [2:0]  image_num ;
14685
    reg   [11:0] pci_ctrl_offset ;
14686
    reg   [11:0] ctrl_offset ;
14687
    reg   [11:0] ba_offset ;
14688
    reg   [11:0] am_offset ;
14689
    reg   [11:0] ta_offset ;
14690
    reg   [31:0] pci_address ;
14691
    reg   [3:0]  byte_enables ;
14692
    reg          ok ;
14693 35 mihad
    reg          error_monitor_done ;
14694 15 mihad
begin:main
14695
    pci_ctrl_offset = 12'h4 ;
14696
    if (image_num === 0)
14697
    begin
14698
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14699
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14700
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14701
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14702
    end
14703
    else if (image_num === 1)
14704
    begin
14705
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14706
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14707
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14708
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14709
    end
14710
    else if (image_num === 2)
14711
    begin
14712
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14713
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14714
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14715
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14716
    end
14717
    else if (image_num === 3)
14718
    begin
14719
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14720
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14721
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14722
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14723
    end
14724
    else if (image_num === 4)
14725
    begin
14726
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14727
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14728
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14729
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14730
    end
14731
    else if (image_num === 5)
14732
    begin
14733
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14734
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14735
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14736
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14737
    end
14738
 
14739
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14740
 
14741
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14742
    if ( ok !== 1 )
14743
    begin
14744
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14745
        test_fail("PCI Base Address register could not be written") ;
14746
        disable main ;
14747
    end
14748
 
14749
    // Set Address Mask of IMAGE
14750
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14751
    if ( ok !== 1 )
14752
    begin
14753
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14754
        test_fail("PCI Address Mask register could not be written") ;
14755
        disable main ;
14756
    end
14757
 
14758
    // Set Translation Address of IMAGE
14759
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14760
    if ( ok !== 1 )
14761
    begin
14762
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14763
        test_fail("PCI Translation Address Register could not be written") ;
14764
        disable main ;
14765
    end
14766
 
14767
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14768
    if ( ok !== 1 )
14769
    begin
14770
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14771
        test_fail("PCI Image Control register could not be written") ;
14772
        disable main ;
14773
    end
14774
 
14775
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14776
 
14777
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14778
 
14779
    pci_address  = Target_Base_Addr_R[image_num] ;
14780
    byte_enables = 4'b0001 ;
14781
 
14782
    fork
14783
    begin
14784
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14785
        do_pause ( 1 ) ;
14786
    end
14787
    begin:monitor_error_event1
14788 35 mihad
        error_monitor_done = 0 ;
14789 15 mihad
        @(error_event_int) ;
14790
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14791
        ok = 0 ;
14792 35 mihad
        error_monitor_done = 1 ;
14793 15 mihad
    end
14794
    begin
14795
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14796
        @(posedge pci_clock) ;
14797 35 mihad
        #1 ;
14798
        if ( !error_monitor_done )
14799
            disable monitor_error_event1 ;
14800 15 mihad
    end
14801
    join
14802
 
14803
    if ( ok )
14804
        test_ok ;
14805
 
14806
    ok = 1 ;
14807
 
14808
    fork
14809
    begin
14810
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14811
        do_pause ( 1 ) ;
14812
    end
14813
    begin:monitor_error_event2
14814 35 mihad
        error_monitor_done = 0 ;
14815 15 mihad
        @(error_event_int) ;
14816
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14817
        ok = 0 ;
14818 35 mihad
        error_monitor_done = 1 ;
14819 15 mihad
    end
14820
    begin
14821
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14822
        @(posedge pci_clock) ;
14823 35 mihad
        #1 ;
14824
        if ( !error_monitor_done )
14825
            disable monitor_error_event2 ;
14826 15 mihad
    end
14827
    join
14828
 
14829
    if ( ok )
14830
        test_ok ;
14831
 
14832
    ok = 1 ;
14833
 
14834
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14835
    byte_enables = 4'b0011 ;
14836
 
14837
    fork
14838
    begin
14839
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14840
        do_pause ( 1 ) ;
14841
    end
14842
    begin:monitor_error_event3
14843 35 mihad
        error_monitor_done = 0 ;
14844 15 mihad
        @(error_event_int) ;
14845
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14846
        ok = 0 ;
14847 35 mihad
        error_monitor_done = 1 ;
14848 15 mihad
    end
14849
    begin
14850
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14851
        @(posedge pci_clock) ;
14852 35 mihad
        if ( !error_monitor_done )
14853
            disable monitor_error_event3 ;
14854 15 mihad
    end
14855
    join
14856
 
14857
    if ( ok )
14858
        test_ok ;
14859
 
14860
    ok = 1 ;
14861
 
14862
    byte_enables = 4'b0000 ;
14863
 
14864
    fork
14865
    begin
14866
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14867
        do_pause ( 1 ) ;
14868
    end
14869
    begin:monitor_error_event4
14870 35 mihad
        error_monitor_done = 0 ;
14871 15 mihad
        @(error_event_int) ;
14872
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14873
        ok = 0 ;
14874 35 mihad
        error_monitor_done = 1 ;
14875 15 mihad
    end
14876
    begin
14877
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14878
        @(posedge pci_clock) ;
14879 35 mihad
        #1 ;
14880
        if ( !error_monitor_done )
14881
            disable monitor_error_event4 ;
14882 15 mihad
    end
14883
    join
14884
 
14885
    if ( ok )
14886
        test_ok ;
14887
 
14888
    ok = 1 ;
14889
 
14890
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
14891
    byte_enables = 4'b0111 ;
14892
 
14893
    fork
14894
    begin
14895
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14896
        do_pause ( 1 ) ;
14897
    end
14898
    begin:monitor_error_event5
14899 35 mihad
        error_monitor_done = 0 ;
14900 15 mihad
        @(error_event_int) ;
14901
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14902
        ok = 0 ;
14903 35 mihad
        error_monitor_done = 1 ;
14904 15 mihad
    end
14905
    begin
14906
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14907
        @(posedge pci_clock) ;
14908 35 mihad
        #1 ;
14909
        if ( !error_monitor_done )
14910
            disable monitor_error_event5 ;
14911 15 mihad
    end
14912
    join
14913
 
14914
    if ( ok )
14915
        test_ok ;
14916
 
14917
    ok = 1 ;
14918
 
14919
    byte_enables = 4'b0010 ;
14920
 
14921
    fork
14922
    begin
14923
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14924
        do_pause ( 1 ) ;
14925
    end
14926
    begin:monitor_error_event6
14927 35 mihad
        error_monitor_done = 0 ;
14928 15 mihad
        @(error_event_int) ;
14929
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14930
        ok = 0 ;
14931 35 mihad
        error_monitor_done = 1 ;
14932 15 mihad
    end
14933
    begin
14934
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14935
        @(posedge pci_clock) ;
14936 35 mihad
        #1 ;
14937
        if ( !error_monitor_done )
14938
            disable monitor_error_event6 ;
14939 15 mihad
    end
14940
    join
14941
 
14942
    if ( ok )
14943
        test_ok ;
14944
 
14945
    ok = 1 ;
14946
    byte_enables = 4'b0001 ;
14947
 
14948
    fork
14949
    begin
14950
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14951
        do_pause ( 1 ) ;
14952
    end
14953
    begin:monitor_error_event7
14954 35 mihad
        error_monitor_done = 0 ;
14955 15 mihad
        @(error_event_int) ;
14956
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14957
        ok = 0 ;
14958 35 mihad
        error_monitor_done = 1 ;
14959 15 mihad
    end
14960
    begin
14961
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14962
        @(posedge pci_clock) ;
14963 35 mihad
        #1 ;
14964
        if ( !error_monitor_done )
14965
            disable monitor_error_event7 ;
14966 15 mihad
    end
14967
    join
14968
 
14969
    if ( ok )
14970
        test_ok ;
14971
 
14972
    ok = 1 ;
14973
    byte_enables = 4'b0000 ;
14974
 
14975
    fork
14976
    begin
14977
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14978
        do_pause ( 1 ) ;
14979
    end
14980
    begin:monitor_error_event8
14981 35 mihad
        error_monitor_done = 0 ;
14982 15 mihad
        @(error_event_int) ;
14983
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14984
        ok = 0 ;
14985 35 mihad
        error_monitor_done = 1 ;
14986 15 mihad
    end
14987
    begin
14988
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14989
        @(posedge pci_clock) ;
14990 35 mihad
        #1 ;
14991
        if ( !error_monitor_done )
14992
            disable monitor_error_event8 ;
14993 15 mihad
    end
14994
    join
14995
 
14996
    if ( ok )
14997
        test_ok ;
14998
 
14999
    ok = 1 ;
15000
 
15001
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15002
    byte_enables = 4'b0110 ;
15003
 
15004
    fork
15005
    begin
15006
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15007
        do_pause ( 1 ) ;
15008
    end
15009
    begin:monitor_error_event9
15010 35 mihad
        error_monitor_done = 0 ;
15011 15 mihad
        @(error_event_int) ;
15012
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15013
        ok = 0 ;
15014 35 mihad
        error_monitor_done = 1 ;
15015 15 mihad
    end
15016
    begin
15017
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15018
        @(posedge pci_clock) ;
15019 35 mihad
        #1 ;
15020
        if ( !error_monitor_done )
15021
            disable monitor_error_event9 ;
15022 15 mihad
    end
15023
    join
15024
 
15025
    if ( ok )
15026
        test_ok ;
15027
 
15028
    ok = 1 ;
15029
    fork
15030
    begin
15031
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15032
        do_pause ( 1 ) ;
15033
    end
15034
    begin:monitor_error_event10
15035 35 mihad
        error_monitor_done = 0 ;
15036 15 mihad
        @(error_event_int) ;
15037
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15038
        ok = 0 ;
15039 35 mihad
        error_monitor_done = 1 ;
15040 15 mihad
    end
15041
    begin
15042
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15043
        @(posedge pci_clock) ;
15044 35 mihad
 
15045
        #1 ;
15046
        if ( !error_monitor_done )
15047
            disable monitor_error_event10 ;
15048 15 mihad
    end
15049
    join
15050
 
15051
    if ( ok )
15052
        test_ok ;
15053
 
15054
    ok = 1 ;
15055
 
15056
    byte_enables = 4'b0001 ;
15057
 
15058
    fork
15059
    begin
15060
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15061
        do_pause ( 1 ) ;
15062
    end
15063
    begin:monitor_error_event11
15064 35 mihad
        error_monitor_done = 0 ;
15065 15 mihad
        @(error_event_int) ;
15066
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15067
        ok = 0 ;
15068 35 mihad
        error_monitor_done = 1 ;
15069 15 mihad
    end
15070
    begin
15071
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15072
        @(posedge pci_clock) ;
15073 35 mihad
        #1 ;
15074
        if ( !error_monitor_done )
15075
            disable monitor_error_event11 ;
15076 15 mihad
    end
15077
    join
15078
 
15079
    if ( ok )
15080
        test_ok ;
15081
 
15082
    ok = 1 ;
15083
 
15084
    byte_enables = 4'b0101 ;
15085
 
15086
    fork
15087
    begin
15088
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15089
        do_pause ( 1 ) ;
15090
    end
15091
    begin:monitor_error_event12
15092 35 mihad
        error_monitor_done = 0 ;
15093 15 mihad
        @(error_event_int) ;
15094
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15095
        ok = 0 ;
15096 35 mihad
        error_monitor_done = 1 ;
15097 15 mihad
    end
15098
    begin
15099
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15100
        @(posedge pci_clock) ;
15101 35 mihad
        #1 ;
15102
        if ( !error_monitor_done )
15103
            disable monitor_error_event12 ;
15104 15 mihad
    end
15105
    join
15106
 
15107
    if ( ok )
15108
        test_ok ;
15109
 
15110
    ok = 1 ;
15111
 
15112
    byte_enables = 4'b0011 ;
15113
 
15114
    fork
15115
    begin
15116
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15117
        do_pause ( 1 ) ;
15118
    end
15119
    begin:monitor_error_event13
15120 35 mihad
        error_monitor_done = 0 ;
15121 15 mihad
        @(error_event_int) ;
15122
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15123
        ok = 0 ;
15124 35 mihad
        error_monitor_done = 1 ;
15125 15 mihad
    end
15126
    begin
15127
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15128
        @(posedge pci_clock) ;
15129 35 mihad
        #1 ;
15130
        if ( !error_monitor_done )
15131
            disable monitor_error_event13 ;
15132 15 mihad
    end
15133
    join
15134
 
15135
    if ( ok )
15136
        test_ok ;
15137
 
15138
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15139
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15140
    ok = 1 ;
15141
    if ( pci_address[27] !== 1 )
15142
    begin
15143
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15144
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15145
        ok = 0 ;
15146
    end
15147
    if ( pci_address[28] !== 0 )
15148
    begin
15149
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15150
        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") ;
15151
        ok = 0 ;
15152
    end
15153
    if ( pci_address[29] !== 0 )
15154
    begin
15155
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15156
        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") ;
15157
        ok = 0 ;
15158
    end
15159
 
15160
    // clear statuses
15161
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15162
    if ( !ok )
15163
    begin
15164
        test_fail("write to PCI Device Status register failed") ;
15165
        $display("Couldn't write PCI Device Status register") ;
15166
        disable main ;
15167
    end
15168
 
15169
    if ( ok )
15170
        test_ok ;
15171
 
15172
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15173
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15174
    if ( pci_address[8] !== 0 )
15175
    begin
15176
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15177
    end
15178
    else
15179
        test_ok ;
15180
 
15181
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15182
 
15183
    test_name = "DISABLE IMAGE" ;
15184
 
15185 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15186 15 mihad
    if ( ok !== 1 )
15187
    begin
15188
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15189
        test_fail("PCI Address Mask register could not be written") ;
15190
        disable main ;
15191
    end
15192
end
15193
endtask // test_target_abort
15194
 
15195
task test_target_io_wr_rd ;
15196
    input [2:0]  image_num ;
15197
    input        translate_address ;
15198
    input [11:0] img_ctrl_offset ;
15199
    reg   [31:0] expect_address ;
15200
    reg   [31:0] pci_address ;
15201
    reg          translation ;
15202
    reg   [31:0] read_data ;
15203
    reg   [3:0]  byte_enables ;
15204
    reg          ok ;
15205
    reg          pci_ok ;
15206
    reg          wb_ok ;
15207
    integer      i ;
15208 35 mihad
    reg          error_monitor_done ;
15209 15 mihad
begin:main
15210
    `ifdef ADDR_TRAN_IMPL
15211
        translation = translate_address ;
15212
    `else
15213
        translation = 0 ;
15214
    `endif
15215
 
15216
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15217
 
15218
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15219
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15220
    if ( translation )
15221
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15222
    else
15223
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15224
 
15225
    if ( !ok )
15226
    begin
15227
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15228
        test_fail("PCI Image Control register could not be written") ;
15229
    end
15230
 
15231
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15232
    pci_address  = Target_Base_Addr_R[image_num] ;
15233
    byte_enables = 4'b0000 ;
15234
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15235
 
15236
    fork
15237
    begin
15238
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15239
        do_pause ( 1 ) ;
15240
    end
15241
    begin
15242
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15243
        if ( wb_ok !== 1 )
15244
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15245
 
15246 35 mihad
        #1 ;
15247
        if ( !error_monitor_done )
15248
            disable monitor_pci_error_1 ;
15249 15 mihad
    end
15250
    begin:monitor_pci_error_1
15251 35 mihad
        error_monitor_done = 0 ;
15252 15 mihad
        pci_ok = 1 ;
15253
        @(error_event_int) ;
15254
        pci_ok = 0 ;
15255
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15256 35 mihad
        error_monitor_done = 1 ;
15257 15 mihad
    end
15258
    join
15259
 
15260
    byte_enables = 4'b1111 ;
15261
    for ( i = 0 ; i < 4 ; i = i + 1 )
15262
    begin:loop_1
15263
        byte_enables[i] = 0 ;
15264
        if ( i > 0 )
15265
            byte_enables[i - 1] = 1 ;
15266
        fork
15267
        begin
15268
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15269
            do_pause ( 1 ) ;
15270
        end
15271
        begin
15272
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15273
            if ( wb_ok !== 1 )
15274
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15275
 
15276 35 mihad
            #1 ;
15277
            if ( !error_monitor_done )
15278
                disable monitor_pci_error_2 ;
15279 15 mihad
        end
15280
        begin:monitor_pci_error_2
15281 35 mihad
            error_monitor_done = 0 ;
15282 15 mihad
            pci_ok = 1 ;
15283
            @(error_event_int) ;
15284
            pci_ok = 0 ;
15285
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15286 35 mihad
            error_monitor_done = 1 ;
15287 15 mihad
        end
15288
        join
15289
 
15290
        if ( !pci_ok || !wb_ok )
15291
            disable loop_1 ;
15292
 
15293
        pci_address = pci_address + 1 ;
15294
        expect_address = expect_address + 1 ;
15295
    end
15296
 
15297
    if ( pci_ok && wb_ok )
15298
        test_ok ;
15299
 
15300
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15301
    pci_address  = Target_Base_Addr_R[image_num] ;
15302
    byte_enables = 4'b1100 ;
15303
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15304
 
15305
    master1_check_received_data = 1 ;
15306
    fork
15307
    begin
15308
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15309
        do_pause( 1 ) ;
15310
    end
15311
    begin
15312
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15313
        if ( wb_ok !== 1 )
15314
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15315
 
15316
        do_pause ( 2 ) ;
15317
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15318
        do_pause ( 16 ) ;
15319
 
15320 35 mihad
        #1 ;
15321
        if ( !error_monitor_done )
15322
            disable monitor_pci_error_3 ;
15323 15 mihad
    end
15324
    begin:monitor_pci_error_3
15325 35 mihad
        error_monitor_done = 0 ;
15326 15 mihad
        pci_ok = 1 ;
15327
        @(error_event_int) ;
15328
        pci_ok = 0 ;
15329
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15330 35 mihad
        error_monitor_done = 1 ;
15331 15 mihad
    end
15332
    join
15333
 
15334
    if ( !pci_ok || !wb_ok )
15335
    begin
15336
        disable main ;
15337
    end
15338
 
15339
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15340
    byte_enables = 4'b0011 ;
15341
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15342
 
15343
    master1_check_received_data = 1 ;
15344
    fork
15345
    begin
15346
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15347
        do_pause( 1 ) ;
15348
    end
15349
    begin
15350
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15351
        if ( wb_ok !== 1 )
15352
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15353
 
15354
        do_pause ( 2 ) ;
15355
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15356
        do_pause ( 16 ) ;
15357
 
15358 35 mihad
        #1 ;
15359
        if ( !error_monitor_done )
15360
            disable monitor_pci_error_4 ;
15361 15 mihad
    end
15362
    begin:monitor_pci_error_4
15363 35 mihad
        error_monitor_done = 0 ;
15364 15 mihad
        pci_ok = 1 ;
15365
        @(error_event_int) ;
15366
        pci_ok = 0 ;
15367
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15368 35 mihad
        error_monitor_done = 1 ;
15369 15 mihad
    end
15370
    join
15371
 
15372
    if ( !pci_ok || !wb_ok )
15373
    begin
15374
        disable main ;
15375
    end
15376
 
15377
    pci_address  = Target_Base_Addr_R[image_num] ;
15378
    byte_enables = 4'b0000 ;
15379
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15380
 
15381
    master1_check_received_data = 1 ;
15382
    fork
15383
    begin
15384
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15385
        do_pause( 1 ) ;
15386
    end
15387
    begin
15388
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15389
        if ( wb_ok !== 1 )
15390
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15391
 
15392
        do_pause ( 2 ) ;
15393
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15394
        do_pause ( 16 ) ;
15395
 
15396 35 mihad
        #1 ;
15397
        if ( !error_monitor_done )
15398
            disable monitor_pci_error_5 ;
15399 15 mihad
    end
15400
    begin:monitor_pci_error_5
15401 35 mihad
        error_monitor_done = 0 ;
15402 15 mihad
        pci_ok = 1 ;
15403
        @(error_event_int) ;
15404
        pci_ok = 0 ;
15405
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15406 35 mihad
        error_monitor_done = 1 ;
15407 15 mihad
    end
15408
    join
15409
 
15410
    if ( pci_ok && wb_ok )
15411
        test_ok ;
15412
end
15413
endtask // test_target_io_wr_rd
15414
 
15415
task test_target_io_err_wr ;
15416
    input [2:0]  image_num ;
15417
    input        translate_address ;
15418
    input [11:0] img_ctrl_offset ;
15419
    input        enable_error_report ;
15420
    input        enable_error_interrupt ;
15421
 
15422
    reg   [31:0] expect_address ;
15423
    reg   [31:0] pci_address ;
15424
    reg          translation ;
15425
    reg   [31:0] read_data ;
15426
    reg   [3:0]  byte_enables ;
15427
    reg          ok ;
15428
    reg          pci_ok ;
15429
    reg          wb_ok ;
15430
    integer      i ;
15431
    reg   [11:0] offset ;
15432 35 mihad
    reg          error_monitor_done ;
15433 15 mihad
begin:main
15434
    `ifdef ADDR_TRAN_IMPL
15435
        translation = translate_address ;
15436
    `else
15437
        translation = 0 ;
15438
    `endif
15439
 
15440
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15441
 
15442
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15443
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15444
    if ( translation )
15445
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15446
    else
15447
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15448
 
15449
    if ( !ok )
15450
    begin
15451
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15452
        test_fail("PCI Image Control register could not be written") ;
15453
    end
15454
 
15455
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15456
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15457
    if ( enable_error_report )
15458
    begin
15459
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15460
        if ( !ok )
15461
        begin
15462
            test_fail("PCI Error Control and Status register could not be written") ;
15463
            disable main ;
15464
        end
15465
    end
15466
    else
15467
    begin
15468
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15469
        if ( !ok )
15470
        begin
15471
            test_fail("PCI Error Control and Status register could not be written") ;
15472
            disable main ;
15473
        end
15474
    end
15475
 
15476
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15477
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15478
    if ( enable_error_interrupt )
15479
    begin
15480
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15481
        if ( !ok )
15482
        begin
15483
            test_fail("Interrupt Control register could not be written") ;
15484
            disable main ;
15485
        end
15486
    end
15487
    else
15488
    begin
15489
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15490
        if ( !ok )
15491
        begin
15492
            test_fail("Interrupt Control register could not be written") ;
15493
            disable main ;
15494
        end
15495
    end
15496
 
15497
    pci_address  = Target_Base_Addr_R[image_num] ;
15498
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15499
 
15500
    byte_enables = 4'b1111 ;
15501
 
15502
    for ( i = 0 ; i < 4 ; i = i + 1 )
15503
    begin:loop_1
15504
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15505
        byte_enables[i] = 0 ;
15506
        if ( i > 0 )
15507
            byte_enables[i - 1] = 1 ;
15508
 
15509
        fork
15510
        begin
15511
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15512
            do_pause ( 1 ) ;
15513
        end
15514
        begin
15515
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15516
            if ( wb_ok !== 1 )
15517
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15518
 
15519 35 mihad
            #1 ;
15520
            if ( !error_monitor_done )
15521
                disable monitor_pci_error_2 ;
15522 15 mihad
        end
15523
        begin:monitor_pci_error_2
15524 35 mihad
            error_monitor_done = 0 ;
15525 15 mihad
            pci_ok = 1 ;
15526
            @(error_event_int) ;
15527
            pci_ok = 0 ;
15528
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15529 35 mihad
            error_monitor_done = 1 ;
15530 15 mihad
        end
15531
        join
15532
 
15533
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15534
        `ifdef HOST
15535
 
15536
            repeat ( 4 )
15537
                @( posedge wb_clock ) ;
15538
 
15539
            if ( enable_error_interrupt && enable_error_report )
15540
            begin
15541
                if ( INT_O !== 1 )
15542
                begin
15543
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15544
                end
15545
            end
15546
            else
15547
            begin
15548
                if ( INT_O !== 0 )
15549
                begin
15550
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15551
                end
15552
            end
15553
        `else
15554
            repeat ( 4 )
15555
                @( posedge pci_clock ) ;
15556
 
15557
            if ( enable_error_interrupt && enable_error_report )
15558
            begin
15559
                if ( INTA !== 0 )
15560
                begin
15561
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15562
                end
15563
            end
15564
            else
15565
            begin
15566
                if ( INTA !== 1 )
15567
                begin
15568
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15569
                end
15570
            end
15571
        `endif
15572
 
15573
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15574
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15575
        config_read( offset, 4'hF, read_data ) ;
15576
        ok = 1 ;
15577
        if ( enable_error_report )
15578
        begin
15579
            if ( read_data[8] !== 1 )
15580
            begin
15581
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15582
                ok = 0 ;
15583
            end
15584
 
15585
            if ( read_data[9] !== 0 )
15586
            begin
15587
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15588
                ok = 0 ;
15589
            end
15590
 
15591
            if ( read_data[31:28] !== byte_enables )
15592
            begin
15593
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15594
                ok = 0 ;
15595
            end
15596
 
15597
            if ( read_data[27:24] !== `BC_IO_WRITE )
15598
            begin
15599
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15600
                ok = 0 ;
15601
            end
15602
 
15603
            if ( ok )
15604
                test_ok ;
15605
 
15606
            test_name = "CLEAR ERROR STATUS" ;
15607
            config_write( offset, read_data, 4'hF, ok ) ;
15608
            if ( !ok )
15609
                test_fail("PCI Error Control and Status register could not be written") ;
15610
 
15611
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15612
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15613
            config_read ( offset, 4'hf, read_data ) ;
15614
 
15615
            if ( read_data !== expect_address )
15616
            begin
15617
                test_fail("value in Erroneous Address register was incorrect") ;
15618
                ok = 0 ;
15619
            end
15620
 
15621
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15622
            config_read ( offset, 4'hf, read_data ) ;
15623
 
15624
            if ( read_data !== 32'hAAAA_AAAA )
15625
            begin
15626
                test_fail("value in Erroneous Data register was incorrect") ;
15627
                ok = 0 ;
15628
            end
15629
 
15630
            if ( ok )
15631
                test_ok ;
15632
 
15633
        end
15634
        else
15635
        begin
15636
            if ( read_data[8] !== 0 )
15637
            begin
15638
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15639
                ok = 0 ;
15640
            end
15641
            else
15642
                test_ok ;
15643
        end
15644
 
15645
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15646
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15647
        ok = 1 ;
15648
 
15649
        config_read ( offset, 4'hF, read_data ) ;
15650
        if ( enable_error_report && enable_error_interrupt )
15651
        begin
15652
            if ( read_data[2] !== 1 )
15653
            begin
15654
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15655
                ok = 0 ;
15656
            end
15657
 
15658
            test_name = "CLEARING INTERRUPT STATUS" ;
15659
            config_write( offset, read_data, 4'hF, ok ) ;
15660
            if ( !ok )
15661
                test_fail("Interrupt Status register could not be written") ;
15662
        end
15663
        else
15664
        begin
15665
            if ( read_data[2] !== 0 )
15666
            begin
15667
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15668
                ok = 0 ;
15669
            end
15670
        end
15671
 
15672
        if ( ok )
15673
            test_ok ;
15674
 
15675
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15676
        `ifdef HOST
15677
 
15678
            repeat ( 4 )
15679
                @( posedge wb_clock ) ;
15680
 
15681
            if ( INT_O !== 0 )
15682
            begin
15683
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15684
            end
15685
            else
15686
                test_ok ;
15687
 
15688
        `else
15689
            repeat ( 4 )
15690
                @( posedge pci_clock ) ;
15691
 
15692
            if ( INTA !== 1 )
15693
            begin
15694
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15695
            end
15696
            else
15697
                test_ok ;
15698
 
15699
        `endif
15700
 
15701
        pci_address = pci_address + 1 ;
15702
        expect_address = expect_address + 1 ;
15703
    end
15704
 
15705
end
15706
endtask // test_target_io_err_wr
15707
 
15708
task test_pci_image ;
15709
    input [2:0]  image_num ;
15710
    reg   [11:0] pci_ctrl_offset ;
15711
    reg   [11:0] ctrl_offset ;
15712
    reg   [11:0] ba_offset ;
15713
    reg   [11:0] am_offset ;
15714
    reg   [11:0] ta_offset ;
15715
    reg   [7:0]  cache_lsize ;
15716
    reg          ok ;
15717
    reg          test_io ;
15718
    reg          test_mem ;
15719
begin
15720
    pci_ctrl_offset = 12'h4 ;
15721
    if (image_num === 0)
15722
    begin
15723
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15724
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15725
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15726
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15727
    end
15728
    else if (image_num === 1)
15729
    begin
15730
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15731
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15732
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15733
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15734
    end
15735
    else if (image_num === 2)
15736
    begin
15737
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15738
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15739
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15740
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15741
    end
15742
    else if (image_num === 3)
15743
    begin
15744
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15745
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15746
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15747
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15748
    end
15749
    else if (image_num === 4)
15750
    begin
15751
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15752
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15753
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15754
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15755
    end
15756
    else if (image_num === 5)
15757
    begin
15758
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15759
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15760
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15761
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15762
    end
15763
 
15764
    `ifdef HOST
15765
        test_io  = 1 ;
15766
        test_mem = 1 ;
15767
    `else
15768
        if (image_num == 1)
15769
            test_io = `PCI_BA1_MEM_IO ;
15770
        else if ( image_num == 2 )
15771
            test_io = `PCI_BA2_MEM_IO ;
15772
        else if ( image_num == 3 )
15773
            test_io = `PCI_BA3_MEM_IO ;
15774
        else if ( image_num == 4 )
15775
            test_io = `PCI_BA4_MEM_IO ;
15776
        else if ( image_num == 5 )
15777
            test_io = `PCI_BA5_MEM_IO ;
15778
 
15779
        test_mem = !test_io ;
15780
    `endif
15781
 
15782
    $display(" ");
15783
    $display("########################################################################") ;
15784
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15785
    test_name = "PCI IMAGE SETTINGS" ;
15786
 
15787
    // Set Base Address of IMAGE
15788
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15789
    if ( ok !== 1 )
15790
    begin
15791
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15792
        test_fail("PCI Base Address register could not be written") ;
15793
    end
15794
 
15795
    // Set Address Mask of IMAGE
15796
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15797
    if ( ok !== 1 )
15798
    begin
15799
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15800
        test_fail("PCI Address Mask register could not be written") ;
15801
    end
15802
 
15803
    // Set Translation Address of IMAGE
15804
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15805
    if ( ok !== 1 )
15806
    begin
15807
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15808
        test_fail("PCI Translation Address register could not be written") ;
15809
    end
15810
 
15811
// Following are defines for byte enable signals !
15812
//      Byte Masks
15813
//      `Test_Byte_0                            (4'b1110)
15814
//      `Test_Byte_1                            (4'b1101)
15815
//      `Test_Byte_2                            (4'b1011)
15816
//      `Test_Byte_3                            (4'b0111)
15817
//      `Test_Half_0                            (4'b1100)
15818
//      `Test_Half_1                            (4'b0011)
15819
//      `Test_All_Bytes                         (4'b0000)
15820
 
15821
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15822
    // Set Cache Line Size
15823
    cache_lsize = 8'h4 ;
15824
 
15825
    $display(" ");
15826
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15827
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15828
    if ( ok !== 1 )
15829
    begin
15830
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15831
        test_fail("PCI Device Control and Status register could not be written") ;
15832
    end
15833
 
15834
    if (test_mem)
15835
    begin
15836
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15837
        // Task test_normal_wr_rd has the following parameters:
15838
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15839
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15840
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15841
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15842
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15843
 
15844
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15845
        // Set Cache Line Size
15846
        cache_lsize = 8'h4 ;
15847
 
15848
        $display(" ");
15849
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15850
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15851
        if ( ok !== 1 )
15852
        begin
15853
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15854
            test_fail("Cache Line Size register could not be written" ) ;
15855
        end
15856
 
15857
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15858
        // Task test_normal_wr_rd has the following parameters:
15859
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15860
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15861
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15862
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
15863
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
15864
 
15865
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15866
        // Set Cache Line Size
15867
        cache_lsize = 8'h8 ;
15868
 
15869
        $display(" ");
15870
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15871
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15872
        if ( ok !== 1 )
15873
        begin
15874
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15875
            test_fail("Cache Line Size register could not be written" ) ;
15876
        end
15877
 
15878
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
15879
        // Task test_normal_wr_rd has the following parameters:
15880
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15881
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15882
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15883
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
15884
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15885
 
15886
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15887
        // Set Cache Line Size
15888
        cache_lsize = 8'h4 ;
15889
 
15890
        $display(" ");
15891
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15892
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15893
        if ( ok !== 1 )
15894
        begin
15895
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15896
            test_fail("Cache Line Size register could not be written" ) ;
15897
        end
15898
 
15899
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
15900
        // Task test_normal_wr_rd has the following parameters:
15901
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15902
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15903
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15904
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
15905
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15906
 
15907
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15908
        $display(" ");
15909
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
15910
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15911
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15912
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
15913
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
15914
 
15915
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15916
        $display(" ");
15917
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
15918
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15919
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15920
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
15921
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
15922
 
15923
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15924
        $display(" ");
15925
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
15926
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15927
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15928
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
15929
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
15930
 
15931
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15932
        $display(" ");
15933
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
15934
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15935
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15936
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
15937
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
15938
    end
15939
 
15940
    if ( test_io )
15941
    begin
15942
        test_name = "PCI IMAGE SETTINGS" ;
15943
 
15944
        // Set Base Address of IMAGE
15945
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
15946
        if ( ok !== 1 )
15947
        begin
15948
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15949
            test_fail("PCI Base Address register could not be written") ;
15950
        end
15951
 
15952
        // Set Address Mask of IMAGE
15953
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15954
        if ( ok !== 1 )
15955
        begin
15956
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15957
            test_fail("PCI Address Mask register could not be written") ;
15958
        end
15959
 
15960
        // Set Translation Address of IMAGE
15961
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15962
        if ( ok !== 1 )
15963
        begin
15964
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15965
            test_fail("PCI Translation Address register could not be written") ;
15966
        end
15967
 
15968
        // Set Cache Line Size
15969
        cache_lsize = 8'h4 ;
15970
 
15971
        $display(" ");
15972
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15973
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15974
        if ( ok !== 1 )
15975
        begin
15976
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15977
            test_fail("Cache Line Size register could not be written" ) ;
15978
        end
15979
 
15980
        test_target_io_wr_rd
15981
        (
15982
            image_num,    // image number
15983
            0,            // test with address translation
15984
            ctrl_offset   // image control register offset
15985
        ) ;
15986
 
15987
        test_target_io_wr_rd
15988
        (
15989
            image_num,    // image number
15990
            1,            // test with address translation
15991
            ctrl_offset   // image control register offset
15992
        ) ;
15993
 
15994
        test_target_io_err_wr
15995
        (
15996
            image_num,      // image number
15997
            0,              // address translation on/off
15998
            ctrl_offset,    // image control register offset
15999
            0,              // enable error reporting
16000
 
16001
        ) ;
16002
 
16003
        test_target_io_err_wr
16004
        (
16005
            image_num,      // image number
16006
            1,              // address translation on/off
16007
            ctrl_offset,    // image control register offset
16008
            0,              // enable error reporting
16009
            1               // enable error interrupts
16010
        ) ;
16011
 
16012
        test_target_io_err_wr
16013
        (
16014
            image_num,      // image number
16015
            0,              // address translation on/off
16016
            ctrl_offset,    // image control register offset
16017
            1,              // enable error reporting
16018
 
16019
        ) ;
16020
 
16021
        test_target_io_err_wr
16022
        (
16023
            image_num,      // image number
16024
            1,              // address translation on/off
16025
            ctrl_offset,    // image control register offset
16026
            1,              // enable error reporting
16027
            1               // enable error interrupts
16028
        ) ;
16029
    end
16030
 
16031
    // Test master abort with NON supported commands
16032
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16033
 
16034
    // disable the image
16035 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16036 15 mihad
end
16037
endtask //test_pci_image
16038
 
16039
task target_fast_back_to_back ;
16040
    reg   [11:0] pci_ctrl_offset ;
16041
    reg   [11:0] ctrl_offset ;
16042
    reg   [11:0] ba_offset ;
16043
    reg   [11:0] am_offset ;
16044
    reg   [11:0] ta_offset ;
16045
    reg   [11:0] cls_offset ;
16046
    reg          do_mem_fb2b ;
16047
    reg          do_io_fb2b ;
16048
    reg          ok ;
16049
begin:main
16050
 
16051
    if ( target_mem_image !== -1 )
16052
    begin
16053
        do_mem_fb2b = 1 ;
16054
 
16055
        if (target_mem_image === 1)
16056
        begin
16057
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16058
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16059
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16060
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16061
        end
16062
        else if (target_mem_image === 2)
16063
        begin
16064
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16065
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16066
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16067
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16068
        end
16069
        else if (target_mem_image === 3)
16070
        begin
16071
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16072
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16073
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16074
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16075
        end
16076
        else if (target_mem_image === 4)
16077
        begin
16078
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16079
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16080
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16081
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16082
        end
16083
        else if (target_mem_image === 5)
16084
        begin
16085
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16086
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16087
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16088
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16089
        end
16090
    end
16091
    else
16092
        do_mem_fb2b = 0 ;
16093
 
16094
    pci_ctrl_offset = 12'h4 ;
16095
    cls_offset      = 12'h00C ;
16096
 
16097
    if ( do_mem_fb2b )
16098
    begin
16099
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16100
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16101
        if ( ok !== 1 )
16102
        begin
16103
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16104
            test_fail("PCI Base Address register could not be written") ;
16105
            disable main ;
16106
        end
16107
 
16108
        // Set Address Mask of IMAGE
16109
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16110
        if ( ok !== 1 )
16111
        begin
16112
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16113
            test_fail("PCI Address Mask register could not be written") ;
16114
            disable main ;
16115
        end
16116
 
16117
        // Set Translation Address of IMAGE
16118
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16119
        if ( ok !== 1 )
16120
        begin
16121
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16122
            test_fail("PCI Translation Address Register could not be written") ;
16123
            disable main ;
16124
        end
16125
 
16126
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16127
        if ( ok !== 1 )
16128
        begin
16129
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16130
            test_fail("PCI Image Control register could not be written") ;
16131
            disable main ;
16132
        end
16133
 
16134
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16135
        if ( ok !== 1 )
16136
        begin
16137
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16138
            test_fail("Cache Line Size register could not be written") ;
16139
            disable main ;
16140
        end
16141
 
16142
        // enable master 1 fast_b2b
16143 45 mihad
        configuration_cycle_write(0,                        // bus number
16144
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16145
                                  0,                        // function number
16146
                                  1,                        // register number
16147
                                  0,                        // type of configuration cycle
16148
                                  4'b1111,                  // byte enables
16149
                                  32'hFFFF_FFFF             // data
16150 15 mihad
                                 ) ;
16151
 
16152
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16153
 
16154
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16155
        fork
16156
        begin
16157
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16158
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16159
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16160
                  0, `Test_One_Zero_Target_WS,
16161
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16162
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16163
 
16164
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16165
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16166
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16167
                  0, `Test_One_Zero_Target_WS,
16168
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16169
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16170
            do_pause(5) ;
16171
 
16172
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16173
        end
16174
        begin:wb_monitor1
16175
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16176
            if ( ok !== 1 )
16177
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16178
 
16179
            disable monitor_error_event1 ;
16180
        end
16181
        begin:monitor_error_event1
16182
            @(error_event_int) ;
16183
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16184
            ok = 0 ;
16185
            disable wb_monitor1 ;
16186
        end
16187
        join
16188
 
16189
        if ( ok )
16190
            test_ok ;
16191
 
16192
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16193
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16194
        fork
16195
        begin
16196
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16197
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16198
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16199
                  0, `Test_One_Zero_Target_WS,
16200
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16201
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16202
 
16203
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16204
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16205
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16206
                  0, `Test_One_Zero_Target_WS,
16207
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16208
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16209
            do_pause(5) ;
16210
 
16211
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16212
 
16213
        end
16214
        begin:wb_monitor2
16215
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16216
            if ( ok !== 1 )
16217
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16218
            else
16219
            begin
16220
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16221
                if ( ok !== 1 )
16222
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16223
            end
16224
 
16225
            disable monitor_error_event2 ;
16226
        end
16227
        begin:monitor_error_event2
16228
            @(error_event_int) ;
16229
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16230
            ok = 0 ;
16231
            disable wb_monitor2 ;
16232
        end
16233
        join
16234
 
16235
        if ( ok )
16236
            test_ok ;
16237
 
16238
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16239
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16240
        fork
16241
        begin
16242
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16243
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16244
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16245
                  0, `Test_One_Zero_Target_WS,
16246
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16247
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16248
 
16249
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16250
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16251
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16252
                  0, `Test_One_Zero_Target_WS,
16253
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16254
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16255
            do_pause(5) ;
16256
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16257
 
16258
        end
16259
        begin:wb_monitor3
16260
            fork
16261
            begin
16262
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16263
                if ( ok !== 1 )
16264
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16265
            end
16266
            begin
16267
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16268
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16269
                if ( ok !== 1 )
16270
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16271
            end
16272
            join
16273
 
16274
            if ( ok )
16275
            begin
16276
                fork
16277
                begin
16278
                    do_pause(3) ;
16279
 
16280
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16281
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16282
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16283
                        0, `Test_One_Zero_Target_WS,
16284
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16285
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16286
 
16287
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16288
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16289
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16290
                            0, `Test_One_Zero_Target_WS,
16291
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16292
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16293
 
16294
                    do_pause(1) ;
16295
                end
16296
                begin
16297
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16298
                    if ( ok !== 1 )
16299
                    begin
16300
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16301
                        disable monitor_error_event3 ;
16302
                    end
16303
                    else
16304
                    begin
16305
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16306
                        if ( ok !== 1 )
16307
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16308
                    end
16309
                end
16310 26 mihad
                begin
16311
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16312
                        if ( ok !== 1 )
16313
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16314
                end
16315 15 mihad
                join
16316
            end
16317
            disable monitor_error_event3 ;
16318
        end
16319
        begin:monitor_error_event3
16320
            @(error_event_int) ;
16321
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16322
            ok = 0 ;
16323
            disable wb_monitor3 ;
16324
        end
16325
        join
16326
 
16327
        if ( ok )
16328
            test_ok ;
16329
 
16330
        test_name = "DISABLING MEM IMAGE" ;
16331 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16332 15 mihad
        if ( ok !== 1 )
16333
        begin
16334
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16335
            test_fail("PCI Address Mask register could not be written") ;
16336
            disable main ;
16337
        end
16338
    end
16339
 
16340
    if ( target_io_image !== -1 )
16341
    begin
16342
        do_io_fb2b = 1 ;
16343
 
16344
        if (target_io_image === 1)
16345
        begin
16346
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16347
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16348
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16349
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16350
        end
16351
        else if (target_io_image === 2)
16352
        begin
16353
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16354
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16355
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16356
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16357
        end
16358
        else if (target_io_image === 3)
16359
        begin
16360
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16361
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16362
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16363
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16364
        end
16365
        else if (target_io_image === 4)
16366
        begin
16367
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16368
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16369
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16370
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16371
        end
16372
        else if (target_io_image === 5)
16373
        begin
16374
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16375
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16376
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16377
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16378
        end
16379
    end
16380
    else
16381
        do_io_fb2b = 0 ;
16382
 
16383
    if ( do_io_fb2b )
16384
    begin
16385
 
16386
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16387
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16388
        if ( ok !== 1 )
16389
        begin
16390
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16391
            test_fail("PCI Base Address register could not be written") ;
16392
            disable main ;
16393
        end
16394
 
16395
        // Set Address Mask of IMAGE
16396
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16397
        if ( ok !== 1 )
16398
        begin
16399
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16400
            test_fail("PCI Address Mask register could not be written") ;
16401
            disable main ;
16402
        end
16403
 
16404
        // Set Translation Address of IMAGE
16405
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16406
        if ( ok !== 1 )
16407
        begin
16408
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16409
            test_fail("PCI Translation Address Register could not be written") ;
16410
            disable main ;
16411
        end
16412
 
16413
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16414
        if ( ok !== 1 )
16415
        begin
16416
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16417
            test_fail("PCI Image Control register could not be written") ;
16418
            disable main ;
16419
        end
16420
 
16421
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16422
        if ( ok !== 1 )
16423
        begin
16424
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16425
            test_fail("Cache Line Size register could not be written") ;
16426
            disable main ;
16427
        end
16428
 
16429
        // enable master 1 fast_b2b
16430 45 mihad
        configuration_cycle_write(0,                        // bus number
16431
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16432
                                  0,                        // function number
16433
                                  1,                        // register number
16434
                                  0,                        // type of configuration cycle
16435
                                  4'b1111,                  // byte enables
16436
                                  32'hFFFF_FFFF             // data
16437 15 mihad
                                 ) ;
16438
 
16439
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16440
 
16441
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16442
        fork
16443
        begin
16444
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16445
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16446
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16447
                  0, `Test_One_Zero_Target_WS,
16448
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16449
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16450
 
16451
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16452
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16453
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16454
                  0, `Test_One_Zero_Target_WS,
16455
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16456
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16457
            do_pause(5) ;
16458
 
16459
        end
16460
        begin:wb_monitor4
16461
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16462
            if ( ok !== 1 )
16463
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16464
 
16465
            if ( ok )
16466
            begin
16467
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16468
                if ( ok !== 1 )
16469
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16470
            end
16471
 
16472
            disable monitor_error_event4 ;
16473
        end
16474
        begin:monitor_error_event4
16475
            @(error_event_int) ;
16476
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16477
            ok = 0 ;
16478
            disable wb_monitor4 ;
16479
        end
16480
        join
16481
 
16482
        if ( ok )
16483
            test_ok ;
16484
 
16485
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16486
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16487
        fork
16488
        begin
16489
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16490
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16491
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16492
                  0, `Test_One_Zero_Target_WS,
16493
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16494
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16495
 
16496
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16497
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16498
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16499
                  0, `Test_One_Zero_Target_WS,
16500
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16501
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16502
            do_pause(5) ;
16503
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16504
        end
16505
        begin:wb_monitor5
16506
            fork
16507
            begin
16508
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16509
                if ( ok !== 1 )
16510
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16511
            end
16512
            begin
16513
                wb_transaction_stop( 1 ) ;
16514
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16515
                if ( ok !== 1 )
16516
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16517
            end
16518
            join
16519
 
16520
            if ( ok )
16521
            begin
16522
                fork
16523
                begin
16524
                    do_pause(3) ;
16525
 
16526
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16527
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16528
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16529
                            0, `Test_One_Zero_Target_WS,
16530
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16531
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16532
 
16533
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16534
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16535
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16536
                            0, `Test_One_Zero_Target_WS,
16537
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16538
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16539
 
16540
                    do_pause(1) ;
16541
                end
16542
                begin
16543
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16544
                    if ( ok !== 1 )
16545
                    begin
16546
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16547
                        disable monitor_error_event5 ;
16548
                    end
16549
                    else
16550
                    begin
16551
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16552
                        if ( ok !== 1 )
16553
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16554
                    end
16555
                end
16556
                join
16557
            end
16558
            disable monitor_error_event5 ;
16559
        end
16560
        begin:monitor_error_event5
16561
            @(error_event_int) ;
16562
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16563
            ok = 0 ;
16564
            disable wb_monitor5 ;
16565
        end
16566
        join
16567
 
16568
        if ( ok )
16569
            test_ok ;
16570
 
16571
        test_name = "DISABLING IO IMAGE" ;
16572 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16573 15 mihad
        if ( ok !== 1 )
16574
        begin
16575
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16576
            test_fail("PCI Address Mask register could not be written") ;
16577
            disable main ;
16578
        end
16579
    end
16580
 
16581
end
16582
endtask //target_fast_back_to_back
16583
 
16584
task target_disconnects ;
16585
    reg   [11:0] pci_ctrl_offset ;
16586
    reg   [11:0] ctrl_offset ;
16587
    reg   [11:0] ba_offset ;
16588
    reg   [11:0] am_offset ;
16589
    reg   [11:0] ta_offset ;
16590
    reg   [11:0] cls_offset ;
16591
    reg          pci_ok ;
16592
    reg          wb_ok ;
16593
    reg          ok ;
16594
    reg   [31:0] pci_address ;
16595
    reg   [31:0] data ;
16596
    reg   [3:0]  byte_enables ;
16597
    reg   [9:0]  expect_length ;
16598
 
16599
    reg          do_mem_disconnects ;
16600
    reg          do_io_disconnects ;
16601 35 mihad
    reg          error_monitor_done ;
16602 15 mihad
begin:main
16603
    if ( target_mem_image !== -1 )
16604
    begin
16605
        do_mem_disconnects = 1 ;
16606
 
16607
        if (target_mem_image === 1)
16608
        begin
16609
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16610
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16611
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16612
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16613
        end
16614
        else if (target_mem_image === 2)
16615
        begin
16616
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16617
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16618
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16619
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16620
        end
16621
        else if (target_mem_image === 3)
16622
        begin
16623
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16624
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16625
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16626
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16627
        end
16628
        else if (target_mem_image === 4)
16629
        begin
16630
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16631
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16632
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16633
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16634
        end
16635
        else if (target_mem_image === 5)
16636
        begin
16637
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16638
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16639
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16640
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16641
        end
16642
    end
16643
    else
16644
        do_mem_disconnects = 0 ;
16645
 
16646
    pci_ctrl_offset = 12'h4 ;
16647
    cls_offset = 12'h00C ;
16648
 
16649
    master1_check_received_data = 0 ;
16650
    master2_check_received_data = 0 ;
16651
 
16652
    `ifdef HOST
16653
        `ifdef NO_CNF_IMAGE
16654
        `else
16655
            `define TEST_BURST_CONFIG_READ
16656
        `endif
16657
    `else
16658
        `define TEST_BURST_CONFIG_READ
16659
        `define TEST_BURST_CONFIG_WRITE
16660
    `endif
16661
 
16662
    `ifdef TEST_BURST_CONFIG_WRITE
16663
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16664
 
16665
        data = 32'h0000_08_08 ;
16666
 
16667 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16668 15 mihad
        byte_enables = 4'b0000 ;
16669
 
16670
        fork
16671
        begin
16672
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16673
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16674
                    byte_enables,
16675
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16676
                    8'h0_0, `Test_One_Zero_Target_WS,
16677
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16678
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16679
 
16680
            data = 32'h0000_04_04 ;
16681
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16682
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16683
                    byte_enables,
16684
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16685
                    8'h0_0, `Test_One_Zero_Target_WS,
16686
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16687
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16688
            do_pause( 1 ) ;
16689
            while ( FRAME !== 1 || IRDY !== 1 )
16690
                @(posedge pci_clock) ;
16691
 
16692 35 mihad
            #1 ;
16693
            if ( !error_monitor_done )
16694
                disable monitor_error_event1 ;
16695 15 mihad
        end
16696
        begin:monitor_error_event1
16697 35 mihad
            error_monitor_done = 0 ;
16698 15 mihad
            ok = 1 ;
16699
            @(error_event_int) ;
16700
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16701
            ok = 0 ;
16702 35 mihad
            error_monitor_done = 1 ;
16703 15 mihad
        end
16704
        join
16705
 
16706
        config_read(pci_address, 4'hF, data) ;
16707
        if ( data [15:0] !== 16'h04_04 )
16708
        begin
16709
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16710
        end
16711
        else if ( ok )
16712
            test_ok ;
16713
 
16714 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16715
 
16716
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16717 15 mihad
        data         = 32'h0000_0808 ;
16718
        byte_enables = 4'h0 ;
16719
        fork
16720
        begin
16721
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16722
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16723
                    byte_enables,
16724
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16725
                    8'h0_0, `Test_One_Zero_Target_WS,
16726
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16727
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16728
 
16729
            data = 32'h0000_04_04 ;
16730
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16731
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16732
                    byte_enables,
16733
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16734
                    8'h0_0, `Test_One_Zero_Target_WS,
16735
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16736
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16737
 
16738
            do_pause( 1 ) ;
16739
            while ( FRAME !== 1 || IRDY !== 1 )
16740
                @(posedge pci_clock) ;
16741
 
16742 35 mihad
            #1 ;
16743
            if ( !error_monitor_done )
16744
                disable monitor_error_event2 ;
16745 15 mihad
        end
16746
        begin:monitor_error_event2
16747 35 mihad
            error_monitor_done = 0 ;
16748 15 mihad
            ok = 1 ;
16749
            @(error_event_int) ;
16750
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16751
            ok = 0 ;
16752 35 mihad
            error_monitor_done = 1 ;
16753 15 mihad
        end
16754
        join
16755
 
16756
        config_read(pci_address, 4'hF, data) ;
16757
        if ( data [15:0] !== 16'h04_04 )
16758
        begin
16759
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16760
        end
16761
        else if ( ok )
16762
            test_ok ;
16763
    `endif
16764
 
16765
    `ifdef TEST_BURST_CONFIG_READ
16766
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16767
 
16768
        data = 32'h0000_04_04 ;
16769
 
16770 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16771 15 mihad
        byte_enables = 4'b0000 ;
16772
 
16773
        fork
16774
        begin
16775
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16776
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16777
                    byte_enables,
16778
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16779
                    8'h0_0, `Test_One_Zero_Target_WS,
16780
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16781
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16782
            do_pause( 1 ) ;
16783
 
16784
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16785
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16786
                    byte_enables,
16787
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16788
                    8'h0_0, `Test_One_Zero_Target_WS,
16789
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16790
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16791
            do_pause( 1 ) ;
16792
 
16793
            while ( FRAME !== 1 || IRDY !== 1 )
16794
                @(posedge pci_clock) ;
16795
 
16796 35 mihad
            if ( !error_monitor_done )
16797
                disable monitor_error_event3 ;
16798 15 mihad
        end
16799
        begin:monitor_error_event3
16800 35 mihad
            error_monitor_done = 0 ;
16801 15 mihad
            ok = 1 ;
16802
            @(error_event_int) ;
16803
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16804
            ok = 0 ;
16805 35 mihad
            error_monitor_done = 1 ;
16806 15 mihad
        end
16807
        join
16808
 
16809
        if ( ok )
16810
            test_ok ;
16811
 
16812 45 mihad
 
16813
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16814
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16815 15 mihad
        fork
16816
        begin
16817
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16818
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16819
                    byte_enables,
16820
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16821
                    8'h0_0, `Test_One_Zero_Target_WS,
16822
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16823
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16824
            do_pause( 1 ) ;
16825
 
16826
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16827
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16828
                    byte_enables,
16829
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16830
                    8'h0_0, `Test_One_Zero_Target_WS,
16831
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16832
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16833
            do_pause( 1 ) ;
16834
 
16835
            while ( FRAME !== 1 || IRDY !== 1 )
16836
                @(posedge pci_clock) ;
16837
 
16838 35 mihad
            #1 ;
16839
            if ( !error_monitor_done )
16840
                disable monitor_error_event4 ;
16841 15 mihad
        end
16842
        begin:monitor_error_event4
16843 35 mihad
            error_monitor_done = 0 ;
16844 15 mihad
            ok = 1 ;
16845
            @(error_event_int) ;
16846
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16847
            ok = 0 ;
16848 35 mihad
            error_monitor_done = 1 ;
16849 15 mihad
        end
16850
        join
16851
 
16852
        if ( ok )
16853
            test_ok ;
16854
    `endif
16855
 
16856
    `ifdef TEST_BURST_CONFIG_READ
16857
        `undef TEST_BURST_CONFIG_READ
16858
    `endif
16859
 
16860
    `ifdef TEST_BURST_CONFIG_WRITE
16861
        `undef TEST_BURST_CONFIG_WRITE
16862
    `endif
16863
 
16864
    master1_check_received_data = 1 ;
16865
    master2_check_received_data = 1 ;
16866
 
16867
    if ( do_mem_disconnects )
16868
    begin
16869
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
16870
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16871
        if ( ok !== 1 )
16872
        begin
16873
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16874
            test_fail("PCI Base Address register could not be written") ;
16875
            disable main ;
16876
        end
16877
 
16878
        // Set Address Mask of IMAGE
16879
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16880
        if ( ok !== 1 )
16881
        begin
16882
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16883
            test_fail("PCI Address Mask register could not be written") ;
16884
            disable main ;
16885
        end
16886
 
16887
        // Set Translation Address of IMAGE
16888
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16889
        if ( ok !== 1 )
16890
        begin
16891
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16892
            test_fail("PCI Translation Address Register could not be written") ;
16893
            disable main ;
16894
        end
16895
 
16896
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16897
        if ( ok !== 1 )
16898
        begin
16899
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16900
            test_fail("PCI Image Control register could not be written") ;
16901
            disable main ;
16902
        end
16903
 
16904
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
16905
        if ( ok !== 1 )
16906
        begin
16907
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16908
            test_fail("Cache Line Size register could not be written") ;
16909
            disable main ;
16910
        end
16911
 
16912
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16913
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16914
        data = 32'hAAAA_AAAA ;
16915
        byte_enables = 4'h0 ;
16916
        expect_length = `PCIW_DEPTH - 2 ;
16917
 
16918
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16919
        fork
16920
        begin
16921
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
16922
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16923
                        byte_enables,
16924
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
16925
                        8'h0_0, `Test_One_Zero_Target_WS,
16926
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16927
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16928
            do_pause( 3 ) ;
16929
 
16930
            while ( FRAME !== 1 || IRDY !== 1 )
16931
                @(posedge pci_clock) ;
16932
 
16933 35 mihad
            #1 ;
16934
            if ( !error_monitor_done )
16935
                disable monitor_error_event5 ;
16936 15 mihad
        end
16937
        begin:monitor_error_event5
16938 35 mihad
            error_monitor_done = 0 ;
16939 15 mihad
            pci_ok = 1 ;
16940
            @(error_event_int) ;
16941
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
16942
            pci_ok = 0 ;
16943 35 mihad
            error_monitor_done = 1 ;
16944 15 mihad
        end
16945
        begin
16946
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
16947
            if ( wb_ok !== 1 )
16948
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16949
        end
16950
        join
16951
 
16952
        if ( wb_ok && pci_ok )
16953
            test_ok ;
16954
 
16955
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16956
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16957
        data = 32'hAAAA_AAAA ;
16958
        byte_enables = 4'h0 ;
16959
        expect_length = `PCIW_DEPTH - 2 ;
16960
 
16961
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16962
        fork
16963
        begin
16964
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
16965
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16966
                        byte_enables,
16967
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
16968
                        8'h0_0, `Test_One_Zero_Target_WS,
16969
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16970
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16971
            do_pause( 3 ) ;
16972
 
16973
            while ( FRAME !== 1 || IRDY !== 1 )
16974
                @(posedge pci_clock) ;
16975
 
16976 35 mihad
            #1 ;
16977
            if ( !error_monitor_done )
16978
                disable monitor_error_event6 ;
16979 15 mihad
        end
16980
        begin:monitor_error_event6
16981 35 mihad
            error_monitor_done = 0 ;
16982 15 mihad
            pci_ok = 1 ;
16983
            @(error_event_int) ;
16984
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
16985
            pci_ok = 0 ;
16986 35 mihad
            error_monitor_done = 1 ;
16987 15 mihad
        end
16988
        begin
16989
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
16990
            if ( wb_ok !== 1 )
16991
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16992
        end
16993
        join
16994
 
16995
        if ( wb_ok && pci_ok )
16996
            test_ok ;
16997
 
16998
        master1_check_received_data = 1 ;
16999
//        master2_check_received_data = 0 ;
17000
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17001
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17002
        data = 32'hAAAA_AAAA ;
17003
        byte_enables = 4'h0 ;
17004
        expect_length = 4 ;
17005
 
17006
        fork
17007
        begin
17008
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17009
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17010
                        byte_enables,
17011
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17012
                        8'h0_0, `Test_One_Zero_Target_WS,
17013
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17014
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17015
            do_pause( 1 ) ;
17016
 
17017
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17018
            if ( wb_ok !== 1 )
17019
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17020
 
17021
            do_pause(2) ;
17022
 
17023
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17024
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17025
                        byte_enables,
17026
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17027
                        8'h0_0, `Test_One_Zero_Target_WS,
17028
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17029
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17030
            do_pause( 3 ) ;
17031
 
17032
            while ( FRAME !== 1 || IRDY !== 1 )
17033
                @(posedge pci_clock) ;
17034
 
17035 35 mihad
            #1 ;
17036
            if ( !error_monitor_done )
17037
                disable monitor_error_event7 ;
17038 15 mihad
        end
17039
        begin:monitor_error_event7
17040 35 mihad
            error_monitor_done = 0 ;
17041 15 mihad
            pci_ok = 1 ;
17042
            @(error_event_int) ;
17043
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17044
            pci_ok = 0 ;
17045 35 mihad
            error_monitor_done = 1 ;
17046 15 mihad
        end
17047
        join
17048
 
17049
        if ( wb_ok && pci_ok )
17050
            test_ok ;
17051
 
17052
        master1_check_received_data = 1 ;
17053
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17054
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17055
        data = 32'hAAAA_AAAA ;
17056
        byte_enables = 4'h0 ;
17057
        expect_length = 4 ;
17058
 
17059
        fork
17060
        begin
17061
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17062
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17063
                        byte_enables,
17064
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17065
                        8'h0_0, `Test_One_Zero_Target_WS,
17066
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17067
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17068
            do_pause( 1 ) ;
17069
 
17070
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17071
            if ( wb_ok !== 1 )
17072
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17073
 
17074
            do_pause(2) ;
17075
 
17076
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17077
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17078
                        byte_enables,
17079
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17080
                        8'h0_0, `Test_One_Zero_Target_WS,
17081
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17082
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17083
            do_pause( 3 ) ;
17084
 
17085
            while ( FRAME !== 1 || IRDY !== 1 )
17086
                @(posedge pci_clock) ;
17087
 
17088 35 mihad
            #1 ;
17089
            if ( !error_monitor_done )
17090
                disable monitor_error_event8 ;
17091 15 mihad
        end
17092
        begin:monitor_error_event8
17093 35 mihad
            error_monitor_done = 0 ;
17094 15 mihad
            pci_ok = 1 ;
17095
            @(error_event_int) ;
17096
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17097
            pci_ok = 0 ;
17098 35 mihad
            error_monitor_done = 1 ;
17099 15 mihad
        end
17100
        join
17101
 
17102
        if ( wb_ok && pci_ok )
17103
            test_ok ;
17104
 
17105
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17106
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17107
        data = 32'hDEAF_BEAF ;
17108
        byte_enables = 4'h0 ;
17109
        expect_length = 1 ;
17110
 
17111
        fork
17112
        begin
17113
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17114
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17115
                        byte_enables,
17116
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17117
                        8'h0_0, `Test_One_Zero_Target_WS,
17118
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17119
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17120
            do_pause( 3 ) ;
17121
 
17122
            while ( FRAME !== 1 || IRDY !== 1 )
17123
                @(posedge pci_clock) ;
17124
 
17125 35 mihad
            #1 ;
17126
            if ( !error_monitor_done )
17127
                disable monitor_error_event9 ;
17128 15 mihad
        end
17129
        begin:monitor_error_event9
17130 35 mihad
            error_monitor_done = 0 ;
17131 15 mihad
            pci_ok = 1 ;
17132
            @(error_event_int) ;
17133
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17134
            pci_ok = 0 ;
17135 35 mihad
            error_monitor_done = 1 ;
17136 15 mihad
        end
17137
        begin
17138
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17139
            if ( wb_ok !== 1 )
17140
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17141
        end
17142
        join
17143
 
17144
        if ( wb_ok && pci_ok )
17145
            test_ok ;
17146
 
17147
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17148
        data = 32'hDEAD_BEAF ;
17149
        byte_enables = 4'h0 ;
17150
        expect_length = 1 ;
17151
 
17152
        fork
17153
        begin
17154
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17155
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17156
                        byte_enables,
17157
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17158
                        8'h0_0, `Test_One_Zero_Target_WS,
17159
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17160
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17161
            do_pause( 3 ) ;
17162
 
17163
            while ( FRAME !== 1 || IRDY !== 1 )
17164
                @(posedge pci_clock) ;
17165
 
17166 35 mihad
            #1 ;
17167
            if ( !error_monitor_done )
17168
                disable monitor_error_event10 ;
17169 15 mihad
        end
17170
        begin:monitor_error_event10
17171 35 mihad
            error_monitor_done = 0 ;
17172 15 mihad
            pci_ok = 1 ;
17173
            @(error_event_int) ;
17174
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17175
            pci_ok = 0 ;
17176 35 mihad
            error_monitor_done = 1 ;
17177 15 mihad
        end
17178
        begin
17179
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17180
            if ( wb_ok !== 1 )
17181
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17182
        end
17183
        join
17184
 
17185
        if ( wb_ok && pci_ok )
17186
            test_ok ;
17187
 
17188
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17189
        data = 32'hAAAA_AAAA ;
17190
        byte_enables = 4'h0 ;
17191
        expect_length = 1 ;
17192
 
17193
        fork
17194
        begin
17195
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17196
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17197
                        byte_enables,
17198
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17199
                        8'h0_0, `Test_One_Zero_Target_WS,
17200
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17201
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17202
            do_pause( 3 ) ;
17203
 
17204
            while ( FRAME !== 1 || IRDY !== 1 )
17205
                @(posedge pci_clock) ;
17206
 
17207 35 mihad
            #1 ;
17208
            if ( !error_monitor_done )
17209
                disable monitor_error_event11 ;
17210 15 mihad
        end
17211
        begin:monitor_error_event11
17212 35 mihad
            error_monitor_done = 0 ;
17213 15 mihad
            pci_ok = 1 ;
17214
            @(error_event_int) ;
17215
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17216
            pci_ok = 0 ;
17217 35 mihad
            error_monitor_done = 1 ;
17218 15 mihad
        end
17219
        begin
17220
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17221
            if ( wb_ok !== 1 )
17222
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17223
        end
17224
        join
17225
 
17226
        if ( wb_ok && pci_ok )
17227
            test_ok ;
17228
 
17229
        master1_check_received_data = 1 ;
17230
 
17231
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17232
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17233
        data = 32'hDEAF_BEAF ;
17234
        byte_enables = 4'h0 ;
17235
        expect_length = 1 ;
17236
 
17237
        fork
17238
        begin
17239
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17240
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17241
                        byte_enables,
17242
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17243
                        8'h0_0, `Test_One_Zero_Target_WS,
17244
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17245
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17246
            do_pause( 1 ) ;
17247
 
17248
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17249
            if ( wb_ok !== 1 )
17250
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17251
 
17252
            do_pause(3) ;
17253
 
17254
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17255
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17256
                        byte_enables,
17257
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17258
                        8'h0_0, `Test_One_Zero_Target_WS,
17259
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17260
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17261
            do_pause( 3 ) ;
17262
 
17263
            while ( FRAME !== 1 || IRDY !== 1 )
17264
                @(posedge pci_clock) ;
17265
 
17266 35 mihad
            #1 ;
17267
            if ( !error_monitor_done )
17268
                disable monitor_error_event12 ;
17269 15 mihad
        end
17270
        begin:monitor_error_event12
17271 35 mihad
            error_monitor_done = 0 ;
17272 15 mihad
            pci_ok = 1 ;
17273
            @(error_event_int) ;
17274
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17275
            pci_ok = 0 ;
17276 35 mihad
            error_monitor_done = 1 ;
17277 15 mihad
        end
17278
        join
17279
 
17280
        if ( wb_ok && pci_ok )
17281
            test_ok ;
17282
 
17283
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17284
        data = 32'hDEAD_BEAF ;
17285
        byte_enables = 4'h0 ;
17286
        expect_length = 1 ;
17287
 
17288
        fork
17289
        begin
17290
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17291
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17292
                        byte_enables,
17293
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17294
                        8'h0_0, `Test_One_Zero_Target_WS,
17295
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17296
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17297
            do_pause( 1 ) ;
17298
 
17299
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17300
            if ( wb_ok !== 1 )
17301
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17302
 
17303
            do_pause(3) ;
17304
 
17305
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17306
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17307
                        byte_enables,
17308
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17309
                        8'h0_0, `Test_One_Zero_Target_WS,
17310
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17311
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17312
            do_pause( 3 ) ;
17313
 
17314
            while ( FRAME !== 1 || IRDY !== 1 )
17315
                @(posedge pci_clock) ;
17316
 
17317 35 mihad
            #1 ;
17318
            if ( !error_monitor_done )
17319
                disable monitor_error_event13 ;
17320 15 mihad
        end
17321
        begin:monitor_error_event13
17322 35 mihad
            error_monitor_done = 0 ;
17323 15 mihad
            pci_ok = 1 ;
17324
            @(error_event_int) ;
17325
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17326
            pci_ok = 0 ;
17327 35 mihad
            error_monitor_done = 1 ;
17328 15 mihad
        end
17329
        join
17330
 
17331
        if ( wb_ok && pci_ok )
17332
            test_ok ;
17333
 
17334
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17335
        data = 32'hAAAA_AAAA ;
17336
        byte_enables = 4'h0 ;
17337
        expect_length = 1 ;
17338
 
17339
        fork
17340
        begin
17341
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17342
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17343
                        byte_enables,
17344
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17345
                        8'h0_0, `Test_One_Zero_Target_WS,
17346
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17347
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17348
            do_pause( 1 ) ;
17349
 
17350
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17351
            if ( wb_ok !== 1 )
17352
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17353
 
17354
            do_pause(3) ;
17355
 
17356
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17357
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17358
                        byte_enables,
17359
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17360
                        8'h0_0, `Test_One_Zero_Target_WS,
17361
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17362
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17363
            do_pause( 3 ) ;
17364
 
17365
            while ( FRAME !== 1 || IRDY !== 1 )
17366
                @(posedge pci_clock) ;
17367
 
17368 35 mihad
            #1 ;
17369
            if ( !error_monitor_done )
17370
                disable monitor_error_event14 ;
17371 15 mihad
        end
17372
        begin:monitor_error_event14
17373 35 mihad
            error_monitor_done = 0 ;
17374 15 mihad
            pci_ok = 1 ;
17375
            @(error_event_int) ;
17376
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17377
            pci_ok = 0 ;
17378 35 mihad
            error_monitor_done = 1 ;
17379 15 mihad
        end
17380
        join
17381
 
17382
        if ( wb_ok && pci_ok )
17383
            test_ok ;
17384
 
17385
        // disable the image
17386
        test_name = "DISABLING MEMORY IMAGE" ;
17387 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17388 15 mihad
        if ( ok !== 1 )
17389
        begin
17390
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17391
            test_fail("PCI Address Mask register could not be written") ;
17392
            disable main ;
17393
        end
17394
    end
17395
//*
17396
    if ( target_io_image !== -1 )
17397
    begin
17398
        do_io_disconnects = 1 ;
17399
 
17400
        if (target_io_image === 1)
17401
        begin
17402
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17403
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17404
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17405
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17406
        end
17407
        else if (target_io_image === 2)
17408
        begin
17409
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17410
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17411
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17412
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17413
        end
17414
        else if (target_io_image === 3)
17415
        begin
17416
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17417
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17418
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17419
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17420
        end
17421
        else if (target_io_image === 4)
17422
        begin
17423
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17424
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17425
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17426
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17427
        end
17428
        else if (target_io_image === 5)
17429
        begin
17430
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17431
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17432
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17433
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17434
        end
17435
    end
17436
    else
17437
        do_io_disconnects = 0 ;
17438
 
17439
    if ( do_io_disconnects )
17440
    begin
17441
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17442
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17443
        if ( ok !== 1 )
17444
        begin
17445
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17446
            test_fail("PCI Base Address register could not be written") ;
17447
            disable main ;
17448
        end
17449
 
17450
        // Set Address Mask of IMAGE
17451
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17452
        if ( ok !== 1 )
17453
        begin
17454
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17455
            test_fail("PCI Address Mask register could not be written") ;
17456
            disable main ;
17457
        end
17458
 
17459
        // Set Translation Address of IMAGE
17460
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17461
        if ( ok !== 1 )
17462
        begin
17463
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17464
            test_fail("PCI Translation Address Register could not be written") ;
17465
            disable main ;
17466
        end
17467
 
17468
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17469
        if ( ok !== 1 )
17470
        begin
17471
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17472
            test_fail("PCI Image Control register could not be written") ;
17473
            disable main ;
17474
        end
17475
 
17476
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17477
        if ( ok !== 1 )
17478
        begin
17479
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17480
            test_fail("Cache Line Size register could not be written") ;
17481
            disable main ;
17482
        end
17483
 
17484
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17485
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17486
        data = 32'h5555_5555 ;
17487
        byte_enables = 4'h0 ;
17488
        expect_length = 1 ;
17489
 
17490
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17491
 
17492
        fork
17493
        begin
17494
            PCIU_IO_WRITE
17495
            (
17496
                `Test_Master_1,             // which master
17497
                pci_address,                // to what address
17498
                data,                       // data
17499
                byte_enables,               // byte enable
17500
                expect_length + 1,          // length to request
17501
                `Test_Target_Retry_On       // expected target termination
17502
            ) ;
17503
 
17504
            do_pause( 3 ) ;
17505
 
17506
            while ( FRAME !== 1 || IRDY !== 1 )
17507
                @(posedge pci_clock) ;
17508
 
17509 35 mihad
            #1 ;
17510
            if ( !error_monitor_done )
17511
                disable monitor_error_event15 ;
17512 15 mihad
        end
17513
        begin:monitor_error_event15
17514 35 mihad
            error_monitor_done = 0 ;
17515 15 mihad
            pci_ok = 1 ;
17516
            @(error_event_int) ;
17517
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17518
            pci_ok = 0 ;
17519 35 mihad
            error_monitor_done = 1 ;
17520 15 mihad
        end
17521
        begin
17522
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17523
            if ( wb_ok !== 1 )
17524
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17525
        end
17526
        join
17527
 
17528
        if ( wb_ok && pci_ok )
17529
            test_ok ;
17530
 
17531
        data = 32'hAAAA_AAAA ;
17532
        fork
17533
        begin
17534
            PCIU_IO_WRITE
17535
            (
17536
                `Test_Master_1,             // which master
17537
                pci_address,                // to what address
17538
                data,                       // data
17539
                byte_enables,               // byte enable
17540
                expect_length + 2,          // length to request
17541
                `Test_Target_Retry_Before   // expected target termination
17542
            ) ;
17543
 
17544
            do_pause( 3 ) ;
17545
 
17546
            while ( FRAME !== 1 || IRDY !== 1 )
17547
                @(posedge pci_clock) ;
17548
 
17549 35 mihad
            #1 ;
17550
            if ( !error_monitor_done )
17551
                disable monitor_error_event16 ;
17552 15 mihad
        end
17553
        begin:monitor_error_event16
17554 35 mihad
            error_monitor_done = 0 ;
17555 15 mihad
            pci_ok = 1 ;
17556
            @(error_event_int) ;
17557
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17558
            pci_ok = 0 ;
17559 35 mihad
            error_monitor_done = 1 ;
17560 15 mihad
        end
17561
        begin
17562
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17563
            if ( wb_ok !== 1 )
17564
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17565
        end
17566
        join
17567
 
17568
        if ( wb_ok && pci_ok )
17569
            test_ok ;
17570
 
17571
        master2_check_received_data = 1 ;
17572
 
17573
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17574
 
17575
        fork
17576
        begin
17577
 
17578
             PCIU_IO_READ
17579
             (
17580
                `Test_Master_2,
17581
                pci_address[PCI_BUS_DATA_RANGE:0],
17582
                data,
17583
                byte_enables,
17584
                2,
17585
                `Test_Target_Retry_Before
17586
             );
17587
 
17588
            do_pause( 1 ) ;
17589
 
17590
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17591
            if ( wb_ok !== 1 )
17592
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17593
 
17594
            do_pause(3) ;
17595
 
17596
            PCIU_IO_READ
17597
             (
17598
                `Test_Master_2,
17599
                pci_address[PCI_BUS_DATA_RANGE:0],
17600
                data,
17601
                byte_enables,
17602
                expect_length + 1,
17603
                `Test_Target_Retry_On
17604
             );
17605
 
17606
            do_pause( 3 ) ;
17607
 
17608
            while ( FRAME !== 1 || IRDY !== 1 )
17609
                @(posedge pci_clock) ;
17610
 
17611 35 mihad
            #1 ;
17612
            if ( !error_monitor_done )
17613
                disable monitor_error_event17 ;
17614 15 mihad
        end
17615
        begin:monitor_error_event17
17616 35 mihad
            error_monitor_done = 0 ;
17617 15 mihad
            pci_ok = 1 ;
17618
            @(error_event_int) ;
17619
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17620
            pci_ok = 0 ;
17621 35 mihad
            error_monitor_done = 1 ;
17622 15 mihad
        end
17623
        join
17624
 
17625
        if ( wb_ok && pci_ok )
17626
            test_ok ;
17627
 
17628
        fork
17629
        begin
17630
 
17631
             PCIU_IO_READ
17632
             (
17633
                `Test_Master_2,
17634
                pci_address[PCI_BUS_DATA_RANGE:0],
17635
                data,
17636
                byte_enables,
17637
                2,
17638
                `Test_Target_Retry_Before
17639
             );
17640
 
17641
            do_pause( 1 ) ;
17642
 
17643
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17644
            if ( wb_ok !== 1 )
17645
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17646
 
17647
            do_pause(3) ;
17648
 
17649
            PCIU_IO_READ
17650
             (
17651
                `Test_Master_2,
17652
                pci_address[PCI_BUS_DATA_RANGE:0],
17653
                data,
17654
                byte_enables,
17655
                expect_length + 2,
17656
                `Test_Target_Retry_Before
17657
             );
17658
 
17659
            do_pause( 3 ) ;
17660
 
17661
            while ( FRAME !== 1 || IRDY !== 1 )
17662
                @(posedge pci_clock) ;
17663
 
17664 35 mihad
            #1 ;
17665
            if ( !error_monitor_done )
17666
                disable monitor_error_event18 ;
17667 15 mihad
        end
17668
        begin:monitor_error_event18
17669 35 mihad
            error_monitor_done = 0 ;
17670 15 mihad
            pci_ok = 1 ;
17671
            @(error_event_int) ;
17672
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17673
            pci_ok = 0 ;
17674 35 mihad
            error_monitor_done = 1 ;
17675 15 mihad
        end
17676
        join
17677
 
17678
        if ( wb_ok && pci_ok )
17679
            test_ok ;
17680
 
17681
        test_name = "DISABLING IO IMAGE" ;
17682 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17683 15 mihad
        if ( ok !== 1 )
17684
        begin
17685
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17686
            test_fail("PCI Address Mask register could not be written") ;
17687
            disable main ;
17688
        end
17689
    end
17690
//*/
17691
end
17692
endtask // target_disconnects
17693
 
17694
task target_unsupported_cmds ;
17695
        input [31:0] Address;
17696
        input [2:0]  image_num ;
17697
    reg          ok ;
17698
begin:main
17699
 
17700
    $display("  ") ;
17701
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17702
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17703 45 mihad
 
17704
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17705
    configuration_cycle_write
17706
    (
17707
        0,                        // bus number
17708
        `TAR1_IDSEL_INDEX - 11,   // device number
17709
        0,                        // function number
17710
        1,                        // register number
17711
        0,                        // type of configuration cycle
17712
        4'b0001,                  // byte enables
17713
        32'h0000_0044             // data
17714
    ) ;
17715
 
17716
    configuration_cycle_write
17717
    (
17718
        0,                        // bus number
17719
        `TAR2_IDSEL_INDEX - 11,   // device number
17720
        0,                        // function number
17721
        1,                        // register number
17722
        0,                        // type of configuration cycle
17723
        4'b0001,                  // byte enables
17724
        32'h0000_0044             // data
17725
    ) ;
17726
 
17727 15 mihad
    ipci_unsupported_commands_master.master_reference
17728
    (
17729
        Address,                // first part of address in dual address cycle
17730
        Address,                // second part of address in dual address cycle
17731
        `BC_IACK,                       // dual address cycle command
17732
        `BC_IACK,               // normal command
17733
        4'h0,               // byte enables
17734
        32'h1234_5678,      // data
17735
        1'b0,               // make address parity error on first phase of dual address
17736
        1'b0,               // make address parity error on second phase of dual address
17737
        ok                  // result of operation
17738
    ) ;
17739
    if ( ok )
17740
        test_ok ;
17741
    else
17742
    begin
17743
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17744
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17745
    end
17746
 
17747
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17748
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17749
    ipci_unsupported_commands_master.master_reference
17750
    (
17751
        Address,                // first part of address in dual address cycle
17752
        Address,                // second part of address in dual address cycle
17753
        `BC_SPECIAL,            // dual address cycle command
17754
        `BC_SPECIAL,            // normal command
17755
        4'h0,               // byte enables
17756
        32'h1234_5678,      // data
17757
        1'b0,               // make address parity error on first phase of dual address
17758
        1'b0,               // make address parity error on second phase of dual address
17759
        ok                  // result of operation
17760
    ) ;
17761
    if ( ok )
17762
        test_ok ;
17763
    else
17764
    begin
17765
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17766
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17767
    end
17768
 
17769
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17770
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17771
    ipci_unsupported_commands_master.master_reference
17772
    (
17773
        Address,                // first part of address in dual address cycle
17774
        Address,                // second part of address in dual address cycle
17775
        `BC_RESERVED0,          // dual address cycle command
17776
        `BC_RESERVED0,      // normal command
17777
        4'h0,               // byte enables
17778
        32'h1234_5678,      // data
17779
        1'b0,               // make address parity error on first phase of dual address
17780
        1'b0,               // make address parity error on second phase of dual address
17781
        ok                  // result of operation
17782
    ) ;
17783
    if ( ok )
17784
        test_ok ;
17785
    else
17786
    begin
17787
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17788
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17789
    end
17790
 
17791
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17792
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17793
    ipci_unsupported_commands_master.master_reference
17794
    (
17795
        Address,                // first part of address in dual address cycle
17796
        Address,                // second part of address in dual address cycle
17797
        `BC_RESERVED1,          // dual address cycle command
17798
        `BC_RESERVED1,      // normal command
17799
        4'h0,               // byte enables
17800
        32'h1234_5678,      // data
17801
        1'b0,               // make address parity error on first phase of dual address
17802
        1'b0,               // make address parity error on second phase of dual address
17803
        ok                  // result of operation
17804
    ) ;
17805
    if ( ok )
17806
        test_ok ;
17807
    else
17808
    begin
17809
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17810
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17811
    end
17812
 
17813
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17814
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17815
    ipci_unsupported_commands_master.master_reference
17816
    (
17817
        Address,                // first part of address in dual address cycle
17818
        Address,                // second part of address in dual address cycle
17819
        `BC_RESERVED2,          // dual address cycle command
17820
        `BC_RESERVED2,      // normal command
17821
        4'h0,               // byte enables
17822
        32'h1234_5678,      // data
17823
        1'b0,               // make address parity error on first phase of dual address
17824
        1'b0,               // make address parity error on second phase of dual address
17825
        ok                  // result of operation
17826
    ) ;
17827
    if ( ok )
17828
        test_ok ;
17829
    else
17830
    begin
17831
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17832
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17833
    end
17834
 
17835
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17836
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17837
    ipci_unsupported_commands_master.master_reference
17838
    (
17839
        Address,                // first part of address in dual address cycle
17840
        Address,                // second part of address in dual address cycle
17841
        `BC_RESERVED3,          // dual address cycle command
17842
        `BC_RESERVED3,      // normal command
17843
        4'h0,               // byte enables
17844
        32'h1234_5678,      // data
17845
        1'b0,               // make address parity error on first phase of dual address
17846
        1'b0,               // make address parity error on second phase of dual address
17847
        ok                  // result of operation
17848
    ) ;
17849
    if ( ok )
17850
        test_ok ;
17851
    else
17852
    begin
17853
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17854
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17855
    end
17856
 
17857
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17858
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17859
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17860
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17861
    ipci_unsupported_commands_master.master_reference
17862
    (
17863
        Address,                // first part of address in dual address cycle
17864
        Address,                // second part of address in dual address cycle
17865
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
17866
        `BC_MEM_WRITE,      // normal command
17867
        4'h0,               // byte enables;
17868
        32'h1234_5678,      // data
17869
        1'b0,               // make address parity error on first phase of dual address
17870
        1'b0,               // make address parity error on second phase of dual address
17871
        ok                  // result of operation
17872
    ) ;
17873
    if ( ok )
17874
        test_ok ;
17875
    else
17876
    begin
17877
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17878
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
17879
    end
17880
 
17881 45 mihad
    // enable pci blue behavioral targets 1 and 2
17882
    configuration_cycle_write
17883
    (
17884
        0,                        // bus number
17885
        `TAR1_IDSEL_INDEX - 11,   // device number
17886
        0,                        // function number
17887
        1,                        // register number
17888
        0,                        // type of configuration cycle
17889
        4'b0001,                  // byte enables
17890
        32'h0000_0047             // data
17891
    ) ;
17892
 
17893
    configuration_cycle_write
17894
    (
17895
        0,                        // bus number
17896
        `TAR2_IDSEL_INDEX - 11,   // device number
17897
        0,                        // function number
17898
        1,                        // register number
17899
        0,                        // type of configuration cycle
17900
        4'b0001,                  // byte enables
17901
        32'h0000_0047             // data
17902
    ) ;
17903 15 mihad
end
17904
endtask // target_unsupported_cmds
17905
 
17906
task target_completion_expiration ;
17907
    reg   [11:0] pci_ctrl_offset ;
17908
    reg   [11:0] pci_ba_offset ;
17909
    reg   [11:0] pci_am_offset ;
17910
    reg   [11:0] pci_device_ctrl_offset ;
17911
    reg   [11:0] pci_err_cs_offset ;
17912
    reg   [11:0] icr_offset ;
17913
    reg   [11:0] isr_offset ;
17914
    reg   [11:0] lat_tim_cls_offset ;
17915
 
17916
    reg [31:0] temp_val1 ;
17917
    reg [31:0] temp_val2 ;
17918
    reg        ok   ;
17919 33 mihad
    reg        ok_wb ;
17920
    reg        ok_pci ;
17921 15 mihad
 
17922
    reg [31:0] pci_image_base ;
17923
    integer i ;
17924 33 mihad
    integer clocks_after_completion ;
17925
    reg     error_monitor_done ;
17926
    reg     test_mem ;
17927 15 mihad
 
17928
begin:main
17929
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17930
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
17931
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
17932
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
17933
 
17934
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
17935
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
17936
    lat_tim_cls_offset = 12'hC ;
17937
    pci_device_ctrl_offset    = 12'h4 ;
17938
 
17939 33 mihad
    `ifdef HOST
17940
        test_mem = 1'b1 ;
17941
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
17942
    `else
17943
        test_mem = !`PCI_BA1_MEM_IO ;
17944
        pci_image_base = Target_Base_Addr_R[1] ;
17945
    `endif
17946 15 mihad
 
17947
    // enable master & target operation
17948
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
17949
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
17950
    if ( ok !== 1 )
17951
    begin
17952
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
17953
        test_fail("write to PCI Device Control register failed") ;
17954
        disable main ;
17955
    end
17956
 
17957
    // prepare image control register
17958 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
17959 15 mihad
    if ( ok !== 1 )
17960
    begin
17961
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
17962
        test_fail("write to PCI Image Control register failed") ;
17963
        disable main ;
17964
    end
17965
 
17966
    // prepare base address register
17967
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
17968
    if ( ok !== 1 )
17969
    begin
17970
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
17971
        test_fail("write to PCI Base Address register failed") ;
17972
        disable main ;
17973
    end
17974
 
17975
    // write address mask register
17976
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
17977
    if ( ok !== 1 )
17978
    begin
17979
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
17980
        test_fail("write to PCI Address Mask register failed") ;
17981
        disable main ;
17982
    end
17983
 
17984
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
17985
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
17986
    if ( ok !== 1 )
17987
    begin
17988
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
17989
        test_fail("write to PCI Error Control and Status register failed") ;
17990
        disable main ;
17991
    end
17992
 
17993 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
17994 15 mihad
    if ( ok !== 1 )
17995
    begin
17996
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
17997
        test_fail("write to Interrupt Control register failed") ;
17998
        disable main ;
17999
    end
18000
 
18001
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18002
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18003
    if ( ok !== 1 )
18004
    begin
18005
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18006
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18007
        disable main ;
18008
    end
18009
 
18010
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18011
 
18012
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18013 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18014
    master1_check_received_data = 0 ;
18015 15 mihad
 
18016 33 mihad
    ok_pci = 1 ;
18017
    // start a delayed read request
18018
    fork
18019
    begin
18020
        if ( test_mem )
18021
 
18022
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18023
                          pci_image_base, 32'h1234_5678,
18024
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18025
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18026
        else
18027
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18028
 
18029
        do_pause( 1 ) ;
18030
    end
18031
    begin:error_monitor1
18032 35 mihad
        error_monitor_done = 0 ;
18033 33 mihad
        @(error_event_int) ;
18034
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18035
        ok_pci = 0 ;
18036 35 mihad
        error_monitor_done = 1 ;
18037 33 mihad
    end
18038
    begin
18039
        if ( test_mem )
18040
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18041
        else
18042
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18043 15 mihad
 
18044 33 mihad
        if ( ok_wb !== 1 )
18045
        begin
18046
            test_fail("Bridge failed to process Target Memory read correctly") ;
18047
            disable main ;
18048
        end
18049
 
18050 35 mihad
        #1 ;
18051
        if ( !error_monitor_done )
18052 33 mihad
            disable error_monitor1 ;
18053
    end
18054
    join
18055
 
18056
    clocks_after_completion = 0 ;
18057
    // now do another - different transaction
18058
    fork
18059
    begin
18060
        if ( test_mem )
18061
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18062
                          pci_image_base + 4, 32'h1234_5678,
18063
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18064
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18065
        else
18066
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18067
 
18068
        while ( clocks_after_completion < 32'h0000_FFF0 )
18069
        begin
18070
            @(posedge pci_clock) ;
18071
            clocks_after_completion = clocks_after_completion + 1 ;
18072
        end
18073
 
18074
        do_pause('hFF) ;
18075
 
18076
        if ( test_mem )
18077
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18078
                          pci_image_base + 4, 32'h1234_5678,
18079
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18080
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18081
        else
18082
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18083
 
18084
        do_pause( 1 ) ;
18085
    end
18086
    begin:error_monitor2
18087 35 mihad
        error_monitor_done = 0 ;
18088 33 mihad
        @(error_event_int) ;
18089
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18090
        ok_pci = 0 ;
18091 35 mihad
        error_monitor_done = 1 ;
18092 33 mihad
    end
18093
    begin
18094
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18095
        repeat( 'hFF )
18096
            @(posedge pci_clock) ;
18097
 
18098
        if ( test_mem )
18099
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18100
        else
18101
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18102
 
18103
        if ( ok_wb !== 1 )
18104
        begin
18105
            test_fail("Bridge failed to process Target Memory read correctly") ;
18106
            disable main ;
18107
        end
18108
 
18109
        repeat(4)
18110
            @(posedge pci_clock) ;
18111
 
18112
        fork
18113
        begin
18114
            if ( test_mem )
18115
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18116
                              pci_image_base + 4, 32'h1234_5678,
18117
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18118
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18119
            else
18120
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18121
 
18122
            do_pause(1) ;
18123
        end
18124
        begin
18125
           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 ) ;
18126 35 mihad
           #1 ;
18127
           if ( !error_monitor_done )
18128 33 mihad
               disable error_monitor2 ;
18129
        end
18130
        join
18131
    end
18132
    join
18133
 
18134
    if ( ok && ok_pci && ok_wb )
18135
        test_ok ;
18136
 
18137
    if ( ok !== 1 )
18138
    begin
18139
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18140
        test_fail("write to PCI Address Mask register failed") ;
18141
        disable main ;
18142
    end
18143
 
18144
    // check statuses after this situation - none should be set
18145
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18146
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18147
    if ( ok !== 1 )
18148
    begin
18149
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18150
        test_fail("read from pci device status register failed") ;
18151
        disable main ;
18152
    end
18153
 
18154
    if ( temp_val1[31] )
18155
    begin
18156
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18157
        test_fail("detected parity error bit was set for no reason") ;
18158
    end
18159
 
18160
    if ( temp_val1[30] )
18161
    begin
18162
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18163
        test_fail("signaled system error bit was set for no reason") ;
18164
    end
18165
 
18166
    if ( temp_val1[29] )
18167
    begin
18168
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18169
        test_fail("received master abort bit was set for no reason") ;
18170
    end
18171
 
18172
    if ( temp_val1[28] )
18173
    begin
18174
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18175
        test_fail("received target abort bit was set for no reason") ;
18176
    end
18177
 
18178
    if ( temp_val1[27] )
18179
    begin
18180
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18181
        test_fail("signaled target abort bit was set for no reason") ;
18182
    end
18183
 
18184
    if ( temp_val1[24] )
18185
    begin
18186
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18187
        test_fail("Master Data parity error bit was set for no reason") ;
18188
    end
18189
 
18190
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18191
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18192
    if ( temp_val1[8] !== 0 )
18193
    begin
18194
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18195
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18196
    end
18197
    // test target retry counter expiration
18198
    // set wb slave to retry response
18199
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18200
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18201
    ok_pci = 1 ;
18202
 
18203
    fork
18204
    begin
18205
        if ( test_mem == 1 )
18206
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18207
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18208
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18209
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18210
        else
18211
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18212
 
18213
        do_pause(1) ;
18214
 
18215
        // do another write with same address and different data
18216
        if ( test_mem == 1 )
18217
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18218
                        pci_image_base, 32'h8765_4321, 4'h0,
18219
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18220
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18221
        else
18222
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18223
 
18224
        do_pause(1) ;
18225
    end
18226
    begin
18227
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18228
        begin
18229
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18230
            if ( ok_wb !== 1 )
18231
            begin
18232
                $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) ;
18233
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18234
                disable main ;
18235
            end
18236
        end
18237
 
18238
        // set WB slave to normal completion
18239
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18240
 
18241
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18242
        if ( ok_wb !== 1 )
18243
        begin
18244
            $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) ;
18245
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18246
            disable main ;
18247
        end
18248
 
18249 35 mihad
        #1 ;
18250
        if ( !error_monitor_done )
18251 33 mihad
            disable error_monitor3 ;
18252
    end
18253
    begin:error_monitor3
18254 35 mihad
        error_monitor_done = 0 ;
18255 33 mihad
        @(error_event_int) ;
18256
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18257
        ok_pci = 0 ;
18258 35 mihad
        error_monitor_done = 1 ;
18259 33 mihad
    end
18260
    join
18261
 
18262
    if ( ok_wb && ok_pci )
18263
    begin
18264
        test_ok ;
18265
    end
18266
 
18267
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18268
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18269
    if ( temp_val1[8] !== 1'b1 )
18270
    begin
18271
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18272
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18273
    end
18274
 
18275
    if ( temp_val1[9] !== 1 )
18276
    begin
18277
        $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) ;
18278
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18279
    end
18280
 
18281
    if ( temp_val1[10] !== 1 )
18282
    begin
18283
        $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) ;
18284
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18285
    end
18286
 
18287
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18288
    begin
18289
        $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) ;
18290
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18291
    end
18292
 
18293
    if ( temp_val1[31:28] !== 4'hA )
18294
    begin
18295
        $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) ;
18296
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18297
    end
18298
 
18299
    // clear error status register
18300
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18301
 
18302
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18303
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18304
    if ( temp_val1 !== pci_image_base )
18305
    begin
18306
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18307
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18308
    end
18309
 
18310
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18311
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18312
    if ( temp_val1 !== 32'hDEAD_BEAF )
18313
    begin
18314
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18315
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18316
    end
18317
 
18318
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18319
    ok_pci = 1 ;
18320
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18321
 
18322
    i = 0 ;
18323
    fork
18324
    begin
18325
        if ( test_mem )
18326
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18327
                          pci_image_base + 4, 32'h1234_5678,
18328
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18329
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18330
        else
18331
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18332
 
18333
        do_pause( 1 ) ;
18334
 
18335
    end
18336
    begin
18337
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18338
        begin
18339
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18340
            if ( ok_wb !== 1 )
18341
            begin
18342
                $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) ;
18343
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18344
                disable main ;
18345
            end
18346
        end
18347
 
18348
        // set WB slave to normal completion
18349
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18350
 
18351
        fork
18352
        begin
18353
            repeat(4)
18354
                @(posedge pci_clock) ;
18355
 
18356
            if ( test_mem )
18357
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18358
                              pci_image_base, 32'h8765_4321,
18359
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18360
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18361
            else
18362
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18363
 
18364
            do_pause(1) ;
18365
        end
18366
        begin
18367
 
18368
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18369
            if ( ok_wb !== 1 )
18370
            begin
18371
                $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) ;
18372
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18373
                disable main ;
18374
            end
18375
        end
18376
        join
18377
 
18378
        repeat( 4 )
18379
            @(posedge pci_clock) ;
18380
 
18381
        if ( test_mem )
18382
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18383
                          pci_image_base, 32'h8765_4321,
18384
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18385
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18386
        else
18387
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18388
 
18389
        do_pause(1) ;
18390
 
18391 35 mihad
        #1 ;
18392
        if ( !error_monitor_done )
18393 33 mihad
            disable error_monitor4 ;
18394
    end
18395
    begin:error_monitor4
18396 35 mihad
        error_monitor_done = 0 ;
18397 33 mihad
        @(error_event_int) ;
18398
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18399
        ok_pci = 0 ;
18400 35 mihad
        error_monitor_done = 1 ;
18401 33 mihad
    end
18402
    join
18403
 
18404
    if ( ok_wb && ok_pci )
18405
        test_ok ;
18406
 
18407
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18408
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18409
    if ( temp_val1[8] !== 1'b0 )
18410
    begin
18411
        $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) ;
18412
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18413
    end
18414
 
18415
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18416 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18417
    $fdisplay(pciu_mon_log_file_desc,
18418
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18419 33 mihad
    ok_pci = 1 ;
18420
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18421
 
18422
    fork
18423
    begin
18424
        if ( test_mem )
18425
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18426
                          pci_image_base + 4, 32'h1234_5678,
18427
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18428
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18429
        else
18430
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18431
 
18432
        do_pause( 1 ) ;
18433
 
18434
    end
18435
    begin
18436
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18437
        if ( ok_wb !== 1 )
18438
        begin
18439
            $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) ;
18440
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18441
            disable main ;
18442
        end
18443
 
18444
        repeat(4)
18445
            @(posedge pci_clock) ;
18446
 
18447
        fork
18448
        begin
18449
 
18450
            if ( test_mem )
18451
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18452
                              pci_image_base + 4, 32'h8765_4321,
18453
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18454
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18455
            else
18456
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18457
 
18458
            do_pause(1) ;
18459
 
18460
        end
18461
        begin
18462
 
18463
            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 ) ;
18464
            if ( ok !== 1 )
18465
            begin
18466
                $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) ;
18467
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18468
                disable main ;
18469
            end
18470
        end
18471
        join
18472
 
18473 35 mihad
        #1 ;
18474
        if ( !error_monitor_done )
18475 33 mihad
            disable error_monitor5 ;
18476
    end
18477
    begin:error_monitor5
18478 35 mihad
        error_monitor_done = 0 ;
18479 33 mihad
        @(error_event_int) ;
18480
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18481
        ok_pci = 0 ;
18482 35 mihad
        error_monitor_done = 1 ;
18483 33 mihad
    end
18484
    join
18485
 
18486
    if ( ok_wb && ok_pci )
18487
        test_ok ;
18488
 
18489
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18490
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18491
    if ( temp_val1[8] !== 1'b0 )
18492
    begin
18493
        $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) ;
18494
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18495
    end
18496
 
18497
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18498
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18499
    if ( temp_val1[25] !== 1'b1 )
18500
    begin
18501
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18502
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18503
    end
18504
 
18505
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18506
 
18507
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18508
    ok_pci = 1 ;
18509
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18510
 
18511
    fork
18512
    begin
18513
        if ( test_mem == 1 )
18514
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18515
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18516
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18517
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18518
        else
18519
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18520
 
18521
        do_pause(1) ;
18522
 
18523
        // do another write with same address and different data
18524
        if ( test_mem == 1 )
18525
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18526
                        pci_image_base, 32'h8765_6789, 4'h0,
18527
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18528
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18529
        else
18530
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18531
 
18532
        do_pause(1) ;
18533
    end
18534
    begin
18535
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18536
        if ( ok_wb !== 1 )
18537
        begin
18538
            $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) ;
18539
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18540
            disable main ;
18541
        end
18542
 
18543
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18544
 
18545
        if ( test_mem )
18546
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18547
        else
18548
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18549
 
18550
        if ( ok_wb !== 1 )
18551
        begin
18552
            $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) ;
18553
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18554
            disable main ;
18555
        end
18556
 
18557 35 mihad
        #1 ;
18558
        if ( !error_monitor_done )
18559 33 mihad
            disable error_monitor6 ;
18560
    end
18561
    begin:error_monitor6
18562 35 mihad
        error_monitor_done = 0 ;
18563 33 mihad
        @(error_event_int) ;
18564
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18565
        ok_pci = 0 ;
18566 35 mihad
        error_monitor_done = 1 ;
18567 33 mihad
    end
18568
    join
18569
 
18570
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18571
    $fdisplay(pciu_mon_log_file_desc,
18572
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18573
 
18574
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18575
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18576
    if ( temp_val1[8] !== 1'b1 )
18577
    begin
18578
        $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) ;
18579
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18580
    end
18581
 
18582
    if ( temp_val1[9] !== 0 )
18583
    begin
18584
        $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) ;
18585
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18586
    end
18587
 
18588
    if ( temp_val1[10] !== 1 )
18589
    begin
18590
        $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) ;
18591
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18592
    end
18593
 
18594
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18595
    begin
18596
        $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) ;
18597
        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") ;
18598
    end
18599
 
18600
    if ( temp_val1[31:28] !== 4'h0 )
18601
    begin
18602
        $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) ;
18603
        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") ;
18604
    end
18605
 
18606
    // clear error status register
18607
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18608
 
18609
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18610
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18611
    if ( temp_val1 !== pci_image_base )
18612
    begin
18613
        $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) ;
18614
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18615
    end
18616
 
18617
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18618
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18619
    if ( temp_val1 !== 32'hBEAF_DEAD )
18620
    begin
18621
        $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) ;
18622
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18623
    end
18624
 
18625
    // disable current image - write address mask register
18626 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18627 15 mihad
end
18628
endtask // target_completion_expired
18629
 
18630
task config_write ;
18631
    input [11:0] offset ;
18632
    input [31:0] data ;
18633
    input [3:0]  byte_enable ;
18634
    output       ok ;
18635
    `ifdef HOST
18636
    reg   `WRITE_STIM_TYPE   write_data ;
18637
    reg   `WB_TRANSFER_FLAGS write_flags ;
18638
    reg   `WRITE_RETURN_TYPE write_status ;
18639
    `else
18640
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18641
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18642
    `endif
18643
    reg in_use ;
18644
    reg [31:0] temp_var ;
18645
begin
18646
    if ( in_use === 1 )
18647
    begin
18648
        $display("config_read task re-entered! Time %t ", $time) ;
18649
        ok = 0 ;
18650
        #20 $stop ;
18651
    end
18652
    else
18653
    begin
18654
        ok = 1 ;
18655
        in_use = 1 ;
18656
    end
18657
    `ifdef HOST
18658
    write_flags                    = 0 ;
18659
    write_flags`INIT_WAITS         = tb_init_waits ;
18660
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18661
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18662
 
18663
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18664
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18665
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18666
    write_data`WRITE_SEL                         = byte_enable ;
18667
    write_data`WRITE_TAG_STIM                    = 0 ;
18668
    write_data`WRITE_DATA                        = data ;
18669
 
18670
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18671
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18672
    begin
18673
        $display("Write to configuration space failed! Time %t ", $time) ;
18674
        ok = 0 ;
18675
    end
18676
 
18677
    @(posedge wb_clock) ;
18678
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18679
    // here we just wait for two guest cycles for conf space bits to synchronize
18680
    repeat( 2 )
18681
        @(posedge pci_clock) ;
18682
 
18683
    `else // GUEST
18684
    byte_enables_l = ~byte_enable ;
18685
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18686
 
18687
    fork
18688
    begin
18689
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18690
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
18691
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
18692
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18693
              8'h0_0, `Test_One_Zero_Target_WS,
18694
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
18695
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18696
    do_pause( 1 ) ;
18697
    end
18698
    begin
18699
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
18700
        @(posedge pci_clock) ;
18701
    end
18702
    join
18703
 
18704
     repeat( 2 )
18705
         @(posedge wb_clock) ;
18706
 
18707
    `endif
18708
    in_use = 0 ;
18709
end
18710
endtask // config_write
18711
 
18712
task config_read ;
18713
    input [11:0] offset ;
18714
    input [3:0]  byte_enable ;
18715
    output [31:0] data ;
18716
 
18717
    reg `READ_STIM_TYPE    read_data ;
18718
    reg `WB_TRANSFER_FLAGS read_flags ;
18719
    reg `READ_RETURN_TYPE  read_status ;
18720
 
18721
    reg [31:0] pci_address ;
18722
    reg [3:0] byte_enables_l ;
18723
 
18724
    reg master_check_data_prev ;
18725
    reg in_use ;
18726
    reg [31:0] temp_var ;
18727
begin:main
18728
    if ( in_use === 1 )
18729
    begin
18730
        $display("config_read task re-entered! Time %t ", $time) ;
18731
        data = 32'hxxxx_xxxx ;
18732
        disable main ;
18733
    end
18734
 
18735
    in_use = 1 ;
18736
 
18737
`ifdef HOST
18738 26 mihad
    repeat(4)
18739
        @(posedge pci_clock) ;
18740
    repeat(4)
18741
        @(posedge wb_clock) ;
18742 15 mihad
    read_flags                    = 0 ;
18743
    read_flags`INIT_WAITS         = tb_init_waits ;
18744
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18745
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18746
 
18747
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18748
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18749
 
18750
    read_data`READ_ADDRESS  = temp_var + offset ;
18751
    read_data`READ_SEL      = byte_enable ;
18752
    read_data`READ_TAG_STIM = 0 ;
18753
 
18754
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
18755
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18756
    begin
18757
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
18758
        #20 $stop ;
18759
    end
18760
    data = read_status`READ_DATA ;
18761
`else
18762
  `ifdef GUEST
18763 26 mihad
    repeat(4)
18764
        @(posedge wb_clock) ;
18765
    repeat(4)
18766
        @(posedge pci_clock) ;
18767 15 mihad
    master_check_data_prev = master2_check_received_data ;
18768
    master2_check_received_data = 0 ;
18769
 
18770
    byte_enables_l = ~byte_enable ;
18771
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18772
 
18773
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18774
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
18775
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
18776
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18777
             8'h4_0, `Test_One_Zero_Target_WS,
18778
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
18779
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18780
    do_pause( 1 ) ;
18781
 
18782
    @(master2_received_data_valid) ;
18783
    data = master2_received_data ;
18784
 
18785
    master2_check_received_data = master_check_data_prev ;
18786
  `endif
18787
`endif
18788
    in_use = 0 ;
18789
end
18790
endtask //config_read
18791
 
18792
task test_fail ;
18793
    input [7999:0] failure_reason ;
18794
    reg   [8007:0] display_failure ;
18795
    reg   [799:0] display_test ;
18796
begin
18797
    tests_failed = tests_failed + 1 ;
18798
 
18799
    display_failure = {failure_reason, "!"} ;
18800
    while ( display_failure[7999:7992] == 0 )
18801
        display_failure = display_failure << 8 ;
18802
 
18803
    display_test = test_name ;
18804
    while ( display_test[799:792] == 0 )
18805
       display_test = display_test << 8 ;
18806
 
18807
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18808
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
18809
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
18810
    $fdisplay( tb_log_file, " *FAILED* because") ;
18811
    $fdisplay( tb_log_file, " %s", display_failure ) ;
18812
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18813
    $fdisplay( tb_log_file, " " ) ;
18814
 
18815
    `ifdef STOP_ON_FAILURE
18816
    #20 $stop ;
18817
    `endif
18818
end
18819
endtask // test_fail
18820
 
18821
task test_ok ;
18822
    reg [799:0] display_test ;
18823
begin
18824
   tests_successfull = tests_successfull + 1 ;
18825
 
18826
   display_test = test_name ;
18827
   while ( display_test[799:792] == 0 )
18828
       display_test = display_test << 8 ;
18829
 
18830
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18831
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
18832
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
18833
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
18834
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
18835
   $fdisplay( tb_log_file, " " ) ;
18836
end
18837
endtask // test_ok
18838
 
18839
task test_summary;
18840
begin
18841
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
18842
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
18843
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
18844
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
18845
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
18846
    $fclose(tb_log_file) ;
18847
end
18848
endtask
18849
 
18850
endmodule

powered by: WebSVN 2.1.0

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