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

Subversion Repositories pci

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

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

Line No. Rev Author Line
1 52 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "system.v"                                        ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////      - Tadej Markovic (tadej@opencores.org)                  ////
11
////                                                              ////
12
//////////////////////////////////////////////////////////////////////
13
////                                                              ////
14
//// Copyright (C) 2000 Miha Dolenc, mihad@opencores.org          ////
15
////                                                              ////
16
//// This source file may be used and distributed without         ////
17
//// restriction provided that this copyright statement is not    ////
18
//// removed from the file and that any derivative work contains  ////
19
//// the original copyright notice and the associated disclaimer. ////
20
////                                                              ////
21
//// This source file is free software; you can redistribute it   ////
22
//// and/or modify it under the terms of the GNU Lesser General   ////
23
//// Public License as published by the Free Software Foundation; ////
24
//// either version 2.1 of the License, or (at your option) any   ////
25
//// later version.                                               ////
26
////                                                              ////
27
//// This source is distributed in the hope that it will be       ////
28
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
29
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
30
//// PURPOSE.  See the GNU Lesser General Public License for more ////
31
//// details.                                                     ////
32
////                                                              ////
33
//// You should have received a copy of the GNU Lesser General    ////
34
//// Public License along with this source; if not, download it   ////
35
//// from http://www.opencores.org/lgpl.shtml                     ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38
//
39
// CVS Revision History
40
//
41
// $Log: not supported by cvs2svn $
42 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
43
// Oops, never before noticed that OC header is missing
44 52 mihad
//
45 57 mihad
//
46 52 mihad
 
47 15 mihad
`include "pci_constants.v"
48
`include "bus_commands.v"
49
`include "pci_testbench_defines.v"
50
`include "timescale.v"
51
 
52 51 mihad
`ifdef HOST
53
    `ifdef NO_CNF_IMAGE
54
    `else
55
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
56
    `endif
57
`else
58
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
59
`endif
60
 
61 15 mihad
module SYSTEM ;
62
 
63
`include "pci_blue_constants.vh"
64
`include "pci_blue_options.vh"
65
 
66
integer tests_successfull ;
67
integer tests_failed ;
68
integer tb_log_file ;
69
reg [799:0] test_name ;
70
 
71
reg pci_clock ;
72
reg wb_clock ;
73
reg reset ;
74
 
75
wire [4:0] arb_grant_out ;
76
 
77
wire [31:0] AD ;
78
wire [3:0]  CBE ;
79
pullup(INTA) ;
80
pullup(MAS0_REQ) ;
81
pullup(MAS1_REQ) ;
82
pullup(MAS2_REQ) ;
83
pullup(MAS3_REQ) ;
84
 
85
wire MAS0_GNT = ~arb_grant_out[0];
86
wire MAS1_GNT = ~arb_grant_out[1] ;
87
wire MAS2_GNT = ~arb_grant_out[2] ;
88
wire MAS3_GNT = ~arb_grant_out[3] ;
89
 
90
pullup(FRAME) ;
91
pullup(IRDY) ;
92 45 mihad
 
93
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
94
 
95 15 mihad
pullup(DEVSEL) ;
96
pullup(TRDY) ;
97
pullup(STOP) ;
98
wire   PAR ;
99
pullup(PERR) ;
100
pullup(SERR) ;
101
wire [3:0] MAS1_IDSEL ;
102
 
103
pullup lockpu ( LOCK ) ;
104
 
105
wire        RST_O ;
106
wire        INT_O ;
107
reg         INT_I ;
108
wire [31:0] ADR_I ;
109
wire [31:0] SDAT_I ;
110
wire [31:0] SDAT_O ;
111
wire [3:0]  SEL_I ;
112
wire        CYC_I ;
113
wire        STB_I ;
114
wire        WE_I ;
115
wire        CAB_I ;
116
wire        ACK_O ;
117
wire        RTY_O ;
118
wire        ERR_O ;
119
 
120
wire [31:0] ADR_O ;
121
wire [31:0] MDAT_I ;
122
wire [31:0] MDAT_O ;
123
wire [3:0]  SEL_O ;
124
wire        CYC_O ;
125
wire        STB_O ;
126
wire        WE_O ;
127
wire        CAB_O ;
128
wire        ACK_I ;
129
wire        RTY_I ;
130
wire        ERR_I ;
131
 
132 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
133
 
134
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
135
 
136 15 mihad
wire        reset_wb ; // reset to Wb devices
137
 
138
`ifdef GUEST
139
    wire    RST = ~reset ;
140
    assign  reset_wb = RST_O ;
141
`else
142
    pullup(RST) ;
143
    assign  reset_wb = reset ;
144
`endif
145
 
146
`define PCI_BRIDGE_INSTANCE bridge32_top
147
 
148
TOP `PCI_BRIDGE_INSTANCE
149
(
150
    .CLK    ( pci_clock),
151
    .AD     ( AD ),
152
    .CBE    ( CBE ),
153
    .RST    ( RST ),
154
    .INTA   ( INTA ),
155
    .REQ    ( MAS0_REQ ),
156
    .GNT    ( MAS0_GNT ),
157
    .FRAME  ( FRAME ),
158
    .IRDY   ( IRDY ),
159
    .IDSEL  ( TAR0_IDSEL),
160
    .DEVSEL ( DEVSEL ),
161
    .TRDY   ( TRDY ),
162
    .STOP   ( STOP ),
163
    .PAR    ( PAR ),
164
    .PERR   ( PERR ),
165
    .SERR   ( SERR ),
166
 
167
    .CLK_I  ( wb_clock ),
168
    .RST_I  ( reset ),
169
    .RST_O  ( RST_O ),
170
    .INT_I  ( INT_I ),
171
    .INT_O  ( INT_O ),
172
 
173
    // WISHBONE slave interface
174
    .ADR_I  ( ADR_I ),
175
    .SDAT_I ( SDAT_I ),
176
    .SDAT_O ( SDAT_O ),
177
    .SEL_I  ( SEL_I ),
178
    .CYC_I  ( CYC_I ),
179
    .STB_I  ( STB_I ),
180
    .WE_I   ( WE_I ),
181
    .CAB_I  ( CAB_I),
182
    .ACK_O  ( ACK_O ),
183
    .RTY_O  ( RTY_O ),
184
    .ERR_O  ( ERR_O ),
185
 
186
    // WISHBONE master interface
187
    .ADR_O  ( ADR_O ),
188
    .MDAT_I ( MDAT_I ),
189
    .MDAT_O ( MDAT_O ),
190
    .SEL_O  ( SEL_O ),
191
    .CYC_O  ( CYC_O ),
192
    .STB_O  ( STB_O ),
193
    .WE_O   ( WE_O ),
194
    .CAB_O  ( CAB_O ),
195
    .ACK_I  ( ACK_I ),
196
    .RTY_I  ( RTY_I ),
197
    .ERR_I  ( ERR_I )
198
) ;
199
 
200
WB_MASTER_BEHAVIORAL wishbone_master
201
(
202
    .CLK_I(wb_clock),
203
    .RST_I(reset_wb),
204
    .TAG_I(4'b0000),
205
    .TAG_O(),
206
    .ACK_I(ACK_O),
207
    .ADR_O(ADR_I),
208
    .CYC_O(CYC_I),
209
    .DAT_I(SDAT_O),
210
    .DAT_O(SDAT_I),
211
    .ERR_I(ERR_O),
212
    .RTY_I(RTY_O),
213
    .SEL_O(SEL_I),
214
    .STB_O(STB_I),
215
    .WE_O (WE_I),
216
    .CAB_O(CAB_I)
217
);
218
 
219
WB_SLAVE_BEHAVIORAL wishbone_slave
220
(
221
    .CLK_I              (wb_clock),
222
    .RST_I              (reset_wb),
223
    .ACK_O              (ACK_I),
224
    .ADR_I              (ADR_O),
225
    .CYC_I              (CYC_O),
226
    .DAT_O              (MDAT_I),
227
    .DAT_I              (MDAT_O),
228
    .ERR_O              (ERR_I),
229
    .RTY_O              (RTY_I),
230
    .SEL_I              (SEL_O),
231
    .STB_I              (STB_O),
232
    .WE_I               (WE_O),
233
    .CAB_I              (CAB_O)
234
);
235
 
236
integer wbu_mon_log_file_desc ;
237
integer pciu_mon_log_file_desc ;
238
WB_BUS_MON wbu_wb_mon(
239
                    .CLK_I(wb_clock),
240
                    .RST_I(reset_wb),
241
                    .ACK_I(ACK_O),
242
                    .ADDR_O(ADR_I),
243
                    .CYC_O(CYC_I),
244
                    .DAT_I(SDAT_O),
245
                    .DAT_O(SDAT_I),
246
                    .ERR_I(ERR_O),
247
                    .RTY_I(RTY_O),
248
                    .SEL_O(SEL_I),
249
                    .STB_O(STB_I),
250
                    .WE_O (WE_I),
251
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
252
                    .TAG_O(),
253
                    .CAB_O(CAB_I),
254
                    .log_file_desc ( wbu_mon_log_file_desc )
255
                  ) ;
256
 
257
WB_BUS_MON pciu_wb_mon(
258
                    .CLK_I(wb_clock),
259
                    .RST_I(reset_wb),
260
                    .ACK_I(ACK_I),
261
                    .ADDR_O(ADR_O),
262
                    .CYC_O(CYC_O),
263
                    .DAT_I(MDAT_I),
264
                    .DAT_O(MDAT_O),
265
                    .ERR_I(ERR_I),
266
                    .RTY_I(RTY_I),
267
                    .SEL_O(SEL_O),
268
                    .STB_O(STB_O),
269
                    .WE_O (WE_O),
270
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
271
                    .TAG_O(),
272
                    .CAB_O(CAB_O),
273
                    .log_file_desc( pciu_mon_log_file_desc )
274
                  ) ;
275
 
276
// some aditional signals are needed here because of the arbiter
277
reg [3:0] pci_ext_req_prev ;
278
always@(posedge pci_clock)
279
begin
280
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
281
end
282
reg pci_frame_prev ;
283
always@(posedge pci_clock)
284
begin
285
    pci_frame_prev <= FRAME ;
286
end
287
reg pci_irdy_prev ;
288
always@(posedge pci_clock)
289
begin
290
    pci_irdy_prev <= IRDY ;
291
end
292
 
293
pci_blue_arbiter pci_arbiter
294
(
295
  .pci_int_req_direct(1'b0),
296
  .pci_ext_req_prev(pci_ext_req_prev),
297
  .pci_int_gnt_direct_out(arb_grant_out[4]),
298
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
299
  .pci_frame_prev(~pci_frame_prev),
300
  .pci_irdy_prev(~pci_irdy_prev),
301
  .pci_irdy_now(~IRDY),
302
  .arbitration_enable(1'b1),
303
  .pci_clk(pci_clock),
304
  .pci_reset_comb(~RST)
305
);
306
 
307
reg [31:0] target_message ;
308
 
309
// define output enable signals for monitor inputs
310
// real output enable signals
311
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
312
`ifdef ACTIVE_LOW_OE
313
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
314
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
315
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
316
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
317
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
318
                        !devsel_t_s_oe,
319
                        !ad_oe,
320
                        !cbe_oe,
321
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
322
                        ;
323
`else
324
`ifdef ACTIVE_HIGH_OE
325
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
326
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
327
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
328
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
329
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
330
                        devsel_t_s_oe,
331
                        ad_oe,
332
                        cbe_oe,
333
                        `PCI_BRIDGE_INSTANCE.PERR_en}
334
                        ;
335
`endif
336
`endif
337
/*wire [5:0] oe_sigs_0 = {1'b0,
338
                        1'b0,
339
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
340
                        pci_target32.ad_enable,
341
                        1'b0,
342
                        pci_target32.err_enable | pci_target32.r_err_enable
343
                       } ;
344
*/
345
 
346
wire [5:0] oe_sigs_2 ;
347
wire [5:0] oe_sigs_1 ;
348
 
349
// signals which are used by test modules to know what to do
350
triand  test_accepted_l_int, error_event_int;
351
pullup  (test_accepted_l_int), (error_event_int);
352
 
353
wire    pci_reset_comb  = ~RST;
354
wire    pci_ext_clk     = pci_clock;
355
 
356
integer pci_mon_log_file_desc ;
357
pci_bus_monitor monitor32
358
(
359
    .pci_ext_ad                 (AD),
360
    .pci_ext_cbe_l              (CBE),
361
    .pci_ext_par                (PAR),
362
    .pci_ext_frame_l            (FRAME),
363
    .pci_ext_irdy_l             (IRDY),
364
    .pci_ext_devsel_l           (DEVSEL),
365
    .pci_ext_trdy_l             (TRDY),
366
    .pci_ext_stop_l             (STOP),
367
    .pci_ext_perr_l             (PERR),
368
    .pci_ext_serr_l             (SERR),
369
    .pci_real_req_l             (MAS0_REQ),
370
    .pci_real_gnt_l             (MAS0_GNT),
371
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
372
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
373
    .test_error_event           (error_event_int),
374
    .test_observe_r_oe_sigs     (r_oe_sigs),
375
    .test_observe_0_oe_sigs     (6'h00),
376
    .test_observe_1_oe_sigs     (oe_sigs_1),
377
    .test_observe_2_oe_sigs     (oe_sigs_2),
378
    .test_observe_3_oe_sigs     (6'h00),
379
    .pci_ext_reset_l            (RST),
380
    .pci_ext_clk                (pci_clock),
381
    .log_file_desc              (pci_mon_log_file_desc)
382
) ;
383
 
384
reg [2:0]  test_master_number ;
385
reg [31:0] test_address ;
386
reg [3:0]  test_command ;
387
reg [31:0] test_data ;
388
reg [3:0]  test_byte_enables_l ;
389
reg [9:0]  test_size ;
390
reg        test_make_addr_par_error ;
391
reg        test_make_data_par_error ;
392
reg [3:0]  test_master_initial_wait_states ;
393
reg [3:0]  test_master_subsequent_wait_states ;
394
reg [3:0]  test_target_initial_wait_states ;
395
reg [3:0]  test_target_subsequent_wait_states ;
396
reg [1:0]  test_target_devsel_speed ;
397
reg        test_fast_back_to_back ;
398
reg [2:0]  test_target_termination ;
399
reg        test_expect_master_abort ;
400
reg        test_start ;
401
reg [25:0] test_target_response ;
402
 
403
wire [31:0] master2_received_data ;
404
wire        master2_received_data_valid ;
405
reg         master2_check_received_data ;
406
pci_behaviorial_device pci_behaviorial_device2
407
(
408
    .pci_ext_ad(AD),
409
    .pci_ext_cbe_l(CBE),
410
    .pci_ext_par(PAR),
411
    .pci_ext_frame_l(FRAME),
412
    .pci_ext_irdy_l(IRDY),
413
    .pci_ext_devsel_l(DEVSEL),
414
    .pci_ext_trdy_l(TRDY),
415
    .pci_ext_stop_l(STOP),
416
    .pci_ext_perr_l(PERR),
417
    .pci_ext_serr_l(SERR),
418
    .pci_ext_idsel(TAR2_IDSEL),
419
    .pci_ext_inta_l(INTA),
420
    .pci_ext_req_l(MAS2_REQ),
421
    .pci_ext_gnt_l(MAS2_GNT),
422
    .pci_ext_reset_l(RST),
423
    .pci_ext_clk(pci_clock),
424
 
425
// Signals used by the test bench instead of using "." notation
426
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
427
    .test_master_number                 (test_master_number[2:0]),
428
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
429
    .test_command                       (test_command[3:0]),
430
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
431
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
432
    .test_size                          (test_size),
433
    .test_make_addr_par_error           (test_make_addr_par_error),
434
    .test_make_data_par_error           (test_make_data_par_error),
435
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
436
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
437
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
438
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
439
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
440
    .test_fast_back_to_back             (test_fast_back_to_back),
441
    .test_target_termination            (test_target_termination[2:0]),
442
    .test_expect_master_abort           (test_expect_master_abort),
443
    .test_start                         (test_start),
444
    .test_accepted_l                    (test_accepted_l_int),
445
    .test_error_event                   (error_event_int),
446
    .test_device_id                     (`Test_Master_2),
447
    .test_target_response               (test_target_response),
448
 
449
    .master_received_data               (master2_received_data),
450
    .master_received_data_valid         (master2_received_data_valid),
451
    .master_check_received_data         (master2_check_received_data)
452
);
453
 
454
wire [31:0] master1_received_data ;
455
wire        master1_received_data_valid ;
456
reg         master1_check_received_data ;
457
pci_behaviorial_device pci_behaviorial_device1
458
(
459
    .pci_ext_ad(AD),
460
    .pci_ext_cbe_l(CBE),
461
    .pci_ext_par(PAR),
462
    .pci_ext_frame_l(FRAME),
463
    .pci_ext_irdy_l(IRDY),
464
    .pci_ext_devsel_l(DEVSEL),
465
    .pci_ext_trdy_l(TRDY),
466
    .pci_ext_stop_l(STOP),
467
    .pci_ext_perr_l(PERR),
468
    .pci_ext_serr_l(SERR),
469
    .pci_ext_idsel(TAR1_IDSEL),
470
    .pci_ext_inta_l(INTA),
471
    .pci_ext_req_l(MAS1_REQ),
472
    .pci_ext_gnt_l(MAS1_GNT),
473
    .pci_ext_reset_l(RST),
474
    .pci_ext_clk(pci_clock),
475
 
476
// Signals used by the test bench instead of using "." notation
477
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
478
    .test_master_number                 (test_master_number[2:0]),
479
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
480
    .test_command                       (test_command[3:0]),
481
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
482
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
483
    .test_size                          (test_size),
484
    .test_make_addr_par_error           (test_make_addr_par_error),
485
    .test_make_data_par_error           (test_make_data_par_error),
486
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
487
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
488
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
489
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
490
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
491
    .test_fast_back_to_back             (test_fast_back_to_back),
492
    .test_target_termination            (test_target_termination[2:0]),
493
    .test_expect_master_abort           (test_expect_master_abort),
494
    .test_start                         (test_start),
495
    .test_accepted_l                    (test_accepted_l_int),
496
    .test_error_event                   (error_event_int),
497
    .test_device_id                     (`Test_Master_1),
498
    .test_target_response               (test_target_response),
499
 
500
    .master_received_data               (master1_received_data),
501
    .master_received_data_valid         (master1_received_data_valid),
502
    .master_check_received_data         (master1_check_received_data)
503
);
504
 
505
pci_unsupported_commands_master ipci_unsupported_commands_master
506
(
507
    .CLK    ( pci_clock),
508
    .AD     ( AD ),
509
    .CBE    ( CBE ),
510
    .RST    ( RST ),
511
    .REQ    ( MAS3_REQ ),
512
    .GNT    ( MAS3_GNT ),
513
    .FRAME  ( FRAME ),
514
    .IRDY   ( IRDY ),
515
    .DEVSEL ( DEVSEL ),
516
    .TRDY   ( TRDY ),
517
    .STOP   ( STOP ),
518
    .PAR    ( PAR )
519
) ;
520
 
521 45 mihad
`ifdef HOST
522
 
523
reg     [1:0]   conf_cyc_type1_target_response ;
524
reg     [31:0]  conf_cyc_type1_target_data ;
525
reg     [7:0]   conf_cyc_type1_target_bus_num ;
526
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
527
 
528
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
529
(
530
    .CLK              ( pci_clock),
531
    .AD               ( AD ),
532
    .CBE              ( CBE ),
533
    .RST              ( RST ),
534
    .FRAME            ( FRAME ),
535
    .IRDY             ( IRDY ),
536
    .DEVSEL           ( DEVSEL ),
537
    .TRDY             ( TRDY ),
538
    .STOP             ( STOP ),
539
    .PAR              ( PAR ),
540
 
541
    .response         ( conf_cyc_type1_target_response ),
542
    .data_out         ( conf_cyc_type1_target_data ),
543
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
544
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
545
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
546
    .bus_number       ( conf_cyc_type1_target_bus_num )
547
);
548
`endif
549
 
550 15 mihad
// pci clock generator
551
always
552
`ifdef PCI33
553
    #15 pci_clock = ~pci_clock ;
554
`else
555
`ifdef PCI66
556
    #7.5 pci_clock = ~pci_clock ;
557
`endif
558
`endif
559
 
560
// WISHBONE clock generation
561
always
562
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
563
 
564
// Make test name visible when the Master starts working on it
565
reg     [79:0] present_test_name;
566
reg     [79:0] next_test_name;
567
wire    test_accepted = ~test_accepted_l_int;
568
always @(posedge test_accepted)
569
begin
570
    present_test_name <= next_test_name;
571
end
572
 
573
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
574
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
575
 
576
// basic configuration parameters for both behavioral devices
577
parameter [2:0] Master_ID_A                           = `Test_Master_1;
578
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
579
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
580
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
581
 
582
parameter [2:0] Master_ID_B                           = `Test_Master_2;
583
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
584
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
585
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
586
 
587
// basic configuration parameters for REAL device
588
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
589
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
590
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
591
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
592
 
593
// reg  [2:0]   ack_err_rty_termination ;
594
// reg          wait_cycles ;
595
// reg  [7:0]   num_of_retries ;
596
 
597
//reg [19:0] pci_config_base ;
598
reg [7:0] system_burst_size ;
599
reg [7:0] bridge_latency ;
600
integer   target_mem_image ;
601
integer   target_io_image ;
602
 
603
initial
604
begin
605
    next_test_name[79:0] <= "Nowhere___";
606
    reset = 1'b1 ;
607
    pci_clock = 1'b0 ;
608
    wb_clock  = 1'b1 ;
609
    target_message = 32'h0000_0000 ;
610
//  num_of_retries = 8'h01 ;
611
//  ack_err_rty_termination = 3'b100 ;
612
//  wait_cycles = 1'b0 ;
613
 
614
    // system paameters
615
    system_burst_size = 16 ;
616
    bridge_latency    = 8 ;
617
 
618
    // set initial values for controling the behavioral PCI master
619
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
620
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
621
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
622
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
623
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
624
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
625
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
626
 
627
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
628
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
629
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
630
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
631
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
632
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
633
 
634
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
635
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
636
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
637
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
638
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
639
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
640
 
641
    test_master_number = `Test_Master_2 ;
642
    test_address = 32'h0000_0000 ;
643
    test_command = `BC_RESERVED0 ;
644
    test_data = 32'h0000_0000 ;
645
    test_byte_enables_l   = 4'hF ;
646
    test_size = 0 ;
647
    test_make_addr_par_error = 0 ;
648
    test_make_data_par_error = 0;
649
    test_master_initial_wait_states = 0 ;
650
    test_master_subsequent_wait_states = 0 ;
651
    test_target_initial_wait_states = 0 ;
652
    test_target_subsequent_wait_states = 0;
653
    test_target_devsel_speed = `Test_Devsel_Fast ;
654
    test_fast_back_to_back = 0 ;
655
    test_target_termination = `Test_Target_Normal_Completion ;
656
    test_expect_master_abort = 0 ;
657
    test_start = 0 ;
658
    test_target_response = 0 ;
659
 
660
    master1_check_received_data = 0 ;
661
    master2_check_received_data = 0 ;
662
 
663 45 mihad
    `ifdef HOST
664
        conf_cyc_type1_target_response = 0 ;
665
        conf_cyc_type1_target_data = 0 ;
666
        conf_cyc_type1_target_bus_num = 255 ;
667
    `endif
668 15 mihad
 
669
    // fill memory and IO data with random values
670
    fill_memory ;
671
 
672
    INT_I = 0 ;
673
 
674
    // extract from constants which target image can be used as IO and which as memory
675
    `ifdef HOST
676
        target_mem_image = 1 ;
677
        target_io_image  = 1 ;
678
    `else
679
        target_mem_image = -1 ;
680
        target_io_image     = -1 ;
681
        if ( `PCI_BA1_MEM_IO === 0 )
682
            target_mem_image = 1 ;
683
        else
684
            target_io_image = 1 ;
685
 
686
        if ( target_mem_image === -1 )
687
        begin
688
            `ifdef PCI_IMAGE2
689
                if ( `PCI_BA2_MEM_IO === 0 )
690
                    target_mem_image = 2 ;
691
                else if ( target_io_image === -1 )
692
                    target_io_image = 2 ;
693
            `endif
694
        end
695
 
696
        if ( target_mem_image === -1 )
697
        begin
698
            `ifdef PCI_IMAGE3
699
                if ( `PCI_BA3_MEM_IO === 0 )
700
                    target_mem_image = 3 ;
701
                else if ( target_io_image === -1 )
702
                    target_io_image = 3 ;
703
            `endif
704
        end
705
 
706
        if ( target_mem_image === -1 )
707
        begin
708
            `ifdef PCI_IMAGE4
709
                if ( `PCI_BA4_MEM_IO === 0 )
710
                    target_mem_image = 4 ;
711
                else if ( target_io_image === -1 )
712
                    target_io_image = 4 ;
713
            `endif
714
        end
715
 
716
        if ( target_mem_image === -1 )
717
        begin
718
            `ifdef PCI_IMAGE5
719
                if ( `PCI_BA5_MEM_IO === 0 )
720
                    target_mem_image = 5 ;
721
                else if ( target_io_image === -1 )
722
                    target_io_image = 5 ;
723
            `endif
724
        end
725
    `endif
726
 
727
    tests_successfull = 0 ;
728
    tests_failed = 0 ;
729
 
730
    tb_log_file = $fopen("../log/pci_tb.log") ;
731
 
732
    if ( tb_log_file < 2 )
733
    begin
734
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
735
        $finish ;
736
    end
737
 
738
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
739
    $fdisplay( tb_log_file,"" ) ;
740
 
741
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
742
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
743
 
744
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
745
    begin
746
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
747
        $finish ;
748
    end
749
 
750
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
751
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
752
 
753
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
754
    if ( pci_mon_log_file_desc < 2 )
755
    begin
756
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
757
        $finish ;
758
    end
759
 
760
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
761
 
762
    run_tests ;
763
end
764
 
765
task fill_memory ;
766
    integer temp_index ;
767
begin
768
    // fill write memories with random data
769
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
770
    begin
771
        wmem_data[temp_index[9:0]] = $random ;
772 26 mihad
        # 1;
773 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
774 26 mihad
        # 1;
775 15 mihad
    end
776
    // fill WB slave behavioral MEMORY
777
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
778
    begin
779
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
780
        # 1;
781
    end
782
end
783
endtask // fill_memory
784
 
785
reg [2:0] tb_init_waits ;
786
reg [2:0] tb_subseq_waits ;
787
reg [2:0] tb_target_decode_speed ;
788
 
789
task run_tests ;
790
begin
791
    // first - reset logic
792
    do_reset ;
793 45 mihad
    test_initial_conf_values ;
794
 
795 15 mihad
    next_test_name[79:0] <= "Initing...";
796
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
797
 
798
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
799
    begin
800
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
801
        begin
802
 
803
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
804
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
805
 
806
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
807
            begin
808
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
809
 
810
                `ifdef HOST
811
                    configure_bridge_target ;
812
                    find_pci_devices ;
813 45 mihad
                    test_configuration_cycle_target_abort ;
814
                    test_configuration_cycle_type1_generation ;
815 15 mihad
                `endif
816
 
817
                @(posedge pci_clock) ;
818
                configure_target(1) ;
819
                @(posedge pci_clock) ;
820
                configure_target(2) ;
821
 
822
                `ifdef GUEST
823
                    configure_bridge_target ;
824
                `endif
825
 
826
               next_test_name[79:0] <= "WB_SLAVE..";
827
 
828
                $display("Testing WISHBONE slave images' features!") ;
829
                test_wb_image(1) ;
830
 
831
                `ifdef WB_IMAGE2
832
                    test_wb_image(2) ;
833
                `else
834
                    $display(" WB IMAGE 2 not implemented! ") ;
835
                `endif
836
 
837
                `ifdef WB_IMAGE3
838
                    test_wb_image(3) ;
839
                `else
840
                    $display(" WB IMAGE 3 not implemented! ") ;
841
                `endif
842
 
843
                `ifdef WB_IMAGE4
844
                    test_wb_image(4) ;
845
                `else
846
                    $display(" WB IMAGE 4 not implemented! ") ;
847
                `endif
848
 
849
                `ifdef WB_IMAGE5
850
                    test_wb_image(5) ;
851
                `else
852
                    $display(" WB IMAGE 5 not implemented! ") ;
853
                `endif
854
 
855
                wb_slave_errors ;
856
                wb_to_pci_error_handling ;
857
 
858
                parity_checking ;
859
 
860
                wb_to_pci_transactions ;
861
 
862
                `ifdef HOST
863
                iack_cycle ;
864
                `endif
865
 
866
            end
867 57 mihad
 
868
            master_completion_expiration ;
869
 
870 15 mihad
            $display(" ") ;
871
            $display("WB slave images' tests finished!") ;
872
 
873
            $display("########################################################################") ;
874
            $display("########################################################################") ;
875
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
876
            $display("########################################################################") ;
877
            $display("########################################################################") ;
878
 
879
            $display("Testing PCI target images' features!") ;
880
            configure_bridge_target_base_addresses ;
881
 
882 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
883
                test_conf_cycle_type1_reference ;
884
            `endif
885
 
886 15 mihad
            `ifdef HOST
887
             `ifdef NO_CNF_IMAGE
888
              `ifdef PCI_IMAGE0
889
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
890
            test_pci_image(0) ;
891
              `else
892
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
893
              `endif
894
             `else
895
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
896
             `endif
897
            `endif
898
 
899
            $display("PCI image 1 is ALWAYS implemented!") ;
900
            test_pci_image(1) ;
901
 
902
            `ifdef PCI_IMAGE2
903
            $display("PCI image 2 is implemented!") ;
904
            test_pci_image(2) ;
905
            `else
906
            $display("PCI image 2 is NOT implemented!") ;
907
            `endif
908
 
909
            `ifdef PCI_IMAGE3
910
            $display("PCI image 3 is implemented!") ;
911
            test_pci_image(3) ;
912
            `else
913
            $display("PCI image 3 is NOT implemented!") ;
914
            `endif
915
 
916
            `ifdef PCI_IMAGE4
917
            $display("PCI image 4 is implemented!") ;
918
            test_pci_image(4) ;
919
            `else
920
            $display("PCI image 4 is NOT implemented!") ;
921
            `endif
922
 
923
            `ifdef PCI_IMAGE5
924
            $display("PCI image 5 is implemented!") ;
925
            test_pci_image(5) ;
926
            `else
927
            $display("PCI image 5 is NOT implemented!") ;
928
            `endif
929
 
930
            test_wb_error_rd ;
931
 
932
            target_fast_back_to_back ;
933
            target_disconnects ;
934
 
935
            if ( target_io_image !== -1 )
936
                test_target_abort( target_io_image ) ;
937
            $display(" ") ;
938
            $display("PCI target images' tests finished!") ;
939
 
940
            transaction_ordering ;
941 33 mihad
 
942
            target_completion_expiration ;
943 15 mihad
            $display(" ") ;
944
            $display("PCI transaction ordering tests finished!") ;
945
        end
946
    end
947
 
948
    test_summary ;
949
 
950
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
951
    $stop ;
952
end
953
endtask // run_tests
954
 
955
task do_reset;
956
begin
957
    next_test_name[79:0] <= "Reset.....";
958
 
959
    reset = 1'b1 ;
960
    #100 ;
961
    `ifdef HOST
962
        @(posedge wb_clock) ;
963
    `else
964
    `ifdef GUEST
965
        @(posedge pci_clock) ;
966
    `endif
967
    `endif
968
 
969
    reset <= 1'b0 ;
970
 
971 45 mihad
    `ifdef HOST
972
        @(posedge wb_clock) ;
973
    `else
974
    `ifdef GUEST
975
        @(posedge pci_clock) ;
976
    `endif
977
    `endif
978
 
979 15 mihad
end
980
endtask
981
 
982
/*############################################################################
983
WB SLAVE UNIT tasks
984
===================
985
############################################################################*/
986
 
987
task configure_target ;
988 45 mihad
    input [1:0]  beh_dev_num ;
989 15 mihad
    reg   [31:0] base_address1 ;
990
    reg   [31:0] base_address2 ;
991
    reg   [2:0]  Master_ID;
992
    reg   [31:0] Target_Config_Addr;
993 45 mihad
    reg   [4:0]  device_num ;
994 15 mihad
begin
995 45 mihad
    if (beh_dev_num === 1)
996 15 mihad
    begin
997
        base_address1       = `BEH_TAR1_MEM_START ;
998
        base_address2       = `BEH_TAR1_IO_START  ;
999
        Master_ID           = `Test_Master_2 ;
1000
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1001 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1002 15 mihad
    end
1003
    else
1004 45 mihad
    if (beh_dev_num === 2)
1005 15 mihad
    begin
1006
        base_address1       = `BEH_TAR2_MEM_START ;
1007
        base_address2       = `BEH_TAR2_IO_START  ;
1008
        Master_ID           = `Test_Master_1 ;
1009
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1010 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1011 15 mihad
    end
1012
 
1013
    // write target's base addresses
1014
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1015
    // type 0 cycle, byte enables, base address
1016
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1017
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1018
 
1019
    // enable target's response and master
1020
    // enable parity errors, disable system error
1021
 
1022
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1023
 
1024
end
1025
endtask //configure_target
1026
 
1027
task test_wb_image ;
1028
    input [2:0]  image_num ;
1029
    reg   [11:0] ctrl_offset ;
1030
    reg   [11:0] ba_offset ;
1031
    reg   [11:0] am_offset ;
1032
    reg   [11:0] ta_offset ;
1033
    reg   [11:0] err_cs_offset ;
1034
    reg `WRITE_STIM_TYPE write_data ;
1035
    reg `READ_STIM_TYPE  read_data ;
1036
    reg `READ_RETURN_TYPE read_status ;
1037
 
1038
    reg `WRITE_RETURN_TYPE write_status ;
1039
    reg `WB_TRANSFER_FLAGS write_flags ;
1040
    reg [31:0] temp_val ;
1041
    reg        ok   ;
1042
    reg [11:0] pci_ctrl_offset ;
1043
    reg [31:0] image_base ;
1044
    reg [31:0] target_address ;
1045
    reg [31:0] translation_address ;
1046
    integer    i ;
1047
    integer    j ;
1048
begin:main
1049
    pci_ctrl_offset = 12'h4 ;
1050
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1051
    // image 0 can only be configuration image - start with 1
1052
    if (image_num === 1)
1053
    begin
1054
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1055
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1056
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1057
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1058
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1059
    end
1060
    else if (image_num === 2)
1061
    begin
1062
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1063
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1064
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1065
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1066
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1067
    end
1068
    else if (image_num === 3)
1069
    begin
1070
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1071
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1072
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1073
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1074
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1075
    end
1076
    else if (image_num === 4)
1077
    begin
1078
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1079
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1080
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1081
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1082
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1083
    end
1084
    else if (image_num === 5)
1085
    begin
1086
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1087
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1088
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1089
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1090
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1091
    end
1092
    else
1093
    begin
1094
        test_name   = "WB IMAGES' FEATURES TEST" ;
1095
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1096
        disable main ;
1097
    end
1098
 
1099
    target_address  = `BEH_TAR1_MEM_START ;
1100
    image_base      = 0 ;
1101
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1102
 
1103
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1104
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1105
    write_flags                      = 0 ;
1106
    write_flags`INIT_WAITS           = tb_init_waits ;
1107
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1108
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1109
 
1110
    test_name = "WB IMAGE CONFIGURATION" ;
1111
    // enable master & target operation
1112
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1113
    if ( ok !== 1 )
1114
    begin
1115
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1116
        test_fail("write to PCI Device Control register didn't succeede");
1117
        disable main ;
1118
    end
1119
 
1120
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1121
    if ( ok !== 1 )
1122
    begin
1123
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1124
        test_fail("write to WB Error Control and Status register didn't succeede");
1125
        disable main ;
1126
    end
1127
 
1128
    // prepare image control register
1129
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1130
    if ( ok !== 1 )
1131
    begin
1132
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1133
        test_fail("write to WB Image Control register didn't succeede");
1134
        disable main ;
1135
    end
1136
 
1137
    // prepare base address register
1138
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1139
    if ( ok !== 1 )
1140
    begin
1141
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1142
        test_fail("write to WB Base Address register didn't succeede");
1143
        disable main ;
1144
    end
1145
 
1146
    // write address mask register
1147
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1148
    if ( ok !== 1 )
1149
    begin
1150
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1151
        test_fail("write to WB Address Mask register didn't succeede");
1152
        disable main ;
1153
    end
1154
 
1155
    fork
1156
    begin
1157
        write_data`WRITE_ADDRESS = target_address ;
1158
        write_data`WRITE_DATA    = wmem_data[0] ;
1159
        write_data`WRITE_SEL     = 4'hF ;
1160
 
1161
        // handle retries from now on
1162
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1163
 
1164
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1165
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1166
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1167
        begin
1168
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1169
            test_fail("WB Slave state machine failed to post single memory write");
1170
            disable main ;
1171
        end
1172
 
1173
        // read written data back
1174
        read_data`READ_ADDRESS  = target_address ;
1175
        read_data`READ_SEL      = 4'hF ;
1176
        read_data`READ_TAG_STIM = 0 ;
1177
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1178
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1179
        begin
1180
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1181
            test_fail("PCI bridge didn't process the read as expected");
1182
            disable main ;
1183
        end
1184
 
1185
        if (read_status`READ_DATA !== wmem_data[0])
1186
        begin
1187
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1188
            test_fail("PCI bridge returned unexpected Read Data");
1189
        end
1190
        else
1191
            test_ok ;
1192
    end
1193
    begin
1194
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1195
        if ( ok !== 1 )
1196
        begin
1197
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1198
        end
1199
        else
1200
            test_ok ;
1201
 
1202
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1203
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1204
        if ( ok !== 1 )
1205
        begin
1206
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1207
        end
1208
    end
1209
    join
1210
 
1211
    // if address translation is implemented - try it out
1212
    translation_address = image_base ;
1213
    `ifdef ADDR_TRAN_IMPL
1214
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1215
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1216
    if ( ok !== 1 )
1217
    begin
1218
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1219
        test_fail("write to WB Image Translation Address Register failed") ;
1220
        disable main ;
1221
    end
1222
 
1223
    target_address  = `BEH_TAR2_MEM_START ;
1224
    image_base      = 0 ;
1225
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1226
 
1227
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1228
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1229
 
1230
    write_flags                      = 0 ;
1231
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1232
 
1233
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1234
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1235
    if ( ok !== 1 )
1236
    begin
1237
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1238
        test_fail("write to WB Image Base Address Register failed") ;
1239
        disable main ;
1240
    end
1241
 
1242
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1243
    // enable address translation
1244
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1245
    if ( ok !== 1 )
1246
    begin
1247
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1248
        test_fail("write to WB Image Control Register failed") ;
1249
        disable main ;
1250
    end
1251
 
1252
    `endif
1253
 
1254
    fork
1255
    begin
1256
        write_data`WRITE_ADDRESS = target_address + 4 ;
1257
        write_data`WRITE_DATA    = wmem_data[1] ;
1258
        write_data`WRITE_SEL     = 4'hF ;
1259
 
1260
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1261
 
1262
        `ifdef ADDR_TRAN_IMPL
1263
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1264
        `else
1265
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1266
        `endif
1267
 
1268
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1269
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1270
        begin
1271
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1272
            test_fail("WB Slave state machine failed to post single memory write") ;
1273
            disable main ;
1274
        end
1275
 
1276
        // read written data back
1277
        read_data`READ_ADDRESS  = target_address + 4 ;
1278
        read_data`READ_SEL      = 4'hF ;
1279
        read_data`READ_TAG_STIM = 0 ;
1280
 
1281
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1282
 
1283
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1284
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1285
        begin
1286
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1287
            test_fail("PCI bridge failed to process single delayed memory read") ;
1288
            disable main ;
1289
        end
1290
 
1291
        if (read_status`READ_DATA !== wmem_data[1])
1292
        begin
1293
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1294
            test_fail("PCI bridge returned unexpected Read Data");
1295
        end
1296
        else
1297
            test_ok ;
1298
    end
1299
    begin
1300
        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 ) ;
1301
        if ( ok !== 1 )
1302
        begin
1303
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1304
        end
1305
        else
1306
            test_ok ;
1307
 
1308
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1309
        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 ) ;
1310
        if ( ok !== 1 )
1311
        begin
1312
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1313
        end
1314
    end
1315
    join
1316
 
1317
    // 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
1318
    // prepare write data
1319
    for ( i = 0 ; i < 6 ; i = i + 1 )
1320
    begin
1321
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1322
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1323
        write_data`WRITE_SEL     = 4'hF ;
1324
        wishbone_master.blk_write_data[i] = write_data ;
1325
    end
1326
 
1327
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1328
    write_flags`WB_TRANSFER_CAB    = 1 ;
1329
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1330
 
1331
    fork
1332
    begin
1333
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1334
        wishbone_master.wb_block_write(write_flags, write_status) ;
1335
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1336
        begin
1337
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1338
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1339
            disable main ;
1340
        end
1341
    end
1342
    begin
1343
        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 ) ;
1344
        if ( ok !== 1 )
1345
        begin
1346
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1347
        end
1348
        else
1349
            test_ok ;
1350
    end
1351
    join
1352
 
1353
    // set burst size and latency timer
1354
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1355
 
1356
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1357
    write_flags`WB_TRANSFER_CAB    = 1 ;
1358
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1359
 
1360
    // prepare read data
1361
    for ( i = 0 ; i < 4 ; i = i + 1 )
1362
    begin
1363
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1364
        read_data`READ_SEL     = 4'hF ;
1365
        wishbone_master.blk_read_data_in[i] = read_data ;
1366
    end
1367
 
1368
    fork
1369
    begin
1370
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1371
        wishbone_master.wb_block_read(write_flags, read_status) ;
1372
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1373
        begin
1374
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1375
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1376
            disable main ;
1377
        end
1378
 
1379
        // check data read from target
1380
        for ( i = 0 ; i < 4 ; i = i + 1 )
1381
        begin
1382
            read_status = wishbone_master.blk_read_data_out[i] ;
1383
            if (read_status`READ_DATA !== wmem_data[2 + i])
1384
            begin
1385
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1386
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1387
            end
1388
        end
1389
    end
1390
    begin
1391
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_READ, 1, 0, 1'b1, 0, 0, ok ) ;
1392
        if ( ok !== 1 )
1393
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1394
        else
1395
            test_ok ;
1396
 
1397
        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 ) ;
1398
        if ( ok !== 1 )
1399
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1400
        else
1401
            test_ok ;
1402
 
1403
        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 ) ;
1404
        if ( ok !== 1 )
1405
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1406
        else
1407
            test_ok ;
1408
 
1409
        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 ) ;
1410
        if ( ok !== 1 )
1411
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1412
        else
1413
            test_ok ;
1414
 
1415
    end
1416
    join
1417
 
1418
    // now repeat this same burst read with various image features enabled or disabled
1419
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1420
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1421
    if (ok !== 1)
1422
    begin
1423
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1424
        test_fail("write to WB Image control register failed") ;
1425
        disable main ;
1426
    end
1427
 
1428
    fork
1429
    begin
1430
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1431
        wishbone_master.wb_block_read(write_flags, read_status) ;
1432
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1433
        begin
1434
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1435
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1436
            disable main ;
1437
        end
1438
 
1439
        // check data read from target
1440
        for ( i = 0 ; i < 4 ; i = i + 1 )
1441
        begin
1442
            read_status = wishbone_master.blk_read_data_out[i] ;
1443
            if (read_status`READ_DATA !== wmem_data[2 + i])
1444
            begin
1445
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1446
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1447
            end
1448
            else
1449
                test_ok ;
1450
        end
1451
    end
1452
    begin
1453
        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 ) ;
1454
        if ( ok !== 1 )
1455
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1456
    end
1457
    join
1458
 
1459
    read_data`READ_ADDRESS  = target_address ;
1460
    read_data`READ_SEL      = 4'hF ;
1461
    read_data`READ_TAG_STIM = 0 ;
1462
 
1463
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1464
    fork
1465
    begin
1466
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1467
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1468
        begin
1469
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1470
            test_fail("delayed single memory read wasn't processed as expected") ;
1471
            disable main ;
1472
        end
1473
 
1474
        if (read_status`READ_DATA !== wmem_data[0])
1475
        begin
1476
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1477
            test_fail("delayed single memory read data value returned was not as expected") ;
1478
        end
1479
        else
1480
            test_ok ;
1481
    end
1482
    begin
1483
        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 ) ;
1484
        if ( ok !== 1 )
1485
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1486
    end
1487
    join
1488
 
1489
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1490
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1491
    if (ok !== 1)
1492
    begin
1493
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1494
        test_fail("write to WB Image control register failed") ;
1495
        disable main ;
1496
    end
1497
 
1498
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1499
    fork
1500
    begin
1501
        wishbone_master.wb_block_read(write_flags, read_status) ;
1502
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1503
        begin
1504
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1505
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1506
            disable main ;
1507
        end
1508
 
1509
        // check data read from target
1510
        for ( i = 0 ; i < 4 ; i = i + 1 )
1511
        begin
1512
            read_status = wishbone_master.blk_read_data_out[i] ;
1513
            if (read_status`READ_DATA !== wmem_data[2 + i])
1514
            begin
1515
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1516
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1517
            end
1518
            else
1519
                test_ok ;
1520
        end
1521
    end
1522
    begin
1523
        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 ) ;
1524
        if ( ok !== 1 )
1525
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1526
    end
1527
    join
1528
 
1529
    read_data`READ_ADDRESS  = target_address + 4 ;
1530
    read_data`READ_SEL      = 4'hF ;
1531
    read_data`READ_TAG_STIM = 0 ;
1532
 
1533
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1534
    fork
1535
    begin
1536
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1537
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1538
        begin
1539
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1540
            test_fail("delayed single memory read wasn't processed as expected") ;
1541
            disable main ;
1542
        end
1543
 
1544
        if (read_status`READ_DATA !== wmem_data[1])
1545
        begin
1546
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1547
            test_fail("delayed single memory read data value returned was not as expected") ;
1548
        end
1549
        else
1550
            test_ok ;
1551
    end
1552
    begin
1553
        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 ) ;
1554
        if ( ok !== 1 )
1555
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1556
    end
1557
    join
1558
 
1559
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1560
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1561
    if (ok !== 1)
1562
    begin
1563
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1564
        test_fail("write to WB Image control register failed") ;
1565
        disable main ;
1566
    end
1567
 
1568
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1569
    fork
1570
    begin
1571
        wishbone_master.wb_block_read(write_flags, read_status) ;
1572
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1573
        begin
1574
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1575
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1576
            disable main ;
1577
        end
1578
 
1579
        // check data read from target
1580
        for ( i = 0 ; i < 4 ; i = i + 1 )
1581
        begin
1582
            read_status = wishbone_master.blk_read_data_out[i] ;
1583
            if (read_status`READ_DATA !== wmem_data[2 + i])
1584
            begin
1585
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1586
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1587
            end
1588
            else
1589
                test_ok ;
1590
        end
1591
    end
1592
    begin
1593
        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 ) ;
1594
        if ( ok !== 1 )
1595
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1596
    end
1597
    join
1598
 
1599
    read_data`READ_ADDRESS  = target_address + 8 ;
1600
    read_data`READ_SEL      = 4'hF ;
1601
    read_data`READ_TAG_STIM = 0 ;
1602
 
1603
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1604
    fork
1605
    begin
1606
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1607
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1608
        begin
1609
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1610
            test_fail("delayed single memory read wasn't processed as expected") ;
1611
            disable main ;
1612
        end
1613
 
1614
        if (read_status`READ_DATA !== wmem_data[2])
1615
        begin
1616
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1617
            test_fail("delayed single memory read data value returned was not as expected") ;
1618
        end
1619
        else
1620
            test_ok ;
1621
    end
1622
    begin
1623
        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 ) ;
1624
        if ( ok !== 1 )
1625
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1626
    end
1627
    join
1628
 
1629
    // map image to IO space
1630
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1631
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1632
    if ( ok !== 1 )
1633
    begin
1634
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1635
        test_fail("write to WB Image Base Address register failed") ;
1636
        disable main ;
1637
    end
1638
 
1639
    write_data`WRITE_ADDRESS = target_address ;
1640
    write_data`WRITE_DATA    = wmem_data[11] ;
1641
    write_data`WRITE_SEL     = 4'hF ;
1642
 
1643
    // handle retries from now on
1644
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1645
 
1646
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1647
    fork
1648
    begin
1649
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1650
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1651
        begin
1652
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1653
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1654
            disable main ;
1655
        end
1656
    end
1657
    begin
1658
        // currently IO commands not supported in behavioral models - master abort
1659
        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 ) ;
1660
        if ( ok !== 1 )
1661
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1662
        else
1663
            test_ok ;
1664
    end
1665
    join
1666
 
1667
    read_data`READ_ADDRESS  = target_address ;
1668
    read_data`READ_SEL      = 4'hF ;
1669
    read_data`READ_TAG_STIM = 0 ;
1670
 
1671
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1672
 
1673
    // currently io commands are not supported by behavioral target - transfer should not be completed
1674
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1675
    fork
1676
    begin
1677
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1678
        if (read_status`CYC_ERR !== 1)
1679
        begin
1680
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1681
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1682
            disable main ;
1683
        end
1684
        else
1685
            test_ok ;
1686
    end
1687
    begin
1688
        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 ) ;
1689
        if ( ok !== 1 )
1690
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1691
    end
1692
    join
1693
 
1694
    // test byte addressing
1695
    read_data`READ_ADDRESS = target_address + 2 ;
1696
    read_data`READ_SEL     = 4'b1100 ;
1697
 
1698
    fork
1699
    begin
1700
        // currently io commands are not supported by behavioral target - transfer should not be completed
1701
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1702
        if (read_status`CYC_ERR !== 1)
1703
        begin
1704
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1705
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1706
            disable main ;
1707
        end
1708
        else test_ok ;
1709
    end
1710
    begin
1711
        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 ) ;
1712
        if ( ok !== 1 )
1713
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1714
    end
1715
    join
1716
 
1717
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1718
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1719
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1720
    if ( ok !== 1 )
1721
    begin
1722
        test_fail("WB Base address register could not be written") ;
1723
        disable main ;
1724
    end
1725
 
1726
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1727
    if ( ok !== 1 )
1728
    begin
1729
        test_fail("WB Address Mask register could not be written") ;
1730
        disable main ;
1731
    end
1732
 
1733
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1734
    if ( ok !== 1 )
1735
    begin
1736
        test_fail("WB Image Control register could not be written") ;
1737
        disable main ;
1738
    end
1739
 
1740
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1741
    write_data`WRITE_DATA    = wmem_data[11] ;
1742
    write_data`WRITE_SEL     = 4'b1000 ;
1743
 
1744
    // handle retries from now on
1745
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1746
 
1747
    fork
1748
    begin
1749
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1750
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1751
        begin
1752
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1753
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1754
            disable main ;
1755
        end
1756
    end
1757
    begin
1758
        // currently IO commands not supported in behavioral models - master abort
1759
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1760
        if ( ok !== 1 )
1761
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1762
        else
1763
            test_ok ;
1764
    end
1765
    join
1766
 
1767
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1768
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1769
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1770
 
1771
    fork
1772
    begin
1773
        // currently io commands are not supported by behavioral target - transfer should not be completed
1774
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1775
        if (read_status`CYC_ERR !== 1)
1776
        begin
1777
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1778
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1779
            disable main ;
1780
        end
1781
        else test_ok ;
1782
    end
1783
    begin
1784
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1785
        if ( ok !== 1 )
1786
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1787
    end
1788
    join
1789
 
1790
    test_name = "DISABLING WB IMAGE" ;
1791
 
1792
    // disable current image
1793
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1794
    if ( ok !== 1 )
1795
    begin
1796
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1797
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1798
        disable main ;
1799
    end
1800
 
1801
    // clear master abort status bit
1802
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1803
    if ( ok !== 1 )
1804
    begin
1805
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1806
        test_fail("write to PCI Device Status register not accepted as expected") ;
1807
        disable main ;
1808
    end
1809
 
1810
end //main
1811
endtask //test_wb_image
1812
 
1813
task wb_slave_errors ;
1814
    reg   [11:0] ctrl_offset ;
1815
    reg   [11:0] ba_offset ;
1816
    reg   [11:0] am_offset ;
1817
    reg   [11:0] ta_offset ;
1818
    reg `WRITE_STIM_TYPE write_data ;
1819
    reg `READ_STIM_TYPE  read_data ;
1820
    reg `READ_RETURN_TYPE read_status ;
1821
 
1822
    reg `WRITE_RETURN_TYPE write_status ;
1823
    reg `WB_TRANSFER_FLAGS write_flags ;
1824
    reg [31:0] temp_val1 ;
1825
    reg [31:0] temp_val2 ;
1826
    reg        ok   ;
1827
    reg [11:0] pci_ctrl_offset ;
1828
    reg [31:0] image_base ;
1829
    reg [31:0] target_address ;
1830
    integer    i ;
1831
    reg skip ;
1832
fork
1833
begin:main
1834
 
1835
    `ifdef GUEST
1836
        skip = 1 ;
1837
    `else
1838
        skip = 0 ;
1839
    `endif
1840
 
1841
    pci_ctrl_offset = 12'h4 ;
1842
 
1843
    // image 1 is used for error testing, since it is always implemented
1844
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1845
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1846
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1847
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1848
 
1849
    target_address  = `BEH_TAR1_MEM_START ;
1850
    image_base      = 0 ;
1851
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1852
 
1853
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1854
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1855
    write_flags                    = 0 ;
1856
    write_flags`INIT_WAITS         = tb_init_waits ;
1857
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1858
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1859
 
1860
    // enable master & target operation
1861
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1862
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1863
    if ( ok !== 1 )
1864
    begin
1865
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1866
        test_fail("PCI Device Control register couldn't be written") ;
1867
        disable no_transaction ;
1868
        disable main ;
1869
    end
1870
 
1871
    // prepare image control register
1872
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1873
    if ( ok !== 1 )
1874
    begin
1875
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1876
        test_fail("WB Image Control register couldn't be written") ;
1877
        disable no_transaction ;
1878
        disable main ;
1879
    end
1880
 
1881
    // prepare base address register
1882
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1883
    if ( ok !== 1 )
1884
    begin
1885
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1886
        test_fail("WB Base Address register couldn't be written") ;
1887
        disable no_transaction ;
1888
        disable main ;
1889
    end
1890
 
1891
    // write address mask register
1892
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1893
    if ( ok !== 1 )
1894
    begin
1895
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1896
        test_fail("WB Address Mask register couldn't be written") ;
1897
        disable no_transaction ;
1898
        disable main ;
1899
    end
1900
 
1901
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1902
 
1903
    skip = 0 ;
1904
 
1905
    // memory mapped image - access is erroneous when address is not alligned
1906
    write_data`WRITE_ADDRESS = target_address + 1 ;
1907
    write_data`WRITE_DATA    = wmem_data[0] ;
1908
    write_data`WRITE_SEL     = 4'hF ;
1909
 
1910
    // handle retries from now on
1911
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1912
 
1913
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1914
 
1915
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1916
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1917
    begin
1918
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1919
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1920
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1921
        disable no_transaction ;
1922
        disable main ;
1923
    end
1924
 
1925
    write_data`WRITE_ADDRESS = target_address + 2 ;
1926
 
1927
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1928
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1929
    begin
1930
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1931
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1932
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1933
        disable no_transaction ;
1934
        disable main ;
1935
 
1936
    end
1937
 
1938
    write_data`WRITE_ADDRESS = target_address + 3 ;
1939
 
1940
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1941
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1942
    begin
1943
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1944
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1945
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1946
        disable no_transaction ;
1947
        disable main ;
1948
    end
1949
 
1950
    test_ok ;
1951
 
1952
    // perform same tests for read accesses
1953
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1954
 
1955
    read_data`READ_ADDRESS  = target_address + 2 ;
1956
    read_data`READ_SEL      = 4'hF ;
1957
    read_data`READ_TAG_STIM = 0 ;
1958
 
1959
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1960
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1961
    begin
1962
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1963
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1964
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
1965
        disable no_transaction ;
1966
        disable main ;
1967
    end
1968
 
1969
    test_ok ;
1970
 
1971
    // prepare write data
1972
    for ( i = 0 ; i < 6 ; i = i + 1 )
1973
    begin
1974
        write_data`WRITE_DATA    = wmem_data[i] ;
1975
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
1976
        write_data`WRITE_SEL     = 4'hF ;
1977
        wishbone_master.blk_write_data[i] = write_data ;
1978
    end
1979
 
1980
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1981
    write_flags`WB_TRANSFER_CAB    = 1 ;
1982
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1983
 
1984
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
1985
    wishbone_master.wb_block_write(write_flags, write_status) ;
1986
 
1987
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1988
    begin
1989
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1990
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1991
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
1992
        disable no_transaction ;
1993
        disable main ;
1994
    end
1995
 
1996
    // prepare read data
1997
    for ( i = 0 ; i < 6 ; i = i + 1 )
1998
    begin
1999
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2000
        read_data`READ_SEL     = 4'hF ;
2001
        wishbone_master.blk_read_data_in[i] = read_data ;
2002
    end
2003
 
2004
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2005
    wishbone_master.wb_block_read(write_flags, read_status) ;
2006
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2007
    begin
2008
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2009
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2010
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2011
        disable no_transaction ;
2012
        disable main ;
2013
    end
2014
 
2015
    test_ok ;
2016
 
2017
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2018
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2019
 
2020
    // map image to IO space
2021
    `ifdef GUEST
2022
        skip = 1 ;
2023
    `endif
2024
 
2025
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2026
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2027
    if ( ok !== 1 )
2028
    begin
2029
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2030
        test_fail("WB Image Base Address register couldn't be written") ;
2031
        disable no_transaction ;
2032
        disable main ;
2033
    end
2034
 
2035
    skip = 0 ;
2036
 
2037
    write_data`WRITE_ADDRESS = target_address ;
2038
    write_data`WRITE_DATA    = wmem_data[0] ;
2039
    write_data`WRITE_SEL     = 4'b1010 ;
2040
 
2041
    // don't handle retries
2042
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2043
 
2044
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2045
 
2046
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2047
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2048
    begin
2049
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2050
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2051
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2052
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2053
        disable no_transaction ;
2054
        disable main ;
2055
    end
2056
 
2057
    write_data`WRITE_ADDRESS = target_address + 1 ;
2058
    write_data`WRITE_SEL     = 4'b0011 ;
2059
 
2060
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2061
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2062
    begin
2063
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2064
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2065
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2066
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2067
        disable no_transaction ;
2068
        disable main ;
2069
    end
2070
 
2071
    write_data`WRITE_SEL     = 4'b1100 ;
2072
 
2073
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2074
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2075
    begin
2076
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2077
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2078
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2079
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2080
        disable no_transaction ;
2081
        disable main ;
2082
    end
2083
 
2084
    write_data`WRITE_ADDRESS = target_address + 2 ;
2085
    write_data`WRITE_SEL     = 4'b0101 ;
2086
 
2087
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2088
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2089
    begin
2090
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2091
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2092
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2093
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2094
        disable no_transaction ;
2095
        disable main ;
2096
    end
2097
 
2098
    write_data`WRITE_SEL     = 4'b1000 ;
2099
 
2100
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2101
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2102
    begin
2103
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2104
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2105
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2106
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2107
        disable no_transaction ;
2108
        disable main ;
2109
    end
2110
 
2111
    write_data`WRITE_ADDRESS = target_address + 3 ;
2112
    write_data`WRITE_SEL     = 4'b1010 ;
2113
 
2114
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2115
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2116
    begin
2117
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2118
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2119
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2120
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2121
        disable no_transaction ;
2122
        disable main ;
2123
    end
2124
 
2125
    write_data`WRITE_SEL     = 4'b0110 ;
2126
 
2127
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2128
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2129
    begin
2130
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2131
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2132
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2133
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2134
        disable no_transaction ;
2135
        disable main ;
2136
    end
2137
 
2138
    test_ok ;
2139
 
2140
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2141
 
2142
    read_data`READ_ADDRESS  = target_address + 3 ;
2143
    read_data`READ_SEL      = 4'hF ;
2144
    read_data`READ_TAG_STIM = 0 ;
2145
 
2146
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2147
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2148
    begin
2149
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2150
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
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 erroneous I/O read as expected") ;
2153
        disable no_transaction ;
2154
        disable main ;
2155
    end
2156
 
2157
    test_ok ;
2158
 
2159
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2160
    // prepare write data
2161
    for ( i = 0 ; i < 6 ; i = i + 1 )
2162
    begin
2163
        write_data`WRITE_DATA    = wmem_data[i] ;
2164
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2165
        write_data`WRITE_SEL     = 4'hF ;
2166
        wishbone_master.blk_write_data[i] = write_data ;
2167
    end
2168
 
2169
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2170
    write_flags`WB_TRANSFER_CAB    = 1 ;
2171
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2172
 
2173
    wishbone_master.wb_block_write(write_flags, write_status) ;
2174
 
2175
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2176
    begin
2177
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2178
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2179
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2180
        disable no_transaction ;
2181
        disable main ;
2182
    end
2183
 
2184
    test_ok ;
2185
 
2186
    test_name = "CAB I/O READ TO WB SLAVE" ;
2187
    // prepare read data
2188
    for ( i = 0 ; i < 6 ; i = i + 1 )
2189
    begin
2190
        read_data`READ_ADDRESS = target_address + 4*i ;
2191
        read_data`READ_SEL     = 4'hF ;
2192
        wishbone_master.blk_read_data_in[i] = read_data ;
2193
    end
2194
 
2195
    wishbone_master.wb_block_read(write_flags, read_status) ;
2196
 
2197
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2198
    begin
2199
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2200
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2201
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2202
        disable no_transaction ;
2203
        disable main ;
2204
    end
2205
 
2206
    test_ok ;
2207
 
2208
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2209
 
2210
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2211
 
2212
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2213
    write_data`WRITE_ADDRESS = target_address + 1 ;
2214
    write_data`WRITE_DATA    = wmem_data[0] ;
2215
    write_data`WRITE_SEL     = 4'hF ;
2216
 
2217
    // don't handle retries
2218
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2219
 
2220
    `ifdef HOST
2221
        `define DO_W_CONF_TEST
2222
        `define DO_R_CONF_TEST
2223
    `else
2224
        `ifdef WB_CNF_IMAGE
2225
             `define DO_R_CONF_TEST
2226
        `endif
2227
    `endif
2228
 
2229
    `ifdef DO_W_CONF_TEST
2230
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2231
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2232
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2233
    begin
2234
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2235
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2236
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2237
        disable no_transaction ;
2238
        disable main ;
2239
    end
2240
 
2241
    write_data`WRITE_ADDRESS = target_address + 2 ;
2242
 
2243
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2244
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2245
    begin
2246
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2247
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2248
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2249
        disable no_transaction ;
2250
        disable main ;
2251
    end
2252
 
2253
    write_data`WRITE_ADDRESS = target_address + 3 ;
2254
 
2255
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2256
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2257
    begin
2258
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2259
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2260
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2261
        disable no_transaction ;
2262
        disable main ;
2263
    end
2264
 
2265
    test_ok ;
2266
    `endif
2267
 
2268
    `ifdef DO_R_CONF_TEST
2269
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2270
    read_data`READ_ADDRESS  = target_address + 3 ;
2271
    read_data`READ_SEL      = 4'hF ;
2272
    read_data`READ_TAG_STIM = 0 ;
2273
 
2274
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2275
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2276
    begin
2277
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2278
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2279
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2280
        disable no_transaction ;
2281
        disable main ;
2282
    end
2283
 
2284
    test_ok ;
2285
    `endif
2286
 
2287
    `ifdef DO_W_CONF_TEST
2288
    // prepare write data
2289
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2290
    for ( i = 0 ; i < 6 ; i = i + 1 )
2291
    begin
2292
        write_data`WRITE_DATA    = wmem_data[i] ;
2293
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2294
        write_data`WRITE_SEL     = 4'hF ;
2295
        wishbone_master.blk_write_data[i] = write_data ;
2296
    end
2297
 
2298
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2299
    write_flags`WB_TRANSFER_CAB    = 1 ;
2300
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2301
 
2302
    wishbone_master.wb_block_write(write_flags, write_status) ;
2303
 
2304
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2305
    begin
2306
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2307
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2308
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2309
        disable no_transaction ;
2310
        disable main ;
2311
    end
2312
    test_ok ;
2313
    `endif
2314
 
2315
    `ifdef DO_R_CONF_TEST
2316
    // prepare read data
2317
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2318
    for ( i = 0 ; i < 6 ; i = i + 1 )
2319
    begin
2320
        read_data`READ_ADDRESS = target_address + 4*i ;
2321
        read_data`READ_SEL     = 4'hF ;
2322
        wishbone_master.blk_read_data_in[i] = read_data ;
2323
    end
2324
 
2325
    wishbone_master.wb_block_read(write_flags, read_status) ;
2326
 
2327
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2328
    begin
2329
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2330
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2331
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2332
        disable no_transaction ;
2333
        disable main ;
2334
    end
2335
    test_ok ;
2336
    `endif
2337
 
2338
    `ifdef GUEST
2339
        skip = 1 ;
2340
    `endif
2341
 
2342
    // disable image
2343
    test_name = "DISABLE IMAGE" ;
2344
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2345
    if ( ok !== 1 )
2346
    begin
2347
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2348
        test_fail("WB Address Mask register couldn't be written") ;
2349
        disable no_transaction ;
2350
        disable main ;
2351
    end
2352
 
2353
    skip = 0 ;
2354
 
2355
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2356
 
2357
    disable no_transaction ;
2358
end
2359
begin:no_transaction
2360
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2361
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2362
    forever
2363
    begin
2364
        @(posedge pci_clock) ;
2365
        if ( skip !== 1 )
2366
        begin
2367
            if ( FRAME !== 1 )
2368
            begin
2369
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2370
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2371
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2372
            end
2373
        end
2374
    end
2375
end
2376
join
2377
endtask //wb_slave_errors
2378
 
2379
task wb_to_pci_error_handling ;
2380
    reg   [11:0] ctrl_offset ;
2381
    reg   [11:0] ba_offset ;
2382
    reg   [11:0] am_offset ;
2383
    reg   [11:0] ta_offset ;
2384
    reg   [11:0] err_cs_offset ;
2385
    reg `WRITE_STIM_TYPE write_data ;
2386
    reg `READ_STIM_TYPE  read_data ;
2387
    reg `READ_RETURN_TYPE read_status ;
2388
 
2389
    reg `WRITE_RETURN_TYPE write_status ;
2390
    reg `WB_TRANSFER_FLAGS write_flags ;
2391
    reg [31:0] temp_val1 ;
2392
    reg [31:0] temp_val2 ;
2393
    reg        ok   ;
2394
    reg [11:0] pci_ctrl_offset ;
2395
    reg [31:0] image_base ;
2396
    reg [31:0] target_address ;
2397
    integer    num_of_trans ;
2398
    integer    current ;
2399
    integer    i ;
2400
begin:main
2401
 
2402
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2403
 
2404
    pci_ctrl_offset = 12'h4 ;
2405
 
2406
    // disable error interrupts and disable error reporting
2407
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2408
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2409
    if ( ok !== 1 )
2410
    begin
2411
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2412
        test_fail("PCI Device Control register couldn't be written") ;
2413
        disable main ;
2414
    end
2415
 
2416
    // image 1 is used for error testing, since it is always implemented
2417
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2418
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2419
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2420
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2421
 
2422
    // set master abort testing address to address that goes out of target's range
2423
    target_address  = `BEH_TAR1_MEM_START ;
2424
    image_base      = 0 ;
2425
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2426
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2427
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2428
 
2429
    write_flags                    = 0 ;
2430
    write_flags`INIT_WAITS         = tb_init_waits ;
2431
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2432
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2433
 
2434
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2435
 
2436
    // enable master & target operation
2437
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2438
    if ( ok !== 1 )
2439
    begin
2440
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2441
        test_fail("PCI Device Control register couldn't be written") ;
2442
        disable main ;
2443
    end
2444
 
2445
    // prepare image control register
2446
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2447
    if ( ok !== 1 )
2448
    begin
2449
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2450
        test_fail("WB Image Control register couldn't be written") ;
2451
        disable main ;
2452
    end
2453
 
2454
    // prepare base address register
2455
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2456
    if ( ok !== 1 )
2457
    begin
2458
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2459
        test_fail("WB Image Base Address register couldn't be written") ;
2460
        disable main ;
2461
    end
2462
 
2463
    // write address mask register
2464
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2465
    if ( ok !== 1 )
2466
    begin
2467
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2468
        test_fail("WB Image Address Mask register couldn't be written") ;
2469
        disable main ;
2470
    end
2471
 
2472
    // disable error reporting
2473
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2474
    if ( ~ok )
2475
    begin
2476
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2477
        test_fail("WB Error Control and Status register couldn't be written") ;
2478
        disable main ;
2479
    end
2480
 
2481
    // perform two writes - one to error address and one to OK address
2482
    // prepare write buffer
2483
 
2484
    write_data`WRITE_ADDRESS = target_address ;
2485
    write_data`WRITE_DATA    = wmem_data[100] ;
2486
    write_data`WRITE_SEL     = 4'hF ;
2487
 
2488
    wishbone_master.blk_write_data[0] = write_data ;
2489
 
2490
    write_flags`WB_TRANSFER_SIZE = 2 ;
2491
 
2492
    // don't handle retries
2493
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2494
    write_flags`WB_TRANSFER_CAB    = 0 ;
2495
 
2496
    $display("Introducing master abort error on single WB to PCI write!") ;
2497
 
2498
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2499
    // first disable target 1
2500
 
2501 45 mihad
    configuration_cycle_write(0,                        // bus number
2502
                              `TAR1_IDSEL_INDEX - 11,   // device number
2503
                              0,                        // function number
2504
                              1,                        // register number
2505
                              0,                        // type of configuration cycle
2506
                              4'b0001,                  // byte enables
2507
                              32'h0000_0000             // data
2508 15 mihad
                             ) ;
2509
 
2510
    fork
2511
    begin
2512
        // start no response monitor in parallel with writes
2513
        musnt_respond(ok) ;
2514
        if ( ok !== 1 )
2515
        begin
2516
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2517
            $display("Testbench is configured wrong!") ;
2518
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2519
        end
2520
        else
2521
            test_ok ;
2522
    end
2523
    begin
2524
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2525
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2526
       begin
2527
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2528
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2529
           test_fail("WB Slave state machine failed to post single memory write");
2530
           disable main ;
2531
       end
2532
    end
2533
    join
2534
 
2535
    /*// read data from second write
2536
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2537
    read_data`READ_ADDRESS = target_address ;
2538
    read_data`READ_SEL     = 4'hF ;
2539
    read_data`READ_TAG_STIM = 0 ;
2540
 
2541
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2542
 
2543
    if ( read_status`READ_DATA !== wmem_data[101] )
2544
    begin
2545
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2546
    end
2547
    */
2548
 
2549
    // read error status register - no errors should be reported since reporting was disabled
2550
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2551
 
2552
    @(posedge pci_clock) ;
2553
    // wait for two WB clocks for synchronization to be finished
2554
    repeat (2)
2555
        @(posedge wb_clock) ;
2556
 
2557
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2558
    if ( temp_val1[8] !== 0 )
2559
    begin
2560
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2561
        $display("Error reporting was disabled, but error was reported anyway!") ;
2562
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2563
        disable main ;
2564
    end
2565
    test_ok ;
2566
 
2567
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2568
    // check for interrupts - there should be no interrupt requests active
2569
    `ifdef HOST
2570
        repeat(4)
2571
            @(posedge wb_clock) ;
2572
 
2573
        if ( INT_O !== 0 )
2574
        begin
2575
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2576
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2577
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2578
        end
2579
        else
2580
            test_ok ;
2581
    `else
2582
    `ifdef GUEST
2583
        repeat( 4 )
2584
            @(posedge pci_clock) ;
2585
 
2586
        if ( INTA !== 1 )
2587
        begin
2588
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2589
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2590
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2591
        end
2592
        else
2593
            test_ok ;
2594
    `endif
2595
    `endif
2596
 
2597
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2598
    // check PCI status register
2599
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2600
    if ( temp_val1[29] !== 1 )
2601
    begin
2602
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2603
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2604
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2605
    end
2606
    else
2607
        test_ok ;
2608
 
2609
    // clear
2610
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2611
 
2612
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2613
 
2614
    $display("Introducing master abort error to CAB write!") ;
2615
    // now enable error reporting mechanism
2616
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2617
    // enable error interrupts
2618
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2619
 
2620
    // configure flags for CAB transfer
2621
    write_flags`WB_TRANSFER_CAB = 1 ;
2622
    write_flags`WB_TRANSFER_SIZE = 3 ;
2623
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2624
 
2625
    // prepare data for erroneous write
2626
    for ( i = 0 ; i < 3 ; i = i + 1 )
2627
    begin
2628
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2629
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2630
        write_data`WRITE_SEL     = 4'hF ;
2631
        wishbone_master.blk_write_data[i] = write_data ;
2632
    end
2633
 
2634
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2635
    fork
2636
    begin
2637
        wishbone_master.wb_block_write(write_flags, write_status) ;
2638
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2639
        begin
2640
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2641
            $display("Complete burst write through WB slave didn't succeed!") ;
2642
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2643
            disable main ;
2644
        end
2645
    end
2646
    begin
2647
        musnt_respond(ok) ;
2648
        if ( ok !== 1 )
2649
        begin
2650
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2651
            $display("Testbench is configured wrong!") ;
2652
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2653
        end
2654
        else
2655
            test_ok ;
2656
    end
2657
    join
2658
 
2659
    // check error status address, data, byte enables and bus command
2660
    // error status bit is signalled on PCI clock and synchronized to WB clock
2661
    // wait one PCI clock cycle
2662
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2663
    ok = 1 ;
2664
    @(posedge pci_clock) ;
2665
 
2666
    // wait for two WB clocks for synchronization to be finished
2667
    repeat (2)
2668
        @(posedge wb_clock) ;
2669
 
2670
    // read registers
2671
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2672
    if ( temp_val1[8] !== 1 )
2673
    begin
2674
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2675
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2676
        ok = 0 ;
2677
    end
2678
 
2679
    if ( temp_val1[9] !== 1 )
2680
    begin
2681
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2682
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2683
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2684
        ok = 0 ;
2685
    end
2686
 
2687
    if ( temp_val1[31:28] !== 0 )
2688
    begin
2689
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2690
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2691
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2692
        ok = 0 ;
2693
    end
2694
 
2695
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2696
    begin
2697
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2698
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2699
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2700
        ok = 0 ;
2701
    end
2702
 
2703
    // read error address register
2704
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2705
    if ( temp_val1 !== target_address )
2706
    begin
2707
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2708
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2709
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2710
        ok = 0 ;
2711
    end
2712
 
2713
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2714
    if ( temp_val1 !== wmem_data[110] )
2715
    begin
2716
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2717
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2718
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2719
        ok = 0 ;
2720
    end
2721
 
2722
    // check PCI status register
2723
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2724
    if ( temp_val1[29] !== 1 )
2725
    begin
2726
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2727
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2728
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2729
        ok = 0 ;
2730
    end
2731
 
2732
    if ( temp_val1[28] !== 0 )
2733
    begin
2734
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2735
        $display("Received Target Abort bit was set for no reason!") ;
2736
        test_fail("Received Target Abort bit was set for no reason") ;
2737
        ok = 0 ;
2738
    end
2739
 
2740
    if ( ok )
2741
        test_ok ;
2742
 
2743
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2744
 
2745
    // clear error status bit
2746
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2747
 
2748
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2749
 
2750
    ok = 1 ;
2751
 
2752
    `ifdef HOST
2753
        repeat(4)
2754
        @(posedge wb_clock) ;
2755
        if ( INT_O !== 1 )
2756
        begin
2757
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2758
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2759
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2760
            ok = 0 ;
2761
        end
2762
    `else
2763
    `ifdef GUEST
2764
        repeat(4)
2765
        @(posedge pci_clock) ;
2766
        if ( INTA !== 0 )
2767
        begin
2768
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2769
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2770
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2771
            ok = 0 ;
2772
        end
2773
    `endif
2774
    `endif
2775
 
2776
    // read interrupt status register
2777
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2778
    if ( temp_val1 !== 32'h0000_0002 )
2779
    begin
2780
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2781
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2782
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2783
        test_fail("Interrupt Status register returned wrong value") ;
2784
        ok = 0 ;
2785
    end
2786
 
2787
    if ( ok )
2788
        test_ok ;
2789
    // clear interrupt status bits
2790
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2791
 
2792
    ok = 1 ;
2793
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2794
    // wait for two clock cycles before checking interrupt request deassertion
2795
    `ifdef HOST
2796
        repeat (4)
2797
            @(posedge wb_clock) ;
2798
 
2799
        if ( INT_O !== 0 )
2800
        begin
2801
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2802
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2803
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2804
            ok = 0 ;
2805
        end
2806
    `else
2807
    `ifdef GUEST
2808
        repeat (4)
2809
            @(posedge pci_clock) ;
2810
 
2811
        if ( INTA !== 1 )
2812
        begin
2813
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2814
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2815
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2816
            ok = 0 ;
2817
        end
2818
    `endif
2819
    `endif
2820
 
2821
    if ( ok )
2822
        test_ok ;
2823
 
2824
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2825
    ok = 1 ;
2826
    // enable target
2827 45 mihad
    configuration_cycle_write(0,                        // bus number
2828
                              `TAR1_IDSEL_INDEX - 11,   // device number
2829
                              0,                        // function number
2830
                              1,                        // register number
2831
                              0,                        // type of configuration cycle
2832
                              4'b0001,                  // byte enables
2833
                              32'h0000_0007             // data
2834 15 mihad
                             ) ;
2835
    // prepare data for ok write
2836
    for ( i = 0 ; i < 3 ; i = i + 1 )
2837
    begin
2838
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2839
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2840
        write_data`WRITE_SEL     = 4'hF ;
2841
        wishbone_master.blk_write_data[i] = write_data ;
2842
    end
2843
 
2844
    wishbone_master.wb_block_write(write_flags, write_status) ;
2845
 
2846
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2847
    begin
2848
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2849
        $display("Complete burst write through WB slave didn't succeed!") ;
2850
        test_fail("WB Slave state machine failed to post CAB write") ;
2851
        disable main ;
2852
    end
2853
 
2854
    // do a read
2855
    for ( i = 0 ; i < 3 ; i = i + 1 )
2856
    begin
2857
        read_data`READ_ADDRESS = target_address + 4*i ;
2858
        read_data`READ_SEL     = 4'hF ;
2859
        wishbone_master.blk_read_data_in[i] = read_data ;
2860
    end
2861
 
2862
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2863
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2864
    write_flags`WB_TRANSFER_CAB    = 1 ;
2865
 
2866
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2867
 
2868
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2869
    begin
2870
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2871
        $display("Complete burst read through WB slave didn't succeed!") ;
2872
        test_fail("Delayed CAB write was not processed as expected") ;
2873
        disable main ;
2874
    end
2875
 
2876
    for ( i = 0 ; i < 3 ; i = i + 1 )
2877
    begin
2878
        read_status = wishbone_master.blk_read_data_out[i] ;
2879
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2880
        begin
2881
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2882
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2883
        end
2884
    end
2885
 
2886
    $display("Introducing master abort error to single read!") ;
2887
    // disable target
2888 45 mihad
    configuration_cycle_write(0,                        // bus number
2889
                              `TAR1_IDSEL_INDEX - 11,   // device number
2890
                              0,                        // function number
2891
                              1,                        // register number
2892
                              0,                        // type of configuration cycle
2893
                              4'b0001,                  // byte enables
2894
                              32'h0000_0000             // data
2895 15 mihad
                             ) ;
2896
    // set read data
2897
    read_data`READ_ADDRESS = target_address ;
2898
    read_data`READ_SEL     = 4'hF ;
2899
 
2900
    // enable automatic retry handling
2901
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2902
    write_flags`WB_TRANSFER_CAB    = 0 ;
2903
 
2904
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2905
    fork
2906
    begin
2907
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2908
    end
2909
    begin
2910
        musnt_respond(ok) ;
2911
        if ( ok !== 1 )
2912
        begin
2913
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2914
            $display("Testbench is configured wrong!") ;
2915
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2916
        end
2917
    end
2918
    join
2919
 
2920
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2921
    begin
2922
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2923
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2924
        $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) ;
2925
        test_fail("read didn't finish on WB bus as expected") ;
2926
        disable main ;
2927
    end
2928
 
2929
    test_ok ;
2930
 
2931
 
2932
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2933
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2934
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2935
    if ( temp_val1[8] !== 0 )
2936
    begin
2937
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2938
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2939
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2940
    end
2941
    else
2942
        test_ok ;
2943
 
2944
    // now check normal read operation
2945 45 mihad
    configuration_cycle_write(0,                        // bus number
2946
                              `TAR1_IDSEL_INDEX - 11,   // device number
2947
                              0,                        // function number
2948
                              1,                        // register number
2949
                              0,                        // type of configuration cycle
2950
                              4'b0001,                  // byte enables
2951
                              32'h0000_0007             // data
2952 15 mihad
                             ) ;
2953
 
2954 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
2955 15 mihad
    read_data`READ_ADDRESS = target_address ;
2956
    read_data`READ_SEL     = 4'hF ;
2957
 
2958
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2959
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2960
    begin
2961
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2962
        $display("WB slave failed to process single read!") ;
2963
        $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) ;
2964
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
2965
        disable main ;
2966
    end
2967
 
2968
    if ( read_status`READ_DATA !== wmem_data[113] )
2969
    begin
2970
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
2971
        test_fail("when read finished on WB bus, wrong data was provided") ;
2972
    end
2973
    else
2974
        test_ok ;
2975
 
2976
    // check PCI status register
2977 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
2978 15 mihad
    ok = 1 ;
2979
 
2980
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2981
    if ( temp_val1[29] !== 1 )
2982
    begin
2983
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2984
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
2985
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
2986
        ok = 0 ;
2987
    end
2988
 
2989
    if ( temp_val1[28] !== 0 )
2990
    begin
2991
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2992
        $display("Received Target Abort bit was set for no reason!") ;
2993
        test_fail("Received Target Abort bit was set for no reason") ;
2994
        ok = 0 ;
2995
    end
2996
    if ( ok )
2997
        test_ok ;
2998
 
2999
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3000
 
3001
    $display("Introducing master abort error to CAB read!") ;
3002
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3003
 
3004 45 mihad
    configuration_cycle_write(0,                        // bus number
3005
                              `TAR1_IDSEL_INDEX - 11,   // device number
3006
                              0,                        // function number
3007
                              1,                        // register number
3008
                              0,                        // type of configuration cycle
3009
                              4'b0001,                  // byte enables
3010
                              32'h0000_0000             // data
3011 15 mihad
                             ) ;
3012
 
3013
    for ( i = 0 ; i < 3 ; i = i + 1 )
3014
    begin
3015
        read_data`READ_ADDRESS = target_address + 4*i ;
3016
        read_data`READ_SEL     = 4'hF ;
3017
        wishbone_master.blk_read_data_in[i] = read_data ;
3018
    end
3019
 
3020
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3021
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3022
    write_flags`WB_TRANSFER_CAB    = 1 ;
3023
 
3024
    fork
3025
    begin
3026
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3027
    end
3028
    begin
3029
        musnt_respond(ok) ;
3030
        if ( ok !== 1 )
3031
        begin
3032
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3033
            $display("Testbench is configured wrong!") ;
3034
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3035
        end
3036
    end
3037
    join
3038
 
3039
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3040
    begin
3041
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3042
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3043
        $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) ;
3044
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3045
        disable main ;
3046
    end
3047
    else
3048
        test_ok ;
3049
 
3050
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3051
    ok = 1 ;
3052
    // check PCI status register
3053
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3054
    if ( temp_val1[29] !== 1 )
3055
    begin
3056
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3057
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3058
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3059
        ok = 0 ;
3060
    end
3061
 
3062
    if ( temp_val1[28] !== 0 )
3063
    begin
3064
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3065
        $display("Received Target Abort bit was set for no reason!") ;
3066
        test_fail("Received Target Abort bit was set for no reason") ;
3067
        ok = 0 ;
3068
    end
3069
 
3070
    if ( ok )
3071
        test_ok ;
3072
 
3073
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3074
 
3075
    $display("Introducing target abort termination to single write!") ;
3076
 
3077
    // disable error reporting and interrupts
3078
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3079
 
3080 45 mihad
    configuration_cycle_write(0,                        // bus number
3081
                              `TAR1_IDSEL_INDEX - 11,   // device number
3082
                              0,                        // function number
3083
                              1,                        // register number
3084
                              0,                        // type of configuration cycle
3085
                              4'b0001,                  // byte enables
3086
                              32'h0000_0007             // data
3087 15 mihad
                             ) ;
3088
 
3089
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3090
    if ( ok !== 1 )
3091
    begin
3092
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3093
        test_fail("WB Error Control and Status register couldn't be written to") ;
3094
        disable main ;
3095
    end
3096
 
3097
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3098
    if ( ok !== 1 )
3099
    begin
3100
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3101
        test_fail("Interrupt Control register couldn't be written to") ;
3102
        disable main ;
3103
    end
3104
 
3105
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3106
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3107
 
3108
    write_data`WRITE_ADDRESS = target_address ;
3109
    write_data`WRITE_DATA    = wmem_data[0] ;
3110
    write_data`WRITE_SEL     = 4'hF ;
3111
 
3112
    wishbone_master.blk_write_data[0] = write_data ;
3113
 
3114
    write_data`WRITE_ADDRESS = target_address + 4;
3115
    write_data`WRITE_DATA    = wmem_data[1] ;
3116
    write_data`WRITE_SEL     = 4'hF ;
3117
 
3118
    wishbone_master.blk_write_data[1] = write_data ;
3119
 
3120
    write_flags`WB_TRANSFER_SIZE = 2 ;
3121
 
3122
    // don't handle retries
3123
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3124
    write_flags`WB_TRANSFER_CAB    = 0 ;
3125
 
3126
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3127
    fork
3128
    begin
3129
        wishbone_master.wb_block_write(write_flags, write_status) ;
3130
 
3131
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3132
        begin
3133
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3134
            $display("Image writes were not accepted as expected!") ;
3135
            $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) ;
3136
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3137
            disable main ;
3138
        end
3139
 
3140
        // read data back to see, if it was written OK
3141
        read_data`READ_ADDRESS         = target_address + 4;
3142
        read_data`READ_SEL             = 4'hF ;
3143
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3144
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3145
    end
3146
    begin
3147
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3148
        if ( ok !== 1 )
3149
        begin
3150
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3151
        end
3152
        else
3153
            test_ok ;
3154
 
3155
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3156
 
3157
        // when first transaction finishes - enable normal target response!
3158
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3159
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3160
 
3161
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3162
        if ( ok !== 1 )
3163
        begin
3164
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3165
        end
3166
        else
3167
            test_ok ;
3168
 
3169
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3170
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3171
        if ( ok !== 1 )
3172
        begin
3173
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3174
        end
3175
    end
3176
    join
3177
 
3178
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3179
    begin
3180
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3181
        $display("Bridge failed to process single read after target abort terminated write!") ;
3182
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3183
        disable main ;
3184
    end
3185
 
3186
    if ( read_status`READ_DATA !== wmem_data[1] )
3187
    begin
3188
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3189
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3190
    end
3191
    else
3192
        test_ok ;
3193
 
3194
    // check interrupt and error statuses!
3195
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3196
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3197
    if ( temp_val1[8] !== 0 )
3198
    begin
3199
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3200
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3201
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3202
    end
3203
    else
3204
        test_ok ;
3205
 
3206
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3207
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3208
    if ( temp_val1[1] !== 0 )
3209
    begin
3210
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3211
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3212
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3213
    end
3214
    else
3215
        test_ok ;
3216
 
3217
    // check PCI status register
3218
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3219
    ok = 1 ;
3220
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3221
    if ( temp_val1[29] !== 0 )
3222
    begin
3223
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3224
        $display("Received Master Abort bit was set with no reason!") ;
3225
        test_fail("Received Master Abort bit was set with no reason") ;
3226
        ok = 0 ;
3227
    end
3228
 
3229
    if ( temp_val1[28] !== 1 )
3230
    begin
3231
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3232
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3233
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3234
        ok = 0 ;
3235
    end
3236
 
3237
    if ( ok )
3238
        test_ok ;
3239
 
3240
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3241
 
3242
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3243
 
3244
    $display("Introducing target abort termination to CAB write!") ;
3245
    // enable error reporting mechanism
3246
 
3247
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3248
    if ( ok !== 1 )
3249
    begin
3250
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3251
        test_fail("WB Error Control and Status register could not be written to") ;
3252
        disable main ;
3253
    end
3254
 
3255
    for ( i = 0 ; i < 3 ; i = i + 1 )
3256
    begin
3257
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3258
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3259
        write_data`WRITE_SEL     = 4'b1010 ;
3260
        wishbone_master.blk_write_data[i] = write_data ;
3261
    end
3262
 
3263
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3264
    write_flags`WB_TRANSFER_CAB    = 1 ;
3265
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3266
 
3267
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3268
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3269
 
3270
    fork
3271
    begin
3272
        wishbone_master.wb_block_write(write_flags, write_status) ;
3273
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3274
        begin
3275
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3276
            $display("Bridge failed to process complete CAB write!") ;
3277
            test_fail("bridge failed to post CAB Memory Write") ;
3278
            disable main ;
3279
        end
3280
    end
3281
    begin
3282
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3283
        if ( ok !== 1 )
3284
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3285
        else
3286
            test_ok ;
3287
    end
3288
    join
3289
 
3290
    // check statuses and data from error
3291
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3292
    ok = 1 ;
3293
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3294
    if ( temp_val1[8] !== 1 )
3295
    begin
3296
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3297
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3298
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3299
        ok = 0 ;
3300
    end
3301
 
3302
    if ( temp_val1[9] !== 0 )
3303
    begin
3304
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3305
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3306
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3307
        ok = 0 ;
3308
    end
3309
 
3310
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3311
    begin
3312
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3313
        $display("Value in W_ERR_CS register was wrong!") ;
3314
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3315
        test_fail("BE Field didn't provided expected value") ;
3316
        ok = 0 ;
3317
    end
3318
 
3319
    if ( ok )
3320
        test_ok ;
3321
 
3322
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3323
    ok = 1 ;
3324
    // check erroneous address and data
3325
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3326
    if ( temp_val1 !== (target_address + 8) )
3327
    begin
3328
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3329
        $display("Value in W_ERR_ADDR register was wrong!") ;
3330
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3331
        test_fail("Value in WB Erroneous Address register was wrong") ;
3332
        ok = 0 ;
3333
    end
3334
 
3335
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3336
    if ( temp_val1 !== wmem_data[120] )
3337
    begin
3338
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3339
        $display("Value in W_ERR_DATA register was wrong!") ;
3340
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3341
        test_fail("Value in WB Erroneous Data register was wrong") ;
3342
        ok = 0 ;
3343
    end
3344
 
3345
    if ( ok )
3346
        test_ok ;
3347
 
3348
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3349
    ok = 1 ;
3350
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3351
    if ( temp_val1[29] !== 0 )
3352
    begin
3353
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3354
        $display("Received Master Abort bit was set with no reason!") ;
3355
        test_fail("Received Master Abort bit was set for no reason") ;
3356
        ok = 0 ;
3357
    end
3358
 
3359
    if ( temp_val1[28] !== 1 )
3360
    begin
3361
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3362
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3363
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3364
        ok = 0 ;
3365
    end
3366
 
3367
    if ( ok )
3368
        test_ok ;
3369
 
3370
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3371
 
3372
    // clear error status bit and enable error interrupts
3373
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3374
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3375
 
3376
    // check if error bit was cleared
3377
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3378
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3379
    if ( temp_val1[8] !== 0 )
3380
    begin
3381
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3382
        $display("Error bit was not cleared even though one was written to its location!") ;
3383
        test_fail("Error bit was not cleared even though one was written to its location") ;
3384
    end
3385
 
3386
    // repeat same write with different target configuration
3387
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3388
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3389
 
3390
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3391
    fork
3392
    begin
3393
        write_flags`WB_TRANSFER_SIZE = 2 ;
3394
        wishbone_master.wb_block_write(write_flags, write_status) ;
3395
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3396
        begin
3397
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3398
            $display("Bridge failed to process complete CAB write!") ;
3399
            test_fail("bridge failed to post CAB Memory Write") ;
3400
            disable main ;
3401
        end
3402
 
3403
        write_flags`WB_TRANSFER_SIZE = 3 ;
3404
        wishbone_master.wb_block_write(write_flags, write_status) ;
3405
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3406
        begin
3407
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3408
            $display("Bridge failed to process complete CAB write!") ;
3409
            test_fail("bridge failed to post CAB Memory Write") ;
3410
            disable main ;
3411
        end
3412
    end
3413
    begin
3414
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3415
        if ( ok !== 1 )
3416
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3417
        else
3418
        begin
3419
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3420
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3421
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3422
            if ( ok !== 1 )
3423
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3424
            else
3425
                test_ok ;
3426
        end
3427
    end
3428
    join
3429
 
3430
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3431
    ok = 1 ;
3432
    // check statuses and data from error
3433
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3434
    if ( temp_val1[8] !== 1 )
3435
    begin
3436
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3437
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3438
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3439
        ok = 0 ;
3440
    end
3441
 
3442
    if ( temp_val1[9] !== 0 )
3443
    begin
3444
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3445
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3446
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3447
        ok = 0 ;
3448
    end
3449
 
3450
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3451
    begin
3452
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3453
        $display("Value in W_ERR_CS register was wrong!") ;
3454
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3455
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3456
        ok = 0 ;
3457
    end
3458
 
3459
    if ( ok )
3460
        test_ok ;
3461
 
3462
    // check erroneous address and data
3463
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3464
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3465
    ok = 1 ;
3466
    if ( temp_val1 !== (target_address + 8 + 4) )
3467
    begin
3468
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3469
        $display("Value in W_ERR_ADDR register was wrong!") ;
3470
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3471
        test_fail("Value in WB Erroneous Address register was wrong") ;
3472
        ok = 0 ;
3473
 
3474
    end
3475
 
3476
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3477
    if ( temp_val1 !== wmem_data[121] )
3478
    begin
3479
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3480
        $display("Value in W_ERR_DATA register was wrong!") ;
3481
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3482
        test_fail("Value in WB Erroneous Data register was wrong") ;
3483
        ok = 0 ;
3484
    end
3485
 
3486
    if ( ok )
3487
        test_ok ;
3488
 
3489
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3490
    `ifdef HOST
3491
        repeat(4)
3492
            @(posedge wb_clock) ;
3493
        if ( INT_O !== 1 )
3494
        begin
3495
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3496
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3497
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3498
        end
3499
        else
3500
            test_ok ;
3501
    `else
3502
    `ifdef GUEST
3503
        repeat(4)
3504
            @(posedge pci_clock) ;
3505
        if ( INTA !== 0 )
3506
        begin
3507
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3508
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3509
            test_fail("interrupt request was not presented on PCI bus") ;
3510
        end
3511
        else
3512
            test_ok ;
3513
    `endif
3514
    `endif
3515
 
3516
    // read interrupt status register
3517
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3518
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3519
    if ( temp_val1[1] !== 1 )
3520
    begin
3521
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3522
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3523
        test_fail("Expected Interrupt status bit wasn't set") ;
3524
    end
3525
 
3526
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3527
 
3528
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3529
    ok = 1 ;
3530
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3531
    if ( temp_val1[29] !== 0 )
3532
    begin
3533
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3534
        $display("Received Master Abort bit was set with no reason!") ;
3535
        test_fail("Received Master Abort bit was set with no reason") ;
3536
        ok = 0 ;
3537
    end
3538
 
3539
    if ( temp_val1[28] !== 1 )
3540
    begin
3541
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3542
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3543
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3544
        ok = 0 ;
3545
    end
3546
 
3547
    if ( ok )
3548
        test_ok ;
3549
 
3550
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3551
 
3552
    // clear interrupts and errors
3553
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3554
    repeat( 3 )
3555
        @(posedge pci_clock) ;
3556
 
3557
    repeat( 2 )
3558
        @(posedge wb_clock) ;
3559
 
3560
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3561
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3562
    if ( temp_val1[1] !== 0 )
3563
    begin
3564
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3565
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3566
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3567
    end
3568
    else
3569
        test_ok ;
3570
 
3571
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3572
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3573
    if ( temp_val1[8] !== 0 )
3574
    begin
3575
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3576
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3577
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3578
    end
3579
 
3580
 
3581
    $display("Introducing Target Abort error to single read!") ;
3582
    // set read data
3583
    read_data`READ_ADDRESS = target_address + 8 ;
3584
    read_data`READ_SEL     = 4'hF ;
3585
 
3586
    // enable automatic retry handling
3587
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3588
    write_flags`WB_TRANSFER_CAB    = 0 ;
3589
 
3590
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3591
 
3592
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3593
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3594
 
3595
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3596
 
3597
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3598
    begin
3599
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3600
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3601
        $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) ;
3602
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3603
        disable main ;
3604
    end
3605
    else
3606
        test_ok ;
3607
 
3608
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3609
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3610
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3611
    if ( temp_val1[8] !== 0 )
3612
    begin
3613
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3614
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3615
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3616
    end
3617
    else
3618
        test_ok ;
3619
 
3620
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3621
    ok = 1 ;
3622
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3623
    if ( temp_val1[29] !== 0 )
3624
    begin
3625
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3626
        $display("Received Master Abort bit was set with no reason!") ;
3627
        test_fail("Received Master Abort bit was set with no reason") ;
3628
        ok = 0 ;
3629
    end
3630
 
3631
    if ( temp_val1[28] !== 1 )
3632
    begin
3633
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3634
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3635
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3636
        ok = 0 ;
3637
    end
3638
 
3639
    if ( ok )
3640
        test_ok ;
3641
 
3642
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3643
 
3644
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3645
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3646
    if ( temp_val1[1] !== 0 )
3647
    begin
3648
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3649
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3650
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3651
    end
3652
    else
3653
        test_ok ;
3654
 
3655
    $display("Introducing Target Abort error to CAB read!") ;
3656
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3657
 
3658
    for ( i = 0 ; i < 4 ; i = i + 1 )
3659
    begin
3660
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3661
        read_data`READ_SEL     = 4'b1010 ;
3662
        wishbone_master.blk_read_data_in[i] = read_data ;
3663
    end
3664
 
3665
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3666
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3667
    write_flags`WB_TRANSFER_CAB    = 1 ;
3668
 
3669
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3670
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3671
 
3672
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3673
 
3674
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3675
    begin
3676
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3677
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3678
        $display("Actuals: Data transfered: %d, slave response: ACK = %b, RTY = %b, ERR = %b ", read_status`CYC_ACTUAL_TRANSFER, read_status`CYC_ACK, read_status`CYC_RTY, read_status`CYC_ERR) ;
3679
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3680
        disable main ;
3681
    end
3682
 
3683
    read_status = wishbone_master.blk_read_data_out[0] ;
3684
    temp_val1 = read_status`READ_DATA ;
3685
    temp_val2 = wmem_data[120] ;
3686
 
3687
    // last write to this address was with only two byte enables - check only those
3688
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3689
    begin
3690
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3691
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3692
    end
3693
    else
3694
        test_ok ;
3695
 
3696
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3697
    ok = 1 ;
3698
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3699
    if ( temp_val1[29] !== 0 )
3700
    begin
3701
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3702
        $display("Received Master Abort bit was set with no reason!") ;
3703
        test_fail("Received Master Abort bit was set with no reason") ;
3704
        ok = 0 ;
3705
    end
3706
 
3707
    if ( temp_val1[28] !== 1 )
3708
    begin
3709
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3710
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3711
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3712
        ok = 0 ;
3713
    end
3714
 
3715
    if ( ok )
3716
       test_ok ;
3717
 
3718
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3719
 
3720
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3721
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3722
 
3723
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3724
    for ( i = 0 ; i < 3 ; i = i + 1 )
3725
    begin
3726
        read_data`READ_ADDRESS = target_address + 4*i ;
3727
        read_data`READ_SEL     = 4'b1111 ;
3728
        wishbone_master.blk_read_data_in[i] = read_data ;
3729
    end
3730
 
3731
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3732
 
3733
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3734
 
3735
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3736
    begin
3737
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3738
        $display("Complete burst read through WB slave didn't succeed!") ;
3739
        test_fail("bridge didn't process Burst Read in an expected way") ;
3740
        disable main ;
3741
    end
3742
    else
3743
        test_ok ;
3744
 
3745
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3746
 
3747
    for ( i = 0 ; i < 3 ; i = i + 1 )
3748
    begin
3749
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3750
        read_data`READ_SEL     = 4'b1111 ;
3751
        wishbone_master.blk_read_data_in[i] = read_data ;
3752
    end
3753
 
3754
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3755
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3756
    write_flags`WB_TRANSFER_CAB    = 1 ;
3757
 
3758
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3759
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3760
 
3761
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3762
 
3763
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3764
    begin
3765
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3766
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3767
        $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) ;
3768
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3769
        disable main ;
3770
    end
3771
 
3772
    for ( i = 0 ; i < 3 ; i = i + 1 )
3773
    begin
3774
        ok = 1 ;
3775
        read_status = wishbone_master.blk_read_data_out[i] ;
3776
        temp_val1 = read_status`READ_DATA ;
3777
        temp_val2 = wmem_data[120 + i] ;
3778
 
3779
        // last write to this address was with only two byte enables - check only those
3780
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3781
        begin
3782
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3783
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3784
            ok = 0 ;
3785
        end
3786
    end
3787
 
3788
    if ( ok )
3789
        test_ok ;
3790
 
3791
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3792
    ok = 1 ;
3793
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3794
    if ( temp_val1[29] !== 0 )
3795
    begin
3796
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3797
        $display("Received Master Abort bit was set with no reason!") ;
3798
        test_fail("Received Master Abort bit was set with no reason") ;
3799
        ok = 0 ;
3800
    end
3801
 
3802
    if ( temp_val1[28] !== 1 )
3803
    begin
3804
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3805
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3806
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3807
        ok = 0 ;
3808
    end
3809
 
3810
    if ( ok )
3811
       test_ok ;
3812
 
3813
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3814
 
3815
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3816
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3817
 
3818
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3819
    for ( i = 0 ; i < 3 ; i = i + 1 )
3820
    begin
3821
        read_data`READ_ADDRESS = target_address + 4*i ;
3822
        read_data`READ_SEL     = 4'b1111 ;
3823
        wishbone_master.blk_read_data_in[i] = read_data ;
3824
    end
3825
 
3826
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3827
 
3828
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3829
 
3830
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3831
    begin
3832
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3833
        $display("Complete burst read through WB slave didn't succeed!") ;
3834
        test_fail("bridge didn't process Burst Read in an expected way") ;
3835
        disable main ;
3836
    end
3837
    else
3838
        test_ok ;
3839
 
3840
    // test error on IO write
3841
    // change base address
3842
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3843
    write_data`WRITE_SEL     = 4'b0101 ;
3844
    write_data`WRITE_ADDRESS = target_address ;
3845
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3846
 
3847
    write_flags`WB_TRANSFER_CAB    = 0 ;
3848
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3849
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3850
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3851
    fork
3852
    begin
3853
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3854
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3855
        begin
3856
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3857
            $display("WB slave failed to accept IO write!") ;
3858
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3859
            disable main ;
3860
        end
3861
    end
3862
    begin
3863
        musnt_respond(ok) ;
3864
        if ( ok !== 1 )
3865
        begin
3866
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3867
            $display("Testbench is configured wrong!") ;
3868
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3869
        end
3870
        else
3871
            test_ok ;
3872
    end
3873
    join
3874
 
3875
    // check statuses and everything else
3876
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3877
    ok = 1 ;
3878
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3879
    if ( temp_val1[8] !== 1 )
3880
    begin
3881
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3882
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3883
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3884
        ok = 0 ;
3885
    end
3886
 
3887
    if ( temp_val1[9] !== 1 )
3888
    begin
3889
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3890
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3891
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3892
        ok = 0 ;
3893
    end
3894
 
3895
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3896
    begin
3897
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3898
        $display("Value in W_ERR_CS register was wrong!") ;
3899
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3900
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3901
        ok = 0 ;
3902
    end
3903
 
3904
    if ( ok )
3905
        test_ok ;
3906
 
3907
    // check erroneous address and data
3908
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3909
    ok = 1 ;
3910
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3911
    if ( temp_val1 !== target_address )
3912
    begin
3913
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3914
        $display("Value in W_ERR_ADDR register was wrong!") ;
3915
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3916
        test_fail("WB Erroneous Address register didn't provide right value") ;
3917
        ok = 0 ;
3918
    end
3919
 
3920
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3921
    if ( temp_val1 !== 32'hAAAA_AAAA )
3922
    begin
3923
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3924
        $display("Value in W_ERR_DATA register was wrong!") ;
3925
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3926
        test_fail("WB Erroneous Data register didn't provide right value") ;
3927
        ok = 0 ;
3928
    end
3929
 
3930
    if ( ok )
3931
        test_ok ;
3932
 
3933
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3934
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3935
    if ( temp_val1[1] !== 1 )
3936
    begin
3937
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3938
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3939
        test_fail("expected interrupt status bit was not set") ;
3940
    end
3941
    else
3942
        test_ok ;
3943
 
3944
    // clear interrupts and errors
3945
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3946
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3947
 
3948
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3949
    ok = 1 ;
3950
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3951
    if ( temp_val1[29] !== 1 )
3952
    begin
3953
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3954
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3955
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3956
        ok = 0 ;
3957
    end
3958
 
3959
    if ( temp_val1[28] !== 0 )
3960
    begin
3961
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3962
        $display("Received Target Abort bit was set for no reason!") ;
3963
        test_fail("Received Target Abort bit was set for no reason") ;
3964
        ok = 0 ;
3965
    end
3966
 
3967
    if ( ok )
3968
        test_ok ;
3969
 
3970
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3971
 
3972
    // disable image
3973
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
3974
    if ( ok !== 1 )
3975
    begin
3976
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
3977
        test_fail("WB Image Address Mask register couldn't be written") ;
3978
        disable main ;
3979
    end
3980
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
3981
 
3982
end
3983
endtask
3984
 
3985
task parity_checking ;
3986
    reg   [11:0] ctrl_offset ;
3987
    reg   [11:0] ba_offset ;
3988
    reg   [11:0] am_offset ;
3989
    reg   [11:0] ta_offset ;
3990
    reg `WRITE_STIM_TYPE write_data ;
3991
    reg `READ_STIM_TYPE  read_data ;
3992
    reg `READ_RETURN_TYPE read_status ;
3993
 
3994
    reg `WRITE_RETURN_TYPE write_status ;
3995
    reg `WB_TRANSFER_FLAGS write_flags ;
3996
    reg [31:0] temp_val1 ;
3997
    reg [31:0] temp_val2 ;
3998
    reg        ok   ;
3999
    reg [11:0] pci_ctrl_offset ;
4000
    reg [31:0] image_base ;
4001
    reg [31:0] target_address ;
4002
    reg [11:0] icr_offset ;
4003
    reg [11:0] isr_offset ;
4004
    reg [11:0] p_ba_offset ;
4005
    reg [11:0] p_am_offset ;
4006
    reg [11:0] p_ctrl_offset ;
4007
    integer    i ;
4008
    reg        perr_asserted ;
4009
begin:main
4010
    $display("******************************* Testing Parity Checker functions ********************************") ;
4011
    $display("Testing Parity Errors during Master Transactions!") ;
4012
    $display("Introducing Parity Erros to Master Writes!") ;
4013
    $fdisplay(pci_mon_log_file_desc,
4014
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4015
 
4016
    // image 1 is used for error testing, since it is always implemented
4017
    pci_ctrl_offset = 12'h004 ;
4018
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4019
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4020
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4021
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4022
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4023
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4024
 
4025
    // image 1 for PCI target
4026
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4027
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4028
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4029
 
4030
    target_address  = `BEH_TAR1_MEM_START ;
4031
    image_base      = 0 ;
4032
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4033
 
4034
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4035
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4036
    write_flags                    = 0 ;
4037
    write_flags`INIT_WAITS         = tb_init_waits ;
4038
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4039
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4040
 
4041
    // enable master & target operation and disable parity functions
4042
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4043
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4044
    if ( ok !== 1 )
4045
    begin
4046
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4047
        test_fail("PCI Device Control register could not be written to") ;
4048
        disable main ;
4049
    end
4050
 
4051
    // prepare image control register
4052
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4053
    if ( ok !== 1 )
4054
    begin
4055
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4056
        test_fail("WB Image Control register could not be written to") ;
4057
        disable main ;
4058
    end
4059
 
4060
    // prepare base address register
4061
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4062
    if ( ok !== 1 )
4063
    begin
4064
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4065
        test_fail("WB Image Base Address register could not be written to") ;
4066
        disable main ;
4067
    end
4068
 
4069
    // write address mask register
4070
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4071
    if ( ok !== 1 )
4072
    begin
4073
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4074
        test_fail("WB Image Address Mask register could not be written to") ;
4075
        disable main ;
4076
    end
4077
 
4078
    // disable parity interrupts
4079
    config_write( icr_offset, 0, 4'hF, ok ) ;
4080
    if ( ok !== 1 )
4081
    begin
4082
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4083
        test_fail("Interrupt Control register could not be written to") ;
4084
        disable main ;
4085
    end
4086
 
4087
    write_data`WRITE_ADDRESS = target_address ;
4088
    write_data`WRITE_DATA    = wmem_data[0] ;
4089
    write_data`WRITE_SEL     = 4'b1111 ;
4090
 
4091
    // enable target's 1 response to parity errors
4092 45 mihad
    configuration_cycle_write(0,                        // bus number
4093
                              `TAR1_IDSEL_INDEX - 11,   // device number
4094
                              0,                        // function number
4095
                              1,                        // register number
4096
                              0,                        // type of configuration cycle
4097
                              4'b0001,                  // byte enables
4098
                              32'h0000_0047             // data
4099 15 mihad
                             ) ;
4100
 
4101
    // disable target's 2 response to parity errors
4102 45 mihad
    configuration_cycle_write(0,                        // bus number
4103
                              `TAR2_IDSEL_INDEX - 11,   // device number
4104
                              0,                        // function number
4105
                              1,                        // register number
4106
                              0,                        // type of configuration cycle
4107
                              4'b0001,                  // byte enables
4108
                              32'h0000_0007             // data
4109 15 mihad
                             ) ;
4110
 
4111
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4112
 
4113
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4114
    fork
4115
    begin
4116
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4117
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4118
        begin
4119
            $display("Parity checker testing failed! Time %t ", $time) ;
4120
            $display("Bridge failed to process single memory write!") ;
4121
            test_fail("bridge failed to post single WB memory write") ;
4122
            disable main ;
4123
        end
4124
    end
4125
    begin:wait_perr1
4126
        perr_asserted = 0 ;
4127
        @(posedge pci_clock) ;
4128
 
4129 35 mihad
        while ( PERR !== 0 )
4130 15 mihad
            @(posedge pci_clock) ;
4131
 
4132 35 mihad
        perr_asserted = 1 ;
4133 15 mihad
 
4134
    end
4135
    begin
4136
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4137
 
4138
        if ( ok !== 1 )
4139
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4140
 
4141 35 mihad
        repeat(2)
4142 15 mihad
            @(posedge pci_clock) ;
4143
 
4144 35 mihad
        #1 ;
4145
        if ( !perr_asserted )
4146
            disable wait_perr1 ;
4147 15 mihad
    end
4148
    join
4149
 
4150
    if ( perr_asserted && ok )
4151
    begin
4152
        test_ok ;
4153
    end
4154
    else
4155
    if ( ~perr_asserted )
4156
    begin
4157
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4158
        disable main ;
4159
    end
4160
 
4161
    // check all the statuses - if HOST is defined, wait for them to be synced
4162
    `ifdef HOST
4163
    repeat(4)
4164
        @(posedge wb_clock) ;
4165
    `endif
4166
 
4167
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4168
    ok = 1 ;
4169
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4170 45 mihad
    if ( temp_val1[31] !== 0 )
4171 15 mihad
    begin
4172
        $display("Parity checker testing failed! Time %t ", $time) ;
4173 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4174
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4175 15 mihad
        ok = 0 ;
4176
    end
4177
 
4178
    if ( temp_val1[30] !== 0 )
4179
    begin
4180
        $display("Parity checker testing failed! Time %t ", $time) ;
4181
        $display("Signalled System Error bit was set for no reason!") ;
4182
        test_fail("Signalled System Error bit was set for no reason") ;
4183
        ok = 0 ;
4184
    end
4185
 
4186
    if ( temp_val1[24] !== 0 )
4187
    begin
4188
        $display("Parity checker testing failed! Time %t ", $time) ;
4189
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4190
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4191
        ok = 0 ;
4192
    end
4193
 
4194
    if ( ok )
4195
        test_ok ;
4196
 
4197
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4198
    // clear parity bits and enable parity response
4199
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4200
    if ( ok !== 1 )
4201
    begin
4202
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4203
        test_fail("write to PCI Status Register failed") ;
4204
        disable main ;
4205
    end
4206
 
4207
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4208
    fork
4209
    begin
4210
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4211
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4212
        begin
4213
            $display("Parity checker testing failed! Time %t ", $time) ;
4214
            $display("Bridge failed to process single memory write!") ;
4215
            test_fail("bridge failed to post single memory write") ;
4216
            disable main ;
4217
        end
4218
    end
4219
    begin:wait_perr2
4220
        perr_asserted = 0 ;
4221
        @(posedge pci_clock) ;
4222
 
4223 35 mihad
        while ( PERR !== 0 )
4224 15 mihad
            @(posedge pci_clock) ;
4225
 
4226 35 mihad
        perr_asserted = 1 ;
4227 15 mihad
 
4228
    end
4229
    begin
4230
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4231
 
4232
        if ( ok !== 1 )
4233
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4234
 
4235 35 mihad
        repeat(2)
4236 15 mihad
            @(posedge pci_clock) ;
4237
 
4238 35 mihad
        #1 ;
4239
        if (!perr_asserted)
4240
            disable wait_perr2 ;
4241 15 mihad
    end
4242
    join
4243
 
4244
    if ( perr_asserted && ok )
4245
    begin
4246
        test_ok ;
4247
    end
4248
    else
4249
    if ( ~perr_asserted )
4250
    begin
4251
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4252
        disable main ;
4253
    end
4254
 
4255
    // check all the statuses - if HOST is defined, wait for them to be synced
4256
    `ifdef HOST
4257
    repeat(4)
4258
        @(posedge wb_clock) ;
4259
    `endif
4260
 
4261
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4262
    ok = 1 ;
4263
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4264 45 mihad
    if ( temp_val1[31] !== 0 )
4265 15 mihad
    begin
4266
        $display("Parity checker testing failed! Time %t ", $time) ;
4267 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4268
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4269 15 mihad
        ok = 0 ;
4270
    end
4271
 
4272
    if ( temp_val1[30] !== 0 )
4273
    begin
4274
        $display("Parity checker testing failed! Time %t ", $time) ;
4275
        $display("Signalled System Error bit was set for no reason!") ;
4276
        test_fail("Signalled System Error bit was set for no reason") ;
4277
        ok = 0 ;
4278
    end
4279
 
4280
    if ( temp_val1[24] !== 1 )
4281
    begin
4282
        $display("Parity checker testing failed! Time %t ", $time) ;
4283 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!") ;
4284
        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") ;
4285 15 mihad
        ok = 0 ;
4286
    end
4287
 
4288
    if ( ok )
4289
        test_ok ;
4290
 
4291
    // clear status bits and disable parity error response
4292
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4293
 
4294
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4295
 
4296
    // disable perr generation and perform a write - no bits should be set
4297
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4298
    fork
4299
    begin
4300
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4301
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4302
        begin
4303
            $display("Parity checker testing failed! Time %t ", $time) ;
4304
            $display("Bridge failed to process single memory write!") ;
4305
            test_fail("bridge failed to post single memory write") ;
4306
            disable main ;
4307
        end
4308
    end
4309
    begin
4310
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4311
 
4312
        if ( ok !== 1 )
4313
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4314
        else
4315
            test_ok ;
4316
 
4317
        repeat(3)
4318
            @(posedge pci_clock) ;
4319
    end
4320
    join
4321
 
4322
    `ifdef HOST
4323
    repeat(4)
4324
        @(posedge wb_clock) ;
4325
    `endif
4326
 
4327
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4328
    ok = 1 ;
4329
 
4330
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4331
    if ( temp_val1[31] !== 0 )
4332
    begin
4333
        $display("Parity checker testing failed! Time %t ", $time) ;
4334
        $display("Detected Parity Error bit was set for no reason!") ;
4335
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4336
        ok = 0 ;
4337
    end
4338
 
4339
    if ( temp_val1[30] !== 0 )
4340
    begin
4341
        $display("Parity checker testing failed! Time %t ", $time) ;
4342
        $display("Signalled System Error bit was set for no reason!") ;
4343
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4344
        ok = 0 ;
4345
    end
4346
 
4347
    if ( temp_val1[24] !== 0 )
4348
    begin
4349
        $display("Parity checker testing failed! Time %t ", $time) ;
4350
        $display("Master Data Parity Error bit was set for no reason!") ;
4351
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4352
        ok = 0 ;
4353
    end
4354
 
4355
    if ( ok )
4356
        test_ok ;
4357
 
4358
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4359
 
4360
    read_data = 0 ;
4361
    read_data`READ_ADDRESS  = target_address ;
4362
    read_data`READ_SEL      = 4'hF ;
4363
    read_data`READ_TAG_STIM = 0 ;
4364
 
4365
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4366
 
4367
    // enable parity and system error interrupts
4368
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4369
 
4370
    // enable parity error response
4371
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4372
 
4373
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4374
 
4375
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4376
    fork
4377
    begin
4378
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4379
    end
4380
    begin:wait_perr4
4381
        perr_asserted = 0 ;
4382
        @(posedge pci_clock) ;
4383 35 mihad
        while ( PERR !== 0 )
4384 15 mihad
            @(posedge pci_clock) ;
4385
 
4386 35 mihad
        perr_asserted = 1 ;
4387 15 mihad
 
4388
    end
4389
    begin
4390
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4391
 
4392
        if ( ok !== 1 )
4393
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4394
 
4395
        repeat(2)
4396
            @(posedge pci_clock) ;
4397
 
4398 35 mihad
        #1 ;
4399
        if ( !perr_asserted )
4400
            disable wait_perr4 ;
4401 15 mihad
    end
4402
    join
4403
 
4404
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4405
    begin
4406
        $display("Parity checker testing failed! Time %t ", $time) ;
4407
        $display("Bridge failed to process single memory read!") ;
4408
        test_fail("bridge didn't process single memory read correctly") ;
4409
        ok = 0 ;
4410
    end
4411
 
4412
    if ( perr_asserted && ok )
4413
    begin
4414
        test_ok ;
4415
    end
4416
    else
4417
    if ( ~perr_asserted )
4418
    begin
4419
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4420
        disable main ;
4421
    end
4422
 
4423
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4424
    // interrupt should also be present
4425
    `ifdef HOST
4426
        repeat(4)
4427 26 mihad
            @(posedge pci_clock) ;
4428
        repeat(4)
4429 15 mihad
            @(posedge wb_clock) ;
4430
 
4431
        if ( INT_O !== 1 )
4432
        begin
4433
            $display("Parity checker testing failed! Time %t ", $time) ;
4434
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4435
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4436
        end
4437
        else
4438
            test_ok ;
4439
    `else
4440
    `ifdef GUEST
4441 26 mihad
        repeat(4)
4442
            @(posedge wb_clock) ;
4443
        repeat(4)
4444 15 mihad
            @(posedge pci_clock) ;
4445
 
4446
        if ( INTA !== 1 )
4447
        begin
4448
            $display("Parity checker testing failed! Time %t ", $time) ;
4449
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4450
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4451
        end
4452
        else
4453
            test_ok ;
4454
    `endif
4455
    `endif
4456
 
4457
    // check statuses!
4458
 
4459
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4460
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4461
    ok = 1 ;
4462
 
4463
    if ( temp_val1[31] !== 1 )
4464
    begin
4465
        $display("Parity checker testing failed! Time %t ", $time) ;
4466 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4467
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4468 15 mihad
        ok = 0 ;
4469
    end
4470
 
4471
    if ( temp_val1[30] !== 0 )
4472
    begin
4473
        $display("Parity checker testing failed! Time %t ", $time) ;
4474
        $display("Signalled System Error bit was set for no reason!") ;
4475
        test_fail("Signalled System Error bit was set for no reason") ;
4476
        ok = 0 ;
4477
    end
4478
 
4479
    if ( temp_val1[24] !== 1 )
4480
    begin
4481
        $display("Parity checker testing failed! Time %t ", $time) ;
4482 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4483
        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") ;
4484 15 mihad
        ok = 0 ;
4485
    end
4486
 
4487
    if ( ok )
4488
        test_ok ;
4489
 
4490
    // clear statuses and disable parity error response
4491
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4492
 
4493
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4494
    ok = 1 ;
4495
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4496
 
4497
    if ( temp_val1[4] !== 0 )
4498
    begin
4499
        $display("Parity checker testing failed! Time %t ", $time) ;
4500
        $display("System error interrupt status bit set for no reason!") ;
4501
        test_fail("System error interrupt status bit set for no reason") ;
4502
        ok = 0 ;
4503
    end
4504
 
4505
    `ifdef HOST
4506
    if ( temp_val1[3] !== 1 )
4507
    begin
4508
        $display("Parity checker testing failed! Time %t ", $time) ;
4509
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4510
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4511
        ok = 0 ;
4512
    end
4513
    `else
4514
    if ( temp_val1[3] !== 0 )
4515
    begin
4516
        $display("Parity checker testing failed! Time %t ", $time) ;
4517
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4518
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4519
        ok = 0 ;
4520
    end
4521
    `endif
4522
 
4523
    if ( ok )
4524
        test_ok ;
4525
 
4526
    // clear int statuses
4527
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4528
 
4529
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4530
 
4531
    `ifdef HOST
4532
        repeat(4)
4533 26 mihad
            @(posedge pci_clock) ;
4534
        repeat(4)
4535 15 mihad
            @(posedge wb_clock) ;
4536
 
4537
        if ( INT_O !== 0 )
4538
        begin
4539
            $display("Parity checker testing failed! Time %t ", $time) ;
4540
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4541
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4542
        end
4543
        else
4544
            test_ok ;
4545
    `else
4546
    `ifdef GUEST
4547 26 mihad
        repeat(4)
4548
            @(posedge wb_clock) ;
4549
        repeat(4)
4550 15 mihad
            @(posedge pci_clock) ;
4551
 
4552
        if ( INTA !== 1 )
4553
        begin
4554
            $display("Parity checker testing failed! Time %t ", $time) ;
4555
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4556
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4557
        end
4558
        else
4559
            test_ok ;
4560
    `endif
4561
    `endif
4562
 
4563
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4564
 
4565
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4566
    fork
4567
    begin
4568
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4569
    end
4570
    begin:wait_perr5
4571
        perr_asserted = 0 ;
4572
        @(posedge pci_clock) ;
4573
        while ( PERR === 1 )
4574
            @(posedge pci_clock) ;
4575
 
4576
        perr_asserted = 1 ;
4577
        $display("Parity checker testing failed! Time %t ", $time) ;
4578 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4579
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4580 15 mihad
    end
4581
    begin
4582
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4583
        if ( ok !== 1 )
4584
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4585
 
4586
        // perr can be asserted on idle or next PCI address phase
4587
        repeat(2)
4588
            @(posedge pci_clock) ;
4589
 
4590 35 mihad
        #1 ;
4591
        if ( !perr_asserted )
4592
            disable wait_perr5 ;
4593 15 mihad
    end
4594
    join
4595
 
4596
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4597
    begin
4598
        $display("Parity checker testing failed! Time %t ", $time) ;
4599
        $display("Bridge failed to process single memory read!") ;
4600
        test_fail("bridge failed to process single memory read correctly") ;
4601
        ok = 0 ;
4602
    end
4603
 
4604
    if ( ok && !perr_asserted)
4605
        test_ok ;
4606
 
4607
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4608
 
4609
    // interrupts should not be present
4610
    `ifdef HOST
4611
        repeat( 4 )
4612 26 mihad
            @(posedge pci_clock) ;
4613
        repeat( 4 )
4614 15 mihad
            @(posedge wb_clock) ;
4615
        if ( INT_O !== 0 )
4616
        begin
4617
            $display("Parity checker testing failed! Time %t ", $time) ;
4618
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4619
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4620
        end
4621
        else
4622
            test_ok ;
4623
    `else
4624
    `ifdef GUEST
4625
        repeat( 4 )
4626 26 mihad
            @(posedge wb_clock) ;
4627
        repeat( 4 )
4628 15 mihad
            @(posedge pci_clock) ;
4629
        if ( INTA !== 1 )
4630
        begin
4631
            $display("Parity checker testing failed! Time %t ", $time) ;
4632
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4633
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4634
        end
4635
        else
4636
            test_ok ;
4637
    `endif
4638
    `endif
4639
 
4640
    // check statuses!
4641
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4642
    ok = 1 ;
4643
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4644
    if ( temp_val1[31] !== 1 )
4645
    begin
4646
        $display("Parity checker testing failed! Time %t ", $time) ;
4647 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4648 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4649
        ok = 0 ;
4650
    end
4651
 
4652
    if ( temp_val1[30] !== 0 )
4653
    begin
4654
        $display("Parity checker testing failed! Time %t ", $time) ;
4655
        $display("Signalled System Error bit was set for no reason!") ;
4656
        test_fail("Signalled System Error bit was set for no reason") ;
4657
        ok = 0 ;
4658
    end
4659
 
4660
    if ( temp_val1[24] !== 0 )
4661
    begin
4662
        $display("Parity checker testing failed! Time %t ", $time) ;
4663 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4664 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4665
        ok = 0 ;
4666
    end
4667
 
4668
    if ( ok )
4669
        test_ok ;
4670
 
4671
    // clear statuses
4672
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4673
 
4674
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4675
    ok = 1 ;
4676
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4677
 
4678
    if ( temp_val1[4] !== 0 )
4679
    begin
4680
        $display("Parity checker testing failed! Time %t ", $time) ;
4681
        $display("System error interrupt status bit set for no reason!") ;
4682
        test_fail("System error interrupt status bit set for no reason") ;
4683
        ok = 0 ;
4684
    end
4685
 
4686
    if ( temp_val1[3] !== 0 )
4687
    begin
4688
        $display("Parity checker testing failed! Time %t ", $time) ;
4689
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4690
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4691
        ok = 0 ;
4692
    end
4693
 
4694
    if ( ok )
4695
        test_ok ;
4696
 
4697
    // enable all responses to parity errors!
4698
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4699
 
4700
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4701
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4702
 
4703
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4704
 
4705
    // repeat a read
4706
    fork
4707
    begin
4708
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4709
    end
4710
    begin:wait_perr6
4711
        perr_asserted = 0 ;
4712
        @(posedge pci_clock) ;
4713
        while ( PERR === 1 )
4714
            @(posedge pci_clock) ;
4715
 
4716
        perr_asserted = 1 ;
4717
        $display("Parity checker testing failed! Time %t ", $time) ;
4718
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4719
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4720
    end
4721
    begin
4722
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4723
        if ( ok !== 1 )
4724
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4725
 
4726
        repeat(2)
4727
            @(posedge pci_clock) ;
4728
 
4729 35 mihad
        #1 ;
4730
        if ( !perr_asserted )
4731
            disable wait_perr6 ;
4732 15 mihad
    end
4733
    join
4734
 
4735
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4736
    begin
4737
        $display("Parity checker testing failed! Time %t ", $time) ;
4738
        $display("Bridge failed to process single memory read!") ;
4739
        test_fail("bridge didn't process single memory read as expected") ;
4740
        ok = 0 ;
4741
    end
4742
 
4743
    if ( ok && !perr_asserted)
4744
        test_ok ;
4745
 
4746
    // check statuses!
4747
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4748
    ok = 1 ;
4749
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4750
    if ( temp_val1[31] !== 0 )
4751
    begin
4752
        $display("Parity checker testing failed! Time %t ", $time) ;
4753
        $display("Detected Parity Error bit was set for no reason!") ;
4754
        test_fail("Detected Parity Error bit was set for no reason") ;
4755
        ok = 0 ;
4756
    end
4757
 
4758
    if ( temp_val1[30] !== 0 )
4759
    begin
4760
        $display("Parity checker testing failed! Time %t ", $time) ;
4761
        $display("Signalled System Error bit was set for no reason!") ;
4762
        test_fail("Signalled System Error bit was set for no reason") ;
4763
        ok = 0 ;
4764
    end
4765
 
4766
    if ( temp_val1[24] !== 0 )
4767
    begin
4768
        $display("Parity checker testing failed! Time %t ", $time) ;
4769
        $display("Master Data Parity Error bit was set for no reason!") ;
4770
        test_fail("Master Data Parity Error bit was set for no reason") ;
4771
        ok = 0 ;
4772
    end
4773
 
4774
    if ( ok )
4775
        test_ok ;
4776
 
4777
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4778
    ok = 1 ;
4779
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4780
 
4781
    if ( temp_val1[4] !== 0 )
4782
    begin
4783
        $display("Parity checker testing failed! Time %t ", $time) ;
4784
        $display("System error interrupt status bit set for no reason!") ;
4785
        test_fail("System error interrupt status bit set for no reason") ;
4786
        ok = 0 ;
4787
    end
4788
 
4789
    if ( temp_val1[3] !== 0 )
4790
    begin
4791
        $display("Parity checker testing failed! Time %t ", $time) ;
4792
        $display("Parity error interrupt status bit set for no reason!") ;
4793
        test_fail("Parity error interrupt status bit set for no reason") ;
4794
        ok = 0 ;
4795
    end
4796
 
4797
    if ( ok )
4798
        test_ok ;
4799
 
4800
    $display("Presenting address parity error on PCI bus!") ;
4801
    // enable parity errors - this should not affect system errors
4802
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4803
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4804
 
4805
    // perform PCI write
4806
    // check transaction progress
4807
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4808
    fork
4809
    begin
4810
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4811
               target_address, 32'h1234_5678,
4812
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4813
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4814
        do_pause( 1 ) ;
4815
    end
4816
    begin:wait_serr7
4817
        perr_asserted = 0 ;
4818
        @(posedge pci_clock) ;
4819
        while( SERR === 1 )
4820
            @(posedge pci_clock) ;
4821
 
4822
        perr_asserted = 1 ;
4823
        $display("Parity checker testing failed! Time %t ", $time) ;
4824
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4825
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4826
    end
4827
    begin
4828
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4829
        if ( ok !== 1 )
4830
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4831
 
4832 35 mihad
        if ( !perr_asserted )
4833
            disable wait_serr7 ;
4834 15 mihad
    end
4835
    join
4836
 
4837
    if ( ok && !perr_asserted)
4838
        test_ok ;
4839
 
4840
    // check statuses!
4841
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4842
    ok = 1 ;
4843
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4844
    if ( temp_val1[31] !== 1 )
4845
    begin
4846
        $display("Parity checker testing failed! Time %t ", $time) ;
4847
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4848
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4849
        ok = 0 ;
4850
    end
4851
 
4852
    if ( temp_val1[30] !== 0 )
4853
    begin
4854
        $display("Parity checker testing failed! Time %t ", $time) ;
4855
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4856
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4857
        ok = 0 ;
4858
    end
4859
 
4860
    if ( temp_val1[24] !== 0 )
4861
    begin
4862
        $display("Parity checker testing failed! Time %t ", $time) ;
4863
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4864
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4865
        ok = 0 ;
4866
    end
4867
 
4868
    if ( ok )
4869
        test_ok ;
4870
 
4871
    // clear statuses
4872
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4873
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4874
    fork
4875
    begin
4876
        ipci_unsupported_commands_master.master_reference
4877
        (
4878
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4879
            32'h5555_5555,      // second part of address in dual address cycle
4880
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4881
            `BC_MEM_WRITE,      // normal command
4882
            4'h0,               // byte enables
4883
            32'h1234_5678,      // data
4884
            1'b1,               // make address parity error on first phase of dual address
4885
            1'b0,               // make address parity error on second phase of dual address
4886
            ok                  // result of operation
4887
        ) ;
4888 35 mihad
        if ( !perr_asserted )
4889
            disable wait_serr8 ;
4890 15 mihad
    end
4891
    begin:wait_serr8
4892
        perr_asserted = 0 ;
4893
        @(posedge pci_clock) ;
4894
        while( SERR === 1 )
4895
            @(posedge pci_clock) ;
4896
 
4897
        perr_asserted = 1 ;
4898
        $display("Parity checker testing failed! Time %t ", $time) ;
4899
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4900
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4901
    end
4902
    join
4903
 
4904
    if ( ok && !perr_asserted)
4905
        test_ok ;
4906
 
4907
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4908
    fork
4909
    begin
4910
        ipci_unsupported_commands_master.master_reference
4911
        (
4912
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4913
            32'h5555_5555,      // second part of address in dual address cycle
4914
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4915
            `BC_MEM_WRITE,      // normal command
4916
            4'h0,               // byte enables
4917
            32'h1234_5678,      // data
4918
            1'b0,               // make address parity error on first phase of dual address
4919
            1'b1,               // make address parity error on second phase of dual address
4920
            ok                  // result of operation
4921
        ) ;
4922 35 mihad
        if ( !perr_asserted )
4923
            disable wait_serr9 ;
4924 15 mihad
    end
4925
    begin:wait_serr9
4926
        perr_asserted = 0 ;
4927
        @(posedge pci_clock) ;
4928
        while( SERR === 1 )
4929
            @(posedge pci_clock) ;
4930
 
4931
        perr_asserted = 1 ;
4932
        $display("Parity checker testing failed! Time %t ", $time) ;
4933
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4934
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4935
    end
4936
    join
4937
 
4938
    if ( ok && !perr_asserted)
4939
        test_ok ;
4940
 
4941
    // check statuses!
4942
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4943
    ok = 1 ;
4944
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4945
    if ( temp_val1[31] !== 1 )
4946
    begin
4947
        $display("Parity checker testing failed! Time %t ", $time) ;
4948
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4949
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4950
        ok = 0 ;
4951
    end
4952
 
4953
    if ( temp_val1[30] !== 0 )
4954
    begin
4955
        $display("Parity checker testing failed! Time %t ", $time) ;
4956
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4957
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4958
        ok = 0 ;
4959
    end
4960
 
4961
    if ( temp_val1[24] !== 0 )
4962
    begin
4963
        $display("Parity checker testing failed! Time %t ", $time) ;
4964
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4965
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4966
        ok = 0 ;
4967
    end
4968
 
4969
    if ( ok )
4970
        test_ok ;
4971
 
4972
    // clear statuses
4973
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4974
 
4975
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4976
    fork
4977
    begin
4978
        ipci_unsupported_commands_master.master_reference
4979
        (
4980
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4981
            32'h5555_5555,      // second part of address in dual address cycle
4982
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4983
            `BC_MEM_WRITE,      // normal command
4984
            4'h0,               // byte enables
4985
            32'h1234_5678,      // data
4986
            1'b1,               // make address parity error on first phase of dual address
4987
            1'b1,               // make address parity error on second phase of dual address
4988
            ok                  // result of operation
4989
        ) ;
4990 35 mihad
        if ( !perr_asserted )
4991
            disable wait_serr10 ;
4992 15 mihad
    end
4993
    begin:wait_serr10
4994
        perr_asserted = 0 ;
4995
        @(posedge pci_clock) ;
4996
        while( SERR === 1 )
4997
            @(posedge pci_clock) ;
4998
 
4999
        perr_asserted = 1 ;
5000
        $display("Parity checker testing failed! Time %t ", $time) ;
5001
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5002
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5003
    end
5004
    join
5005
 
5006
    if ( ok && !perr_asserted)
5007
        test_ok ;
5008
 
5009
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5010
 
5011
    `ifdef HOST
5012
        repeat(4)
5013 26 mihad
            @(posedge pci_clock) ;
5014
        repeat(4)
5015 15 mihad
            @(posedge wb_clock) ;
5016
        if ( INT_O !== 0 )
5017
        begin
5018
            $display("Parity checker testing failed! Time %t ", $time) ;
5019
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5020
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5021
        end
5022
        else
5023
            test_ok ;
5024
    `else
5025
    `ifdef GUEST
5026 26 mihad
        repeat(4)
5027
            @(posedge wb_clock) ;
5028
        repeat(4)
5029 15 mihad
            @(posedge pci_clock) ;
5030
 
5031
        if ( INTA !== 1 )
5032
        begin
5033
            $display("Parity checker testing failed! Time %t ", $time) ;
5034
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5035
            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") ;
5036
        end
5037
        else
5038
            test_ok ;
5039
    `endif
5040
    `endif
5041
 
5042
    // check statuses!
5043
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5044
    ok = 1 ;
5045
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5046
    if ( temp_val1[31] !== 1 )
5047
    begin
5048
        $display("Parity checker testing failed! Time %t ", $time) ;
5049
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5050
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5051
        ok = 0 ;
5052
    end
5053
 
5054
    if ( temp_val1[30] !== 0 )
5055
    begin
5056
        $display("Parity checker testing failed! Time %t ", $time) ;
5057
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5058
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5059
        ok = 0 ;
5060
    end
5061
 
5062
    if ( temp_val1[24] !== 0 )
5063
    begin
5064
        $display("Parity checker testing failed! Time %t ", $time) ;
5065
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5066
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5067
        ok = 0 ;
5068
    end
5069
 
5070
    if ( ok )
5071
        test_ok ;
5072
 
5073
    // clear statuses
5074
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5075
 
5076
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5077
    ok = 1 ;
5078
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5079
 
5080
    if ( temp_val1[4] !== 0 )
5081
    begin
5082
        $display("Parity checker testing failed! Time %t ", $time) ;
5083
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5084
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5085
        ok = 0 ;
5086
    end
5087
 
5088
    if ( temp_val1[3] !== 0 )
5089
    begin
5090
        $display("Parity checker testing failed! Time %t ", $time) ;
5091
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5092
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5093
        ok = 0 ;
5094
    end
5095
 
5096
    if ( ok )
5097
        test_ok ;
5098
 
5099
    // now enable system error signaling and test response
5100
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5101
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5102
 
5103
    fork
5104
    begin
5105
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5106
               target_address, 32'h1234_5678,
5107
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5108
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5109
        do_pause( 1 ) ;
5110
    end
5111
    begin:wait_serr11
5112
        perr_asserted = 0 ;
5113
        @(posedge pci_clock) ;
5114 35 mihad
        while( SERR !== 0 )
5115 15 mihad
            @(posedge pci_clock) ;
5116
 
5117 35 mihad
        perr_asserted = 1 ;
5118 15 mihad
    end
5119
    begin
5120
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5121
        if ( ok !== 1 )
5122
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5123
 
5124
        @(posedge pci_clock) ;
5125 35 mihad
        #1 ;
5126
        if ( !perr_asserted )
5127
            disable wait_serr11 ;
5128 15 mihad
    end
5129
    join
5130
 
5131
    if ( ok && perr_asserted)
5132
        test_ok ;
5133
    else
5134
    if ( !perr_asserted )
5135
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5136
 
5137
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5138
 
5139
    `ifdef HOST
5140
        repeat(4)
5141 26 mihad
            @(posedge pci_clock) ;
5142
        repeat(4)
5143 15 mihad
            @(posedge wb_clock) ;
5144
        if ( INT_O !== 1 )
5145
        begin
5146
            $display("Parity checker testing failed! Time %t ", $time) ;
5147
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5148
            test_fail("Interrupt Request was not triggered as expected") ;
5149
        end
5150
        else
5151
            test_ok ;
5152
    `else
5153
    `ifdef GUEST
5154 26 mihad
        repeat(4)
5155
            @(posedge wb_clock) ;
5156
        repeat(4)
5157 15 mihad
            @(posedge pci_clock) ;
5158
 
5159
        if ( INTA !== 1 )
5160
        begin
5161
            $display("Parity checker testing failed! Time %t ", $time) ;
5162
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5163
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5164
        end
5165
        else
5166
            test_ok ;
5167
    `endif
5168
    `endif
5169
 
5170
    // check statuses!
5171
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5172
    ok = 1 ;
5173
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5174
    if ( temp_val1[31] !== 1 )
5175
    begin
5176
        $display("Parity checker testing failed! Time %t ", $time) ;
5177
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5178
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5179
        ok = 0 ;
5180
    end
5181
 
5182
    if ( temp_val1[30] !== 1 )
5183
    begin
5184
        $display("Parity checker testing failed! Time %t ", $time) ;
5185
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5186
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5187
        ok = 0 ;
5188
    end
5189
 
5190
    if ( temp_val1[24] !== 0 )
5191
    begin
5192
        $display("Parity checker testing failed! Time %t ", $time) ;
5193
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5194
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5195
        ok = 0 ;
5196
    end
5197
 
5198
    if ( ok )
5199
        test_ok ;
5200
 
5201
    // clear statuses
5202
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5203
 
5204
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5205
 
5206
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5207
    ok = 1 ;
5208
 
5209
    `ifdef HOST
5210
    if ( temp_val1[4] !== 1 )
5211
    begin
5212
        $display("Parity checker testing failed! Time %t ", $time) ;
5213
        $display("System error interrupt status bit not set when expected!") ;
5214
        test_fail("System error interrupt status bit not set when expected") ;
5215
        ok = 0 ;
5216
    end
5217
    `else
5218
    if ( temp_val1[4] !== 0 )
5219
    begin
5220
        $display("Parity checker testing failed! Time %t ", $time) ;
5221
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5222
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5223
        ok = 0 ;
5224
    end
5225
    `endif
5226
 
5227
    if ( temp_val1[3] !== 0 )
5228
    begin
5229
        $display("Parity checker testing failed! Time %t ", $time) ;
5230
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5231
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5232
        ok = 0 ;
5233
    end
5234
 
5235
    if ( ok )
5236
        test_ok ;
5237
 
5238
    // clear statuses
5239
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5240
 
5241
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5242
    fork
5243
    begin
5244
        ipci_unsupported_commands_master.master_reference
5245
        (
5246
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5247
            32'h5555_5555,      // second part of address in dual address cycle
5248
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5249
            `BC_MEM_WRITE,      // normal command
5250
            4'h0,               // byte enables
5251
            32'h1234_5678,      // data
5252
            1'b1,               // make address parity error on first phase of dual address
5253
            1'b0,               // make address parity error on second phase of dual address
5254
            ok                  // result of operation
5255
        ) ;
5256 35 mihad
        if ( !perr_asserted )
5257
            disable wait_serr14 ;
5258 15 mihad
    end
5259
    begin:wait_serr14
5260
        perr_asserted = 0 ;
5261
        @(posedge pci_clock) ;
5262 35 mihad
        while( SERR !== 0 )
5263 15 mihad
            @(posedge pci_clock) ;
5264
 
5265 35 mihad
        perr_asserted = 1 ;
5266 15 mihad
    end
5267
    join
5268
 
5269
    if ( ok && perr_asserted)
5270
        test_ok ;
5271
    else
5272
    if ( !perr_asserted )
5273
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5274
 
5275
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5276
 
5277
    `ifdef HOST
5278
        repeat(4)
5279 26 mihad
            @(posedge pci_clock) ;
5280
        repeat(4)
5281 15 mihad
            @(posedge wb_clock) ;
5282
        if ( INT_O !== 1 )
5283
        begin
5284
            $display("Parity checker testing failed! Time %t ", $time) ;
5285
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5286
            test_fail("Interrupt Request was not triggered as expected") ;
5287
        end
5288
        else
5289
            test_ok ;
5290
    `else
5291
    `ifdef GUEST
5292 26 mihad
        repeat(4)
5293
            @(posedge wb_clock) ;
5294
        repeat(4)
5295 15 mihad
            @(posedge pci_clock) ;
5296
 
5297
        if ( INTA !== 1 )
5298
        begin
5299
            $display("Parity checker testing failed! Time %t ", $time) ;
5300
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5301
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5302
        end
5303
        else
5304
            test_ok ;
5305
    `endif
5306
    `endif
5307
 
5308
    // check statuses!
5309
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5310
    ok = 1 ;
5311
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5312
    if ( temp_val1[31] !== 1 )
5313
    begin
5314
        $display("Parity checker testing failed! Time %t ", $time) ;
5315
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5316
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5317
        ok = 0 ;
5318
    end
5319
 
5320
    if ( temp_val1[30] !== 1 )
5321
    begin
5322
        $display("Parity checker testing failed! Time %t ", $time) ;
5323
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5324
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5325
        ok = 0 ;
5326
    end
5327
 
5328
    if ( temp_val1[24] !== 0 )
5329
    begin
5330
        $display("Parity checker testing failed! Time %t ", $time) ;
5331
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5332
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5333
        ok = 0 ;
5334
    end
5335
 
5336
    if ( ok )
5337
        test_ok ;
5338
 
5339
    // clear statuses
5340
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5341
 
5342
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5343
 
5344
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5345
    ok = 1 ;
5346
 
5347
    `ifdef HOST
5348
    if ( temp_val1[4] !== 1 )
5349
    begin
5350
        $display("Parity checker testing failed! Time %t ", $time) ;
5351
        $display("System error interrupt status bit not set when expected!") ;
5352
        test_fail("System error interrupt status bit not set when expected") ;
5353
        ok = 0 ;
5354
    end
5355
    `else
5356
    if ( temp_val1[4] !== 0 )
5357
    begin
5358
        $display("Parity checker testing failed! Time %t ", $time) ;
5359
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5360
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5361
        ok = 0 ;
5362
    end
5363
    `endif
5364
 
5365
    if ( temp_val1[3] !== 0 )
5366
    begin
5367
        $display("Parity checker testing failed! Time %t ", $time) ;
5368
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5369
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5370
        ok = 0 ;
5371
    end
5372
 
5373
    if ( ok )
5374
        test_ok ;
5375
 
5376
    // clear statuses
5377
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5378
 
5379
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5380
    fork
5381
    begin
5382
        ipci_unsupported_commands_master.master_reference
5383
        (
5384
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5385
            32'h5555_5555,      // second part of address in dual address cycle
5386
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5387
            `BC_MEM_WRITE,      // normal command
5388
            4'h0,               // byte enables
5389
            32'h1234_5678,      // data
5390
            1'b0,               // make address parity error on first phase of dual address
5391
            1'b1,               // make address parity error on second phase of dual address
5392
            ok                  // result of operation
5393
        ) ;
5394 35 mihad
        if ( !perr_asserted )
5395
            disable wait_serr15 ;
5396 15 mihad
    end
5397
    begin:wait_serr15
5398
        perr_asserted = 0 ;
5399
        @(posedge pci_clock) ;
5400 35 mihad
        while( SERR !== 0 )
5401 15 mihad
            @(posedge pci_clock) ;
5402
 
5403 35 mihad
        perr_asserted = 1 ;
5404 15 mihad
    end
5405
    join
5406
 
5407
    if ( ok && perr_asserted)
5408
        test_ok ;
5409
    else
5410
    if ( !perr_asserted )
5411
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5412
 
5413
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5414
 
5415
    `ifdef HOST
5416
        repeat(4)
5417 26 mihad
            @(posedge pci_clock) ;
5418
        repeat(4)
5419 15 mihad
            @(posedge wb_clock) ;
5420
        if ( INT_O !== 1 )
5421
        begin
5422
            $display("Parity checker testing failed! Time %t ", $time) ;
5423
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5424
            test_fail("Interrupt Request was not triggered as expected") ;
5425
        end
5426
        else
5427
            test_ok ;
5428
    `else
5429
    `ifdef GUEST
5430 26 mihad
        repeat(4)
5431
            @(posedge wb_clock) ;
5432
        repeat(4)
5433 15 mihad
            @(posedge pci_clock) ;
5434
 
5435
        if ( INTA !== 1 )
5436
        begin
5437
            $display("Parity checker testing failed! Time %t ", $time) ;
5438
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5439
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5440
        end
5441
        else
5442
            test_ok ;
5443
    `endif
5444
    `endif
5445
 
5446
    // check statuses!
5447
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5448
    ok = 1 ;
5449
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5450
    if ( temp_val1[31] !== 1 )
5451
    begin
5452
        $display("Parity checker testing failed! Time %t ", $time) ;
5453
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5454
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5455
        ok = 0 ;
5456
    end
5457
 
5458
    if ( temp_val1[30] !== 1 )
5459
    begin
5460
        $display("Parity checker testing failed! Time %t ", $time) ;
5461
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5462
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5463
        ok = 0 ;
5464
    end
5465
 
5466
    if ( temp_val1[24] !== 0 )
5467
    begin
5468
        $display("Parity checker testing failed! Time %t ", $time) ;
5469
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5470
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5471
        ok = 0 ;
5472
    end
5473
 
5474
    if ( ok )
5475
        test_ok ;
5476
 
5477
    // clear statuses
5478
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5479
 
5480
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5481
 
5482
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5483
    ok = 1 ;
5484
 
5485
    `ifdef HOST
5486
    if ( temp_val1[4] !== 1 )
5487
    begin
5488
        $display("Parity checker testing failed! Time %t ", $time) ;
5489
        $display("System error interrupt status bit not set when expected!") ;
5490
        test_fail("System error interrupt status bit not set when expected") ;
5491
        ok = 0 ;
5492
    end
5493
    `else
5494
    if ( temp_val1[4] !== 0 )
5495
    begin
5496
        $display("Parity checker testing failed! Time %t ", $time) ;
5497
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5498
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5499
        ok = 0 ;
5500
    end
5501
    `endif
5502
 
5503
    if ( temp_val1[3] !== 0 )
5504
    begin
5505
        $display("Parity checker testing failed! Time %t ", $time) ;
5506
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5507
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5508
        ok = 0 ;
5509
    end
5510
 
5511
    if ( ok )
5512
        test_ok ;
5513
 
5514
    // clear statuses
5515
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5516
 
5517
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5518
    fork
5519
    begin
5520
        ipci_unsupported_commands_master.master_reference
5521
        (
5522
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5523
            32'h5555_5555,      // second part of address in dual address cycle
5524
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5525
            `BC_MEM_WRITE,      // normal command
5526
            4'h0,               // byte enables
5527
            32'h1234_5678,      // data
5528
            1'b1,               // make address parity error on first phase of dual address
5529
            1'b1,               // make address parity error on second phase of dual address
5530
            ok                  // result of operation
5531
        ) ;
5532 35 mihad
        if ( !perr_asserted )
5533
            disable wait_serr16 ;
5534 15 mihad
    end
5535
    begin:wait_serr16
5536
        perr_asserted = 0 ;
5537
        @(posedge pci_clock) ;
5538 35 mihad
        while( SERR !== 0 )
5539 15 mihad
            @(posedge pci_clock) ;
5540
 
5541 35 mihad
        perr_asserted = 1 ;
5542 15 mihad
    end
5543
    join
5544
 
5545
    if ( ok && perr_asserted)
5546
        test_ok ;
5547
    else
5548
    if ( !perr_asserted )
5549
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5550
 
5551
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5552
 
5553
    `ifdef HOST
5554
        repeat(4)
5555 26 mihad
            @(posedge pci_clock) ;
5556
        repeat(4)
5557 15 mihad
            @(posedge wb_clock) ;
5558
        if ( INT_O !== 1 )
5559
        begin
5560
            $display("Parity checker testing failed! Time %t ", $time) ;
5561
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5562
            test_fail("Interrupt Request was not triggered as expected") ;
5563
        end
5564
        else
5565
            test_ok ;
5566
    `else
5567
    `ifdef GUEST
5568 26 mihad
        repeat(4)
5569
            @(posedge wb_clock) ;
5570
        repeat(4)
5571 15 mihad
            @(posedge pci_clock) ;
5572
 
5573
        if ( INTA !== 1 )
5574
        begin
5575
            $display("Parity checker testing failed! Time %t ", $time) ;
5576
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5577
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5578
        end
5579
        else
5580
            test_ok ;
5581
    `endif
5582
    `endif
5583
 
5584
    // check statuses!
5585
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5586
    ok = 1 ;
5587
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5588
    if ( temp_val1[31] !== 1 )
5589
    begin
5590
        $display("Parity checker testing failed! Time %t ", $time) ;
5591
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5592
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5593
        ok = 0 ;
5594
    end
5595
 
5596
    if ( temp_val1[30] !== 1 )
5597
    begin
5598
        $display("Parity checker testing failed! Time %t ", $time) ;
5599
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5600
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5601
        ok = 0 ;
5602
    end
5603
 
5604
    if ( temp_val1[24] !== 0 )
5605
    begin
5606
        $display("Parity checker testing failed! Time %t ", $time) ;
5607
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5608
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5609
        ok = 0 ;
5610
    end
5611
 
5612
    if ( ok )
5613
        test_ok ;
5614
 
5615
    // clear statuses
5616
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5617
 
5618
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5619
 
5620
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5621
    ok = 1 ;
5622
 
5623
    `ifdef HOST
5624
    if ( temp_val1[4] !== 1 )
5625
    begin
5626
        $display("Parity checker testing failed! Time %t ", $time) ;
5627
        $display("System error interrupt status bit not set when expected!") ;
5628
        test_fail("System error interrupt status bit not set when expected") ;
5629
        ok = 0 ;
5630
    end
5631
    `else
5632
    if ( temp_val1[4] !== 0 )
5633
    begin
5634
        $display("Parity checker testing failed! Time %t ", $time) ;
5635
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5636
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5637
        ok = 0 ;
5638
    end
5639
    `endif
5640
 
5641
    if ( temp_val1[3] !== 0 )
5642
    begin
5643
        $display("Parity checker testing failed! Time %t ", $time) ;
5644
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5645
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5646
        ok = 0 ;
5647
    end
5648
 
5649
    if ( ok )
5650
        test_ok ;
5651
 
5652
    // clear statuses
5653
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5654
 
5655
    // now just disable Parity Error response - on Address par errors nothing should happen
5656
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5657
 
5658
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5659
    fork
5660
    begin
5661
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5662
               target_address, 32'h1234_5678,
5663
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5664
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5665
        do_pause( 1 ) ;
5666
    end
5667
    begin:wait_serr12
5668
        perr_asserted = 0 ;
5669
        @(posedge pci_clock) ;
5670
        while( SERR === 1 )
5671
            @(posedge pci_clock) ;
5672
 
5673
        perr_asserted = 1 ;
5674
        $display("Parity checker testing failed! Time %t ", $time) ;
5675
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5676
        test_fail("SERR asserted when parity error response was disabled") ;
5677
    end
5678
    begin
5679
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5680
        if ( ok !== 1 )
5681
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5682
 
5683 35 mihad
        @(posedge pci_clock) ;
5684
        #1 ;
5685
        if ( !perr_asserted )
5686
            disable wait_serr12 ;
5687 15 mihad
    end
5688
    join
5689
 
5690
    if ( ok && !perr_asserted )
5691
        test_ok ;
5692
 
5693
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5694
    `ifdef HOST
5695 26 mihad
        repeat (4)
5696
            @(posedge pci_clock) ;
5697 15 mihad
        repeat(4)
5698
            @(posedge wb_clock) ;
5699
        if ( INT_O !== 0 )
5700
        begin
5701
            $display("Parity checker testing failed! Time %t ", $time) ;
5702
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5703
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5704
        end
5705
        else
5706
            test_ok ;
5707
    `else
5708
    `ifdef GUEST
5709 26 mihad
        repeat(4)
5710
            @(posedge wb_clock) ;
5711
        repeat (4)
5712 15 mihad
            @(posedge pci_clock) ;
5713
 
5714
        if ( INTA !== 1 )
5715
        begin
5716
            $display("Parity checker testing failed! Time %t ", $time) ;
5717
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5718
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5719
        end
5720
        else
5721
            test_ok ;
5722
    `endif
5723
    `endif
5724
 
5725
    // check statuses!
5726
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5727
    ok = 1 ;
5728
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5729
    if ( temp_val1[31] !== 1 )
5730
    begin
5731
        $display("Parity checker testing failed! Time %t ", $time) ;
5732
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5733
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5734
        ok = 0 ;
5735
    end
5736
 
5737
    if ( temp_val1[30] !== 0 )
5738
    begin
5739
        $display("Parity checker testing failed! Time %t ", $time) ;
5740
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5741
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5742
        ok = 0 ;
5743
    end
5744
 
5745
    if ( temp_val1[24] !== 0 )
5746
    begin
5747
        $display("Parity checker testing failed! Time %t ", $time) ;
5748
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5749
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5750
        ok = 0 ;
5751
    end
5752
 
5753
    if ( ok )
5754
        test_ok ;
5755
 
5756
    // clear statuses
5757
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5758
 
5759
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5760
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5761
    ok = 1 ;
5762
    if ( temp_val1[4] !== 0 )
5763
    begin
5764
        $display("Parity checker testing failed! Time %t ", $time) ;
5765
        $display("System error interrupt status bit set when not expected!") ;
5766
        test_fail("System error interrupt status bit set when not expected") ;
5767
        ok = 0 ;
5768
    end
5769
 
5770
    if ( temp_val1[3] !== 0 )
5771
    begin
5772
        $display("Parity checker testing failed! Time %t ", $time) ;
5773
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5774
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5775
        ok = 0 ;
5776
    end
5777
 
5778
    if ( ok )
5779
        test_ok ;
5780
 
5781
    // clear statuses
5782
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5783
 
5784
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5785
    fork
5786
    begin
5787
        ipci_unsupported_commands_master.master_reference
5788
        (
5789
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5790
            32'h5555_5555,      // second part of address in dual address cycle
5791
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5792
            `BC_MEM_WRITE,      // normal command
5793
            4'h0,               // byte enables
5794
            32'h1234_5678,      // data
5795
            1'b1,               // make address parity error on first phase of dual address
5796
            1'b0,               // make address parity error on second phase of dual address
5797
            ok                  // result of operation
5798
        ) ;
5799 35 mihad
        if ( !perr_asserted )
5800
            disable wait_serr17 ;
5801 15 mihad
    end
5802
    begin:wait_serr17
5803
        perr_asserted = 0 ;
5804
        @(posedge pci_clock) ;
5805
        while( SERR === 1 )
5806
            @(posedge pci_clock) ;
5807
 
5808
        perr_asserted = 1 ;
5809
        $display("Parity checker testing failed! Time %t ", $time) ;
5810
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5811
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5812
    end
5813
    join
5814
 
5815
    if ( ok && !perr_asserted)
5816
        test_ok ;
5817
 
5818
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5819
    fork
5820
    begin
5821
        ipci_unsupported_commands_master.master_reference
5822
        (
5823
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5824
            32'h5555_5555,      // second part of address in dual address cycle
5825
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5826
            `BC_MEM_WRITE,      // normal command
5827
            4'h0,               // byte enables
5828
            32'h1234_5678,      // data
5829
            1'b0,               // make address parity error on first phase of dual address
5830
            1'b1,               // make address parity error on second phase of dual address
5831
            ok                  // result of operation
5832
        ) ;
5833 35 mihad
        if ( !perr_asserted )
5834
            disable wait_serr18 ;
5835 15 mihad
    end
5836
    begin:wait_serr18
5837
        perr_asserted = 0 ;
5838
        @(posedge pci_clock) ;
5839
        while( SERR === 1 )
5840
            @(posedge pci_clock) ;
5841
 
5842
        perr_asserted = 1 ;
5843
        $display("Parity checker testing failed! Time %t ", $time) ;
5844
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5845
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5846
    end
5847
    join
5848
 
5849
    if ( ok && !perr_asserted)
5850
        test_ok ;
5851
 
5852
    // check statuses!
5853
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5854
    ok = 1 ;
5855
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5856
    if ( temp_val1[31] !== 1 )
5857
    begin
5858
        $display("Parity checker testing failed! Time %t ", $time) ;
5859
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5860
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5861
        ok = 0 ;
5862
    end
5863
 
5864
    if ( temp_val1[30] !== 0 )
5865
    begin
5866
        $display("Parity checker testing failed! Time %t ", $time) ;
5867
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5868
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5869
        ok = 0 ;
5870
    end
5871
 
5872
    if ( temp_val1[24] !== 0 )
5873
    begin
5874
        $display("Parity checker testing failed! Time %t ", $time) ;
5875
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5876
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5877
        ok = 0 ;
5878
    end
5879
 
5880
    if ( ok )
5881
        test_ok ;
5882
 
5883
    // clear statuses
5884
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5885
 
5886
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5887
    fork
5888
    begin
5889
        ipci_unsupported_commands_master.master_reference
5890
        (
5891
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5892
            32'h5555_5555,      // second part of address in dual address cycle
5893
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5894
            `BC_MEM_WRITE,      // normal command
5895
            4'h0,               // byte enables
5896
            32'h1234_5678,      // data
5897
            1'b1,               // make address parity error on first phase of dual address
5898
            1'b1,               // make address parity error on second phase of dual address
5899
            ok                  // result of operation
5900
        ) ;
5901 35 mihad
        if ( !perr_asserted )
5902
            disable wait_serr19 ;
5903 15 mihad
    end
5904
    begin:wait_serr19
5905
        perr_asserted = 0 ;
5906
        @(posedge pci_clock) ;
5907
        while( SERR === 1 )
5908
            @(posedge pci_clock) ;
5909
 
5910
        perr_asserted = 1 ;
5911
        $display("Parity checker testing failed! Time %t ", $time) ;
5912
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5913
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5914
    end
5915
    join
5916
 
5917
    if ( ok && !perr_asserted)
5918
        test_ok ;
5919
 
5920
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5921
 
5922
    `ifdef HOST
5923
        repeat(4)
5924 26 mihad
            @(posedge pci_clock) ;
5925
        repeat(4)
5926 15 mihad
            @(posedge wb_clock) ;
5927
        if ( INT_O !== 0 )
5928
        begin
5929
            $display("Parity checker testing failed! Time %t ", $time) ;
5930
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5931
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5932
        end
5933
        else
5934
            test_ok ;
5935
    `else
5936
    `ifdef GUEST
5937 26 mihad
        repeat(4)
5938
            @(posedge wb_clock) ;
5939
        repeat(4)
5940 15 mihad
            @(posedge pci_clock) ;
5941
 
5942
        if ( INTA !== 1 )
5943
        begin
5944
            $display("Parity checker testing failed! Time %t ", $time) ;
5945
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5946
            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") ;
5947
        end
5948
        else
5949
            test_ok ;
5950
    `endif
5951
    `endif
5952
 
5953
    // check statuses!
5954
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5955
    ok = 1 ;
5956
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5957
    if ( temp_val1[31] !== 1 )
5958
    begin
5959
        $display("Parity checker testing failed! Time %t ", $time) ;
5960
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5961
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5962
        ok = 0 ;
5963
    end
5964
 
5965
    if ( temp_val1[30] !== 0 )
5966
    begin
5967
        $display("Parity checker testing failed! Time %t ", $time) ;
5968
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5969
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5970
        ok = 0 ;
5971
    end
5972
 
5973
    if ( temp_val1[24] !== 0 )
5974
    begin
5975
        $display("Parity checker testing failed! Time %t ", $time) ;
5976
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5977
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5978
        ok = 0 ;
5979
    end
5980
 
5981
    if ( ok )
5982
        test_ok ;
5983
 
5984
    // clear statuses
5985
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5986
 
5987
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
5988
 
5989
    // do normal write
5990
    fork
5991
    begin
5992
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
5993
               target_address, 32'h1234_5678, `Test_All_Bytes,
5994
               1, 8'h3_0, `Test_One_Zero_Target_WS,
5995
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5996
        do_pause( 1 ) ;
5997
    end
5998
    begin:wait_serr13
5999
        perr_asserted = 0 ;
6000
        @(posedge pci_clock) ;
6001
        while( SERR === 1 )
6002
            @(posedge pci_clock) ;
6003
 
6004
        perr_asserted = 1 ;
6005
        $display("Parity checker testing failed! Time %t ", $time) ;
6006
        $display("SERR asserted for no reason!") ;
6007
        test_fail("SERR was asserted for no reason") ;
6008
    end
6009
    begin
6010
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6011
        if ( ok !== 1 )
6012
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6013
 
6014 35 mihad
        @(posedge pci_clock) ;
6015
        #1 ;
6016
        if ( !perr_asserted )
6017
            disable wait_serr13 ;
6018 15 mihad
    end
6019
    join
6020
 
6021
    if ( ok && !perr_asserted )
6022
        test_ok ;
6023
 
6024
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6025
    `ifdef HOST
6026 26 mihad
        repeat( 4 )
6027
            @(posedge pci_clock) ;
6028 15 mihad
        repeat(4)
6029
            @(posedge wb_clock) ;
6030
        if ( INT_O !== 0 )
6031
        begin
6032
            $display("Parity checker testing failed! Time %t ", $time) ;
6033
            $display("Interrupt request asserted for no reason!") ;
6034
            test_fail("Interrupt request was asserted for no reason") ;
6035
        end
6036
        else
6037
            test_ok ;
6038
    `else
6039
    `ifdef GUEST
6040 26 mihad
        repeat(4)
6041
            @(posedge wb_clock) ;
6042
        repeat(4)
6043 15 mihad
            @(posedge pci_clock) ;
6044
 
6045
        if ( INTA !== 1 )
6046
        begin
6047
            $display("Parity checker testing failed! Time %t ", $time) ;
6048
            $display("Interrupt request asserted for no reason!") ;
6049
            test_fail("Interrupt request was asserted for no reason") ;
6050
        end
6051
        else
6052
            test_ok ;
6053
    `endif
6054
    `endif
6055
 
6056
    // check statuses!
6057
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6058
    ok = 1 ;
6059
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6060
    if ( temp_val1[31] !== 0 )
6061
    begin
6062
        $display("Parity checker testing failed! Time %t ", $time) ;
6063
        $display("Detected Parity Error bit was set for no reason!") ;
6064
        test_fail("Detected Parity Error bit was set for no reason") ;
6065
        ok = 0 ;
6066
    end
6067
 
6068
    if ( temp_val1[30] !== 0 )
6069
    begin
6070
        $display("Parity checker testing failed! Time %t ", $time) ;
6071
        $display("Signalled System Error bit was set for no reason!") ;
6072
        test_fail("Signalled System Error bit was set for no reason") ;
6073
        ok = 0 ;
6074
    end
6075
 
6076
    if ( temp_val1[24] !== 0 )
6077
    begin
6078
        $display("Parity checker testing failed! Time %t ", $time) ;
6079
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6080
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6081
        ok = 0 ;
6082
    end
6083
 
6084
    if ( ok )
6085
        test_ok ;
6086
 
6087
    // clear statuses
6088
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6089
 
6090
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6091
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6092
    ok = 1 ;
6093
 
6094
    if ( temp_val1[4] !== 0 )
6095
    begin
6096
        $display("Parity checker testing failed! Time %t ", $time) ;
6097
        $display("System error interrupt status bit set when not expected!") ;
6098
        test_fail("System error interrupt status bit set when not expected") ;
6099
        ok = 0 ;
6100
    end
6101
 
6102
    if ( temp_val1[3] !== 0 )
6103
    begin
6104
        $display("Parity checker testing failed! Time %t ", $time) ;
6105
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6106
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6107
        ok = 0 ;
6108
    end
6109
 
6110
    if ( ok )
6111
        test_ok ;
6112
 
6113
    // clear statuses
6114
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6115
 
6116
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6117
 
6118
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6119
 
6120
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6121
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6122
 
6123
    // setup target's image!
6124
    target_address  = Target_Base_Addr_R[1] ;
6125
 
6126
    // base address
6127
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6128
 
6129
    // address mask
6130
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6131
 
6132
    // image control
6133
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6134
 
6135
    // enable everything possible for parity checking
6136
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6137
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6138
 
6139
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6140
 
6141
    fork
6142
    begin
6143
        if ( target_mem_image === 1 )
6144
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6145
                   target_address, 32'h1234_5678,
6146
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6147
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6148
        else
6149
            PCIU_IO_WRITE_MAKE_PERR (
6150
                                    `Test_Master_1,
6151
                                    target_address,
6152
                                    32'h1234_5678,
6153
                                    4'h0,
6154
                                    1,
6155
                                    `Test_Target_Normal_Completion
6156
                                    );
6157
 
6158
        do_pause( 1 ) ;
6159
    end
6160
    begin:wait_perr11
6161
        perr_asserted = 0 ;
6162
        @(posedge pci_clock) ;
6163 35 mihad
        while ( PERR !== 0 )
6164 15 mihad
            @(posedge pci_clock) ;
6165
 
6166 35 mihad
        perr_asserted = 1 ;
6167 15 mihad
 
6168
    end
6169
    begin
6170
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6171
 
6172
        if ( ok !== 1 )
6173
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6174
 
6175
        repeat(2)
6176
            @(posedge pci_clock) ;
6177
 
6178 35 mihad
        #1 ;
6179
        if ( !perr_asserted )
6180
            disable wait_perr11 ;
6181 15 mihad
    end
6182
    join
6183
 
6184
    if ( ok && perr_asserted )
6185
        test_ok ;
6186
    else
6187
    if ( !perr_asserted )
6188
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6189
 
6190
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6191
    `ifdef HOST
6192 26 mihad
        repeat (4)
6193
            @(posedge pci_clock) ;
6194 15 mihad
        repeat(4)
6195
            @(posedge wb_clock) ;
6196
        if ( INT_O !== 0 )
6197
        begin
6198
            $display("Parity checker testing failed! Time %t ", $time) ;
6199
            $display("Interrupt request asserted for no reason!") ;
6200
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6201
        end
6202
        else
6203
            test_ok ;
6204
    `else
6205
    `ifdef GUEST
6206 26 mihad
        repeat(4)
6207
            @(posedge wb_clock) ;
6208
        repeat (4)
6209 15 mihad
            @(posedge pci_clock) ;
6210
 
6211
        if ( INTA !== 1 )
6212
        begin
6213
            $display("Parity checker testing failed! Time %t ", $time) ;
6214
            $display("Interrupt request asserted for no reason!") ;
6215
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6216
        end
6217
        else
6218
            test_ok ;
6219
 
6220
    `endif
6221
    `endif
6222
 
6223
    // check statuses!
6224
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6225
    ok = 1 ;
6226
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6227
    if ( temp_val1[31] !== 1 )
6228
    begin
6229
        $display("Parity checker testing failed! Time %t ", $time) ;
6230 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6231
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6232 15 mihad
        ok = 0 ;
6233
    end
6234
 
6235
    if ( temp_val1[30] !== 0 )
6236
    begin
6237
        $display("Parity checker testing failed! Time %t ", $time) ;
6238
        $display("Signalled System Error bit was set for no reason!") ;
6239
        test_fail("Signalled System Error bit was set for no reason") ;
6240
        ok = 0 ;
6241
    end
6242
 
6243
    if ( temp_val1[24] !== 0 )
6244
    begin
6245
        $display("Parity checker testing failed! Time %t ", $time) ;
6246
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6247
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6248
        ok = 0 ;
6249
    end
6250
 
6251
    if ( ok )
6252
        test_ok ;
6253
 
6254
    // clear statuses
6255
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6256
 
6257
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6258
 
6259
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6260
    ok = 1 ;
6261
    if ( temp_val1[4] !== 0 )
6262
    begin
6263
        $display("Parity checker testing failed! Time %t ", $time) ;
6264
        $display("System error interrupt status bit set when not expected!") ;
6265
        test_fail("System error interrupt status bit set when not expected") ;
6266
        ok = 0 ;
6267
    end
6268
 
6269
    if ( temp_val1[3] !== 0 )
6270
    begin
6271
        $display("Parity checker testing failed! Time %t ", $time) ;
6272
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6273
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6274
        ok = 0 ;
6275
    end
6276
 
6277
    if ( ok )
6278
        test_ok ;
6279
 
6280
    // clear statuses
6281
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6282
 
6283
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6284
 
6285
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6286
    fork
6287
    begin
6288
        if ( target_mem_image === 1 )
6289
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6290
                          target_address, 32'h1234_5678,
6291
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6292
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6293
        else
6294
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6295
 
6296
        do_pause( 1 ) ;
6297
    end
6298
    begin:wait_perr12
6299
        perr_asserted = 0 ;
6300
        @(posedge pci_clock) ;
6301 35 mihad
        while ( PERR !== 0 )
6302 15 mihad
            @(posedge pci_clock) ;
6303
 
6304 35 mihad
        perr_asserted = 1 ;
6305 15 mihad
    end
6306
    begin
6307
 
6308
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6309
        if ( ok !== 1 )
6310
        begin
6311
            test_fail("Bridge failed to process Target Memory read correctly") ;
6312
            disable main ;
6313
        end
6314
 
6315
        repeat(3)
6316
            @(posedge pci_clock) ;
6317
 
6318
        if ( target_mem_image === 1 )
6319
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6320
                    target_address, 32'h1234_5678,
6321
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6322
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6323
        else
6324
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6325
 
6326
        do_pause( 1 ) ;
6327
 
6328
    end
6329
    begin
6330
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6331
        if ( ok !== 1 )
6332
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6333
        else
6334
        begin
6335
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6336
            if ( ok !== 1 )
6337
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6338
        end
6339
 
6340 35 mihad
        repeat(2)
6341 15 mihad
            @(posedge pci_clock) ;
6342
 
6343 35 mihad
        #1 ;
6344
        if ( !perr_asserted )
6345
            disable wait_perr12 ;
6346 15 mihad
    end
6347
    join
6348
 
6349
    if ( ok && perr_asserted )
6350
        test_ok ;
6351
    else
6352
    if ( !perr_asserted )
6353
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6354
 
6355
 
6356
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6357
    `ifdef HOST
6358
        repeat(4)
6359 26 mihad
            @(posedge pci_clock) ;
6360
        repeat(4)
6361 15 mihad
            @(posedge wb_clock) ;
6362
        if ( INT_O !== 0 )
6363
        begin
6364
            $display("Parity checker testing failed! Time %t ", $time) ;
6365
            $display("Interrupt request asserted for no reason!") ;
6366
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6367
        end
6368
        else
6369
            test_ok ;
6370
    `else
6371
    `ifdef GUEST
6372 26 mihad
        repeat(4)
6373
            @(posedge wb_clock) ;
6374
        repeat(4)
6375 15 mihad
            @(posedge pci_clock) ;
6376
 
6377
        if ( INTA !== 1 )
6378
        begin
6379
            $display("Parity checker testing failed! Time %t ", $time) ;
6380
            $display("Interrupt request asserted for no reason!") ;
6381
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6382
        end
6383
        else
6384
            test_ok ;
6385
    `endif
6386
    `endif
6387
 
6388
    // check statuses!
6389
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6390
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6391
    ok = 1 ;
6392 45 mihad
    if ( temp_val1[31] !== 0 )
6393 15 mihad
    begin
6394
        $display("Parity checker testing failed! Time %t ", $time) ;
6395 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6396
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6397 15 mihad
        ok = 0 ;
6398
    end
6399
 
6400
    if ( temp_val1[30] !== 0 )
6401
    begin
6402
        $display("Parity checker testing failed! Time %t ", $time) ;
6403
        $display("Signalled System Error bit was set for no reason!") ;
6404
        test_fail("Signalled System Error bit was set for no reason") ;
6405
        ok = 0 ;
6406
    end
6407
 
6408
    if ( temp_val1[24] !== 0 )
6409
    begin
6410
        $display("Parity checker testing failed! Time %t ", $time) ;
6411
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6412
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6413
        ok = 0 ;
6414
    end
6415
 
6416
    if ( ok )
6417
        test_ok ;
6418
 
6419
    // clear statuses
6420
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6421
 
6422
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6423
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6424
    ok = 1 ;
6425
    if ( temp_val1[4] !== 0 )
6426
    begin
6427
        $display("Parity checker testing failed! Time %t ", $time) ;
6428
        $display("System error interrupt status bit set when not expected!") ;
6429
        test_fail("System error interrupt status bit set when not expected") ;
6430
        ok = 0 ;
6431
    end
6432
 
6433
    if ( temp_val1[3] !== 0 )
6434
    begin
6435
        $display("Parity checker testing failed! Time %t ", $time) ;
6436
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6437
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6438
        ok = 0 ;
6439
    end
6440
 
6441
    if ( ok )
6442
        test_ok ;
6443
    // clear statuses
6444
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6445
 
6446
    $fdisplay(pci_mon_log_file_desc,
6447
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6448
    test_name = "DISABLE USED IMAGES" ;
6449
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6450
    if ( ok !== 1 )
6451
    begin
6452
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6453
        test_fail("WB Image Address Mask register could not be written to") ;
6454
        disable main ;
6455
    end
6456
 
6457 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6458 15 mihad
    if ( ok !== 1 )
6459
    begin
6460
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6461
        test_fail("PCI Image Address Mask register could not be written to") ;
6462
        disable main ;
6463
    end
6464
 
6465
    // disable target's 1 response to parity errors
6466 45 mihad
    configuration_cycle_write(0,                        // bus number
6467
                              `TAR1_IDSEL_INDEX - 11,   // device number
6468
                              0,                        // function number
6469
                              1,                        // register number
6470
                              0,                        // type of configuration cycle
6471
                              4'b0001,                  // byte enables
6472
                              32'h0000_0007             // data
6473 15 mihad
                             ) ;
6474
 
6475
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6476
end
6477
endtask // parity_checking
6478
 
6479
task wb_to_pci_transactions ;
6480
    reg   [11:0] ctrl_offset ;
6481
    reg   [11:0] ba_offset ;
6482
    reg   [11:0] am_offset ;
6483
    reg   [11:0] pci_ctrl_offset ;
6484
    reg   [11:0] err_cs_offset ;
6485
    reg   [11:0] icr_offset ;
6486
    reg   [11:0] isr_offset ;
6487
    reg   [11:0] lat_tim_cls_offset ;
6488
 
6489
    reg `WRITE_STIM_TYPE  write_data ;
6490
    reg `READ_STIM_TYPE   read_data ;
6491
    reg `READ_RETURN_TYPE read_status ;
6492
 
6493
    reg `WRITE_RETURN_TYPE write_status ;
6494
    reg `WB_TRANSFER_FLAGS write_flags ;
6495
    reg [31:0] temp_val1 ;
6496
    reg [31:0] temp_val2 ;
6497
    reg        ok   ;
6498
 
6499
    reg [31:0] image_base ;
6500
    reg [31:0] target_address ;
6501
    integer i ;
6502
    integer required_reads ;
6503
    integer writes_left ;
6504
 
6505
begin:main
6506
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6507
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6508
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6509
    pci_ctrl_offset    = 12'h4 ;
6510
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6511
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6512
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6513
    lat_tim_cls_offset = 12'hC ;
6514
 
6515
    $display("Checking WB to PCI transaction lengths!") ;
6516
    target_address  = `BEH_TAR1_MEM_START ;
6517
    image_base      = 0 ;
6518
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6519
 
6520
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6521
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6522
    write_flags                    = 0 ;
6523
    write_flags`INIT_WAITS         = tb_init_waits ;
6524
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6525
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6526
 
6527
    // enable master & target operation
6528
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6529
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6530
    if ( ok !== 1 )
6531
    begin
6532
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6533
        test_fail("write to PCI Device Control register failed") ;
6534
        disable main ;
6535
    end
6536
 
6537
    // prepare image control register
6538
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6539
    if ( ok !== 1 )
6540
    begin
6541
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6542
        test_fail("write to WB Image Control register failed") ;
6543
        disable main ;
6544
    end
6545
 
6546
    // prepare base address register
6547
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6548
    if ( ok !== 1 )
6549
    begin
6550
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6551
        test_fail("write to WB Base Address register failed") ;
6552
        disable main ;
6553
    end
6554
 
6555
    // write address mask register
6556
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6557
    if ( ok !== 1 )
6558
    begin
6559
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6560
        test_fail("write to WB Address Mask register failed") ;
6561
        disable main ;
6562
    end
6563
 
6564
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6565
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6566
    if ( ok !== 1 )
6567
    begin
6568
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6569
        test_fail("write to WB Error Control and Status register failed") ;
6570
        disable main ;
6571
    end
6572
 
6573
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6574
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6575
    if ( ok !== 1 )
6576
    begin
6577
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6578
        test_fail("write to Interrupt Control register failed") ;
6579
        disable main ;
6580
    end
6581
 
6582
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6583
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6584
    if ( ok !== 1 )
6585
    begin
6586
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6587
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6588
        disable main ;
6589
    end
6590
 
6591
    $display("Testing single write transaction progress from WB to PCI!") ;
6592
    write_data`WRITE_ADDRESS = target_address ;
6593
    write_data`WRITE_DATA    = wmem_data[0] ;
6594
    write_data`WRITE_SEL     = 4'hF ;
6595
 
6596
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6597
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6598
 
6599
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6600
    fork
6601
    begin
6602
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6603
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6604
        begin
6605
            $display("Transaction progress testing failed! Time %t ", $time) ;
6606
            $display("Bridge failed to process single memory write!") ;
6607
            test_fail("bridge failed to post single memory write") ;
6608
            disable main ;
6609
        end
6610
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6611
    end
6612
    begin
6613
        // wait two retries, then enable target response
6614
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6615
        if ( ok !== 1 )
6616
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6617
        else
6618
            test_ok ;
6619
 
6620
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6621
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6622
        if ( ok !== 1 )
6623
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6624
        else
6625
            test_ok ;
6626
 
6627
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6628
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6629
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6630
 
6631
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6632
        if ( ok !== 1 )
6633
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6634
        else
6635
            test_ok ;
6636
    end
6637
    join
6638
 
6639
    $display("Testing burst write transaction progress from WB to PCI!") ;
6640
    write_data`WRITE_ADDRESS = target_address ;
6641
    write_data`WRITE_DATA    = wmem_data[0] ;
6642
    write_data`WRITE_SEL     = 4'hF ;
6643
 
6644
    wishbone_master.blk_write_data[0] = write_data ;
6645
 
6646
    write_data`WRITE_ADDRESS = target_address + 4 ;
6647
    write_data`WRITE_DATA    = wmem_data[1] ;
6648
    write_data`WRITE_SEL     = 4'hF ;
6649
 
6650
    wishbone_master.blk_write_data[1] = write_data ;
6651
 
6652
    write_flags`WB_TRANSFER_SIZE = 2 ;
6653
    write_flags`WB_TRANSFER_CAB  = 1 ;
6654
 
6655
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6656
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6657
 
6658
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6659
 
6660
    fork
6661
    begin
6662
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6663
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6664
        begin
6665
            $display("Transaction progress testing failed! Time %t ", $time) ;
6666
            $display("Bridge failed to process whole CAB memory write!") ;
6667
            test_fail("bridge failed to post whole CAB memory write") ;
6668
            disable main ;
6669
        end
6670
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6671
    end
6672
    begin
6673
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6674
        if ( ok !== 1 )
6675
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6676
        else
6677
            test_ok ;
6678
 
6679
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6680
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6681
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6682
 
6683
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6684
        if ( ok !== 1 )
6685
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6686
        else
6687
            test_ok ;
6688
 
6689
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6690
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6691
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6692
 
6693
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6694
        if ( ok !== 1 )
6695
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6696
        else
6697
            test_ok ;
6698
    end
6699
    join
6700
 
6701
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6702
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6703
 
6704
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6705
    // try same write with other terminations
6706
    fork
6707
    begin
6708
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6709
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6710
        begin
6711
            $display("Transaction progress testing failed! Time %t ", $time) ;
6712
            $display("Bridge failed to process whole CAB memory write!") ;
6713
            test_fail("bridge failed to post whole CAB memory write") ;
6714
            disable main ;
6715
        end
6716
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6717
    end
6718
    begin
6719
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6720
        if ( ok !== 1 )
6721
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6722
        else
6723
            test_ok ;
6724
 
6725
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6726
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6727
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6728
 
6729
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6730
        if ( ok !== 1 )
6731
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6732
        else
6733
            test_ok ;
6734
    end
6735
    join
6736
 
6737
    // repeat the write with normal completion
6738
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6739
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6740
 
6741
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6742
    fork
6743
    begin
6744
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6745
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6746
        begin
6747
            $display("Transaction progress testing failed! Time %t ", $time) ;
6748
            $display("Bridge failed to process whole CAB memory write!") ;
6749
            test_fail("bridge failed to post whole CAB memory write") ;
6750
            disable main ;
6751
        end
6752
    end
6753
    begin
6754
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6755
        if ( ok !== 1 )
6756
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6757
        else
6758
            test_ok ;
6759
    end
6760
    join
6761
 
6762
    // do the same thing with burst length of 3
6763
    write_data`WRITE_ADDRESS = target_address + 8 ;
6764
    write_data`WRITE_DATA    = wmem_data[2] ;
6765
    write_data`WRITE_SEL     = 4'hF ;
6766
 
6767
    wishbone_master.blk_write_data[2] = write_data ;
6768
 
6769
    write_flags`WB_TRANSFER_SIZE = 3 ;
6770
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6771
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6772
 
6773
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6774
 
6775
    fork
6776
    begin
6777
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6778
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6779
        begin
6780
            $display("Transaction progress testing failed! Time %t ", $time) ;
6781
            $display("Bridge failed to process whole CAB memory write!") ;
6782
            test_fail("bridge failed to post whole CAB memory write") ;
6783
            disable main ;
6784
        end
6785
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6786
    end
6787
    begin
6788
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6789
        if ( ok !== 1 )
6790
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6791
        else
6792
            test_ok ;
6793
 
6794
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6795
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6796
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6797
 
6798
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6799
        if ( ok !== 1 )
6800
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6801
        else
6802
            test_ok ;
6803
    end
6804
    join
6805
 
6806
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6807
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6808
 
6809
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6810
    fork
6811
    begin
6812
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6813
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6814
        begin
6815
            $display("Transaction progress testing failed! Time %t ", $time) ;
6816
            $display("Bridge failed to process whole CAB memory write!") ;
6817
            test_fail("bridge failed to post whole CAB memory write") ;
6818
            disable main ;
6819
        end
6820
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6821
    end
6822
    begin
6823
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6824
        if ( ok !== 1 )
6825
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6826
        else
6827
            test_ok ;
6828
 
6829
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6830
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6831
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6832
 
6833
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6834
        if ( ok !== 1 )
6835
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6836
        else
6837
            test_ok ;
6838
 
6839
    end
6840
    join
6841
 
6842
    // repeat with normal completion
6843
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6844
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6845
 
6846
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6847
    fork
6848
    begin
6849
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6850
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6851
        begin
6852
            $display("Transaction progress testing failed! Time %t ", $time) ;
6853
            $display("Bridge failed to process whole CAB memory write!") ;
6854
            test_fail("bridge failed to post whole CAB memory write") ;
6855
            disable main ;
6856
        end
6857
    end
6858
    begin
6859
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6860
        if ( ok !== 1 )
6861
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6862
        else
6863
            test_ok ;
6864
 
6865
    end
6866
    join
6867
 
6868
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6869
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6870
    begin
6871
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6872
        write_data`WRITE_DATA    = wmem_data[i] ;
6873
        write_data`WRITE_SEL     = 4'hF ;
6874
 
6875
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6876
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6877
 
6878
        wishbone_master.blk_write_data[i]   = write_data ;
6879
        wishbone_master.blk_read_data_in[i] = read_data ;
6880
    end
6881
 
6882
    write_flags`WB_TRANSFER_CAB      = 1 ;
6883
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6884
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6885
 
6886
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6887
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6888
 
6889
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6890
    fork
6891
    begin
6892
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6893
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6894
        begin
6895
            $display("Transaction progress testing failed! Time %t ", $time) ;
6896
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6897
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6898
            test_fail("bridge failed to post whole CAB memory write") ;
6899
            disable main ;
6900
        end
6901
 
6902
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6903
 
6904
        // read here just checks if data was transfered OK
6905
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6906
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6907
 
6908
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6909
 
6910
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6911
        begin
6912
            $display("Transaction progress testing failed! Time %t ", $time) ;
6913
            $display("Bridge processed CAB read wrong!") ;
6914
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6915
        end
6916
 
6917
    end
6918
    begin
6919
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6920
        if ( ok !== 1 )
6921
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6922
        else
6923
            test_ok ;
6924
 
6925
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6926
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6927
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6928
 
6929
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6930
        if ( ok !== 1 )
6931
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6932
        else
6933
            test_ok ;
6934
 
6935
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6936
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6937
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6938
 
6939
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6940
        if ( ok !== 1 )
6941
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6942
        else
6943
            test_ok ;
6944
 
6945
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6946
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6947
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6948
 
6949
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6950
        if ( ok !== 1 )
6951
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6952
        else
6953
            test_ok ;
6954
 
6955
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6956
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6957
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6958
 
6959
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6960
        if ( ok !== 1 )
6961
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6962
        else
6963
            test_ok ;
6964
 
6965
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
6966
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
6967
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
6968
        for ( i = 0 ; i < required_reads ; i = i + 1 )
6969
        begin
6970
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
6971
            if ( ok !== 1 )
6972
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6973
        end
6974
    end
6975
    join
6976
 
6977
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
6978
    begin
6979
        read_status = wishbone_master.blk_read_data_out[i] ;
6980
        if (read_status`READ_DATA !== wmem_data[i])
6981
        begin
6982
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
6983
            test_fail("data read from target wasn't the same as data written to it") ;
6984
            ok = 0 ;
6985
        end
6986
    end
6987
 
6988
    if ( ok )
6989
        test_ok ;
6990
 
6991
    $display("Testing single read transaction progress from WB to PCI!") ;
6992
    read_data`READ_ADDRESS = target_address + 8 ;
6993
    read_data`READ_SEL     = 4'hF ;
6994
 
6995
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6996
 
6997
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
6998
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6999
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7000
 
7001
    fork
7002
    begin
7003
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7004
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7005
        begin
7006
            $display("Transaction progress testing failed! Time %t ", $time) ;
7007
            $display("Bridge processed single read wrong!") ;
7008
            test_fail("bridge processed single read wrong") ;
7009
            disable main ;
7010
        end
7011
 
7012
        if (read_status`READ_DATA !== wmem_data[2])
7013
        begin
7014
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7015
            test_fail("data returned from single read was not as expected") ;
7016
        end
7017
        else
7018
        if ( ok )
7019
            test_ok ;
7020
    end
7021
    begin
7022
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7023
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7024
 
7025
        if ( ok !== 1 )
7026
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7027
 
7028
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7029
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7030
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7031
 
7032
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7033
        if ( ok !== 1 )
7034
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7035
    end
7036
    join
7037
 
7038
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7039
 
7040
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7041
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7042
 
7043
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7044
    // first fill target's memory with enough data to fill WBR_FIFO
7045
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7046
    begin
7047
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7048
        write_data`WRITE_DATA    = wmem_data[i] ;
7049
        write_data`WRITE_SEL     = 4'hF ;
7050
 
7051
        wishbone_master.blk_write_data[i] = write_data ;
7052
    end
7053
 
7054
    write_flags`WB_TRANSFER_CAB = 1 ;
7055
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7056
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7057
 
7058
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7059
 
7060
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7061
    begin
7062
        $display("Transaction progress testing failed! Time %t ", $time) ;
7063
        $display("Bridge processed CAB write wrong!") ;
7064
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7065
        disable main ;
7066
    end
7067
 
7068
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7069
    // perform single read to force write data to pci
7070
    read_data`READ_ADDRESS = target_address + 8;
7071
    read_data`READ_SEL     = 4'hF ;
7072
 
7073
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7074
 
7075
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7076
    begin
7077
        $display("Transaction progress testing failed! Time %t ", $time) ;
7078
        $display("Bridge processed single read wrong!") ;
7079
        test_fail("bridge didn't process single memory read as expected") ;
7080
        disable main ;
7081
    end
7082
 
7083
    wishbone_master.blk_read_data_in[0] = read_data ;
7084
 
7085
    read_data`READ_ADDRESS = target_address + 12 ;
7086
    read_data`READ_SEL     = 4'hF ;
7087
 
7088
    wishbone_master.blk_read_data_in[1] = read_data ;
7089
 
7090
    read_data`READ_ADDRESS = target_address + 16 ;
7091
    read_data`READ_SEL     = 4'hF ;
7092
 
7093
    wishbone_master.blk_read_data_in[2] = read_data ;
7094
 
7095
    write_flags`WB_TRANSFER_CAB  = 1 ;
7096
    write_flags`WB_TRANSFER_SIZE = 2 ;
7097
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7098
    read_status = 0 ;
7099
 
7100
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7101
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7102
 
7103
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7104
 
7105
    ok = 1 ;
7106
    fork
7107
    begin
7108
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7109
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7110
 
7111
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7112
        begin
7113
            $display("Transaction progress testing failed! Time %t ", $time) ;
7114
            $display("Bridge processed CAB read wrong!") ;
7115
            test_fail("bridge didn't process disconnected burst read as expected") ;
7116
        end
7117
        else
7118
        begin
7119
 
7120
            read_status = wishbone_master.blk_read_data_out[0] ;
7121
 
7122
            if (read_status`READ_DATA !== wmem_data[2])
7123
            begin
7124
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7125
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7126
            end
7127
            else
7128
                test_ok ;
7129
        end
7130
 
7131
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7132
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7133
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7134
 
7135
        read_status = 0 ;
7136
 
7137
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7138
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7139
 
7140
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7141
        begin
7142
            $display("Transaction progress testing failed! Time %t ", $time) ;
7143
            $display("Bridge processed CAB read wrong!") ;
7144
            test_fail("bridge didn't process disconnected burst read as expected") ;
7145
        end
7146
        else
7147
        begin
7148
 
7149
            read_status = wishbone_master.blk_read_data_out[0] ;
7150
 
7151
            if (read_status`READ_DATA !== wmem_data[3])
7152
            begin
7153
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7154
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7155
            end
7156
            else
7157
                test_ok ;
7158
        end
7159
 
7160
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7161
        // complete delayed read which was requested
7162
        read_data = wishbone_master.blk_read_data_in[2] ;
7163
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7164
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7165
 
7166
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7167
        begin
7168
            $display("Transaction progress testing failed! Time %t ", $time) ;
7169
            $display("Bridge processed single out of burst read wrong!") ;
7170
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7171
        end
7172
        else
7173
        begin
7174
 
7175
            if (read_status`READ_DATA !== wmem_data[4])
7176
            begin
7177
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7178
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7179
            end
7180
            else
7181
                test_ok ;
7182
        end
7183
 
7184
    end
7185
    begin
7186
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7187
 
7188
        if ( ok !== 1 )
7189
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7190
 
7191
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7192
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7193
 
7194
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7195
        if ( ok !== 1 )
7196
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7197
 
7198
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7199
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7200
 
7201
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7202
        if ( ok !== 1 )
7203
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7204
    end
7205
    join
7206
 
7207
    // now try burst read with normal termination
7208
    read_data`READ_ADDRESS = target_address + 12 ;
7209
    read_data`READ_SEL     = 4'hF ;
7210
 
7211
    wishbone_master.blk_read_data_in[0] = read_data ;
7212
 
7213
    read_data`READ_ADDRESS = target_address + 16 ;
7214
    read_data`READ_SEL     = 4'hF ;
7215
 
7216
    wishbone_master.blk_read_data_in[1] = read_data ;
7217
 
7218
    write_flags`WB_TRANSFER_SIZE = 2 ;
7219
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7220
    write_flags`WB_TRANSFER_CAB = 1 ;
7221
 
7222
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7223
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7224
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7225
 
7226
    fork
7227
    begin
7228
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7229
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7230
        begin
7231
            $display("Transaction progress testing failed! Time %t ", $time) ;
7232
            $display("Bridge processed CAB read wrong!") ;
7233
            test_fail("bridge didn't process burst read as expected") ;
7234
            ok = 0 ;
7235
        end
7236
    end
7237
    begin
7238
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7239
        if ( ok !== 1 )
7240
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7241
    end
7242
    join
7243
 
7244
    if ( ok )
7245
    begin
7246
        read_status = wishbone_master.blk_read_data_out[0] ;
7247
        if ( read_status`READ_DATA !== wmem_data[3] )
7248
        begin
7249
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7250
            test_fail("data provided from normaly terminated read was wrong") ;
7251
            ok = 0 ;
7252
        end
7253
 
7254
        read_status = wishbone_master.blk_read_data_out[1] ;
7255
        if ( read_status`READ_DATA !== wmem_data[4] )
7256
        begin
7257
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7258
            test_fail("data provided from normaly terminated read was wrong") ;
7259
            ok = 0 ;
7260
        end
7261
    end
7262
 
7263
    if ( ok )
7264
        test_ok ;
7265
 
7266
    // disable memory read line command and enable prefetch
7267
    // prepare image control register
7268
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7269
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7270
    if ( ok !== 1 )
7271
    begin
7272
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7273
        test_fail("WB Image Control register couldn't be written to") ;
7274
        disable main ;
7275
    end
7276
 
7277
    write_flags`WB_TRANSFER_SIZE = 4 ;
7278
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7279
    write_flags`WB_TRANSFER_CAB = 1 ;
7280
 
7281
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7282
 
7283
    for ( i = 0 ; i < 4 ; i = i + 1 )
7284
    begin
7285
        read_data`READ_ADDRESS = target_address + i*4 ;
7286
        read_data`READ_SEL     = 4'b1010 ;
7287
 
7288
        wishbone_master.blk_read_data_in[i] = read_data ;
7289
    end
7290
 
7291
    fork
7292
    begin
7293
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7294
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7295
        begin
7296
            $display("Transaction progress testing failed! Time %t ", $time) ;
7297
            $display("Bridge processed CAB read wrong!") ;
7298
            test_fail("bridge didn't process prefetched burst read as expected") ;
7299
            ok = 0 ;
7300
        end
7301
    end
7302
    begin
7303
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7304
        if ( ok !== 1 )
7305
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7306
    end
7307
    join
7308
 
7309
    if ( ok )
7310
    begin
7311
        for ( i = 0 ; i < 4 ; i = i + 1 )
7312
        begin
7313
            read_status = wishbone_master.blk_read_data_out[i] ;
7314
            if ( read_status`READ_DATA !== wmem_data[i] )
7315
            begin
7316
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7317
                test_fail("burst read returned unexpected data") ;
7318
                ok = 0 ;
7319
            end
7320
        end
7321
    end
7322
 
7323
    if ( ok )
7324
        test_ok ;
7325
 
7326
    // do one single read with different byte enables
7327
    read_data`READ_ADDRESS = target_address + 4 ;
7328
    read_data`READ_SEL     = 4'b1010 ;
7329
 
7330
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7331
    fork
7332
    begin
7333
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7334
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7335
        begin
7336
            $display("Transaction progress testing failed! Time %t ", $time) ;
7337
            $display("Bridge processed single read wrong!") ;
7338
            test_fail("bridge didn't process single memory read as expected") ;
7339
            ok = 0 ;
7340
        end
7341
    end
7342
    begin
7343
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7344
        if ( ok !== 1 )
7345
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7346
    end
7347
    join
7348
 
7349
    // check read data
7350
    if ( ok )
7351
    begin
7352
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7353
        begin
7354
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7355
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7356
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7357
            ok = 0 ;
7358
            test_fail("unexpected data received from single read") ;
7359
        end
7360
    end
7361
 
7362
    if ( ok )
7363
         test_ok ;
7364
 
7365
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7366
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7367
 
7368
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7369
    if ( ok !== 1 )
7370
    begin
7371
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7372
        test_fail("WB Image Control register could not be written") ;
7373
        disable main ;
7374
    end
7375
 
7376
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7377
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7378
    begin
7379
        read_data`READ_ADDRESS = target_address + i*4 ;
7380
        read_data`READ_SEL     = 4'b1111 ;
7381
 
7382
        wishbone_master.blk_read_data_in[i] = read_data ;
7383
    end
7384
 
7385
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7386
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7387
    write_flags`WB_TRANSFER_CAB = 1 ;
7388
 
7389
    fork
7390
    begin
7391
        read_status         = 0 ;
7392
        read_status`CYC_RTY = 1 ;
7393
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7394
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7395
 
7396
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7397
        begin
7398
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7399
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7400
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7401
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7402
            ok = 0 ;
7403
        end
7404
    end
7405
    begin
7406
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7407
        if ( ok !== 1 )
7408
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7409
    end
7410
    join
7411
 
7412
    // now repeat single read to flush redundant read initiated
7413
    write_flags`WB_TRANSFER_SIZE = 1 ;
7414
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7415
    write_flags`WB_TRANSFER_CAB = 1 ;
7416
 
7417
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7418
    read_data`READ_SEL     = 4'hF ;
7419
 
7420
    wishbone_master.blk_read_data_in[0] = read_data ;
7421
 
7422
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7423
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7424
 
7425
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7426
    begin
7427
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7428
        $display(" PCI bridge failed to process single CAB read!") ;
7429
        test_fail("single CAB write was not processed as expected") ;
7430
    end
7431
 
7432
    // because last read could be very long on PCI - delete target abort status
7433
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7434
 
7435
    // write unsupported value to cache line size register
7436
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7437
 
7438
    read_data`READ_ADDRESS = target_address ;
7439
    read_data`READ_SEL     = 4'hF ;
7440
    wishbone_master.blk_read_data_in[0] = read_data ;
7441
 
7442
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7443
    // perform a read
7444
    fork
7445
    begin
7446
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7447
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7448
        begin
7449
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7450
            $display(" PCI bridge failed to process single CAB read!") ;
7451
            test_fail("burst read was not processed as expected") ;
7452
            ok = 0 ;
7453
        end
7454
    end
7455
    begin
7456
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7457
        if ( ok !== 1 )
7458
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7459
    end
7460
    join
7461
 
7462
    if ( ok )
7463
        test_ok ;
7464
 
7465
    // write 2 to cache line size register
7466
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7467
 
7468
    // perform a read
7469
    fork
7470
    begin
7471
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7472
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7473
        begin
7474
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7475
            $display(" PCI bridge failed to process single CAB read!") ;
7476
            test_fail("burst read was not processed as expected") ;
7477
            ok = 0 ;
7478
        end
7479
    end
7480
    begin
7481
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7482
        if ( ok !== 1 )
7483
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7484
    end
7485
    join
7486
 
7487
    if ( ok )
7488
        test_ok ;
7489
 
7490
    // write 0 to cache line size
7491
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7492
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7493
 
7494
    // perform a read
7495
    fork
7496
    begin
7497
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7498
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7499
        begin
7500
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7501
            $display(" PCI bridge failed to process single CAB read!") ;
7502
            test_fail("burst read was not processed as expected") ;
7503
            ok = 0 ;
7504
        end
7505
    end
7506
    begin
7507
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7508
        if ( ok !== 1 )
7509
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7510
    end
7511
    join
7512
 
7513
    if ( ok )
7514
        test_ok ;
7515
 
7516
    // write normal value to cls register
7517
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7518
 
7519
    $display("Testing Master's latency timer operation!") ;
7520
    $display("Testing Latency timer during Master Writes!") ;
7521
 
7522
    for ( i = 0 ; i < 6 ; i = i + 1 )
7523
    begin
7524
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7525
        write_data`WRITE_SEL     = 4'b1111 ;
7526
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7527
 
7528
        wishbone_master.blk_write_data[i] = write_data ;
7529
    end
7530
 
7531
    write_flags`WB_TRANSFER_SIZE = 6 ;
7532
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7533
    write_flags`WB_TRANSFER_CAB = 1 ;
7534
 
7535
    // start wb write, pci write and monitor in parallel
7536
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7537
    fork
7538
    begin
7539
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7540
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7541
        begin
7542
            $display("Transaction progress testing failed! Time %t ", $time) ;
7543
            $display("Bridge failed to process CAB write!") ;
7544
            test_fail("bridge didn't post whole burst memory write") ;
7545
            disable main ;
7546
        end
7547
    end
7548
    begin
7549
        // wait for bridge's master to start transaction
7550
        @(posedge pci_clock) ;
7551
        while ( FRAME === 1 )
7552
            @(posedge pci_clock) ;
7553
 
7554
        // start behavioral master request
7555
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7556
               target_address, wmem_data[1023], `Test_All_Bytes,
7557
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7558
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7559
 
7560
        do_pause ( 1 ) ;
7561
    end
7562
    begin
7563
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7564
        if ( ok !== 1 )
7565
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7566
        else
7567
            test_ok ;
7568
    end
7569
    join
7570
 
7571
    // perform a read to check data
7572
    for ( i = 0 ; i < 6 ; i = i + 1 )
7573
    begin
7574
        read_data`READ_ADDRESS = target_address + i*4 ;
7575
        read_data`READ_SEL     = 4'b1111 ;
7576
 
7577
        wishbone_master.blk_read_data_in[i] = read_data ;
7578
    end
7579
 
7580
    write_flags`WB_TRANSFER_SIZE = 6 ;
7581
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7582
    write_flags`WB_TRANSFER_CAB = 1 ;
7583
 
7584
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7585
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7586
 
7587
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7588
    begin
7589
        $display("Transaction progress testing failed! Time %t ", $time) ;
7590
        $display("Bridge failed to process CAB read!") ;
7591
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7592
        disable main ;
7593
    end
7594
 
7595
    ok = 1 ;
7596
    for ( i = 0 ; i < 6 ; i = i + 1 )
7597
    begin
7598
        read_status = wishbone_master.blk_read_data_out[i] ;
7599
 
7600
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7601
        begin
7602
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7603
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7604
            test_fail("unexpected data read back from PCI") ;
7605
            ok = 0 ;
7606
        end
7607
    end
7608
 
7609
    if ( ok )
7610
        test_ok ;
7611
 
7612
    $display("Testing Latency timer during Master Reads!") ;
7613
 
7614
    // at least 2 words are transfered during Master Reads terminated with timeout
7615
    write_flags`WB_TRANSFER_SIZE = 2 ;
7616
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7617
    fork
7618
    begin
7619
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7620
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7621
        begin
7622
            $display("Transaction progress testing failed! Time %t ", $time) ;
7623
            $display("Bridge failed to process CAB read!") ;
7624
            test_fail("bridge didn't process burst read as expected") ;
7625
            ok = 0 ;
7626
        end
7627
    end
7628
    begin
7629
        // wait for bridge's master to start transaction
7630
        @(posedge pci_clock) ;
7631
        while ( FRAME === 1 )
7632
            @(posedge pci_clock) ;
7633
 
7634
        // start behavioral master request
7635
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7636
               target_address, wmem_data[0], `Test_All_Bytes,
7637
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7638
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7639
 
7640
        do_pause ( 1 ) ;
7641
    end
7642
    begin
7643
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7644
        if ( ok !== 1 )
7645
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7646
    end
7647
    join
7648
 
7649
    // check data provided by target
7650
    if ( ok )
7651
    begin
7652
        for ( i = 0 ; i < 2 ; i = i + 1 )
7653
        begin
7654
            read_status = wishbone_master.blk_read_data_out[i] ;
7655
 
7656
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7657
            begin
7658
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7659
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7660
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7661
                ok = 0 ;
7662
            end
7663
        end
7664
    end
7665
    if ( ok )
7666
        test_ok ;
7667
 
7668
    test_name = "DISABLE_IMAGE" ;
7669
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7670
    if ( ok !== 1 )
7671
    begin
7672
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7673
        test_fail("write to WB Address Mask register failed") ;
7674
        disable main ;
7675
    end
7676
 
7677
end
7678
endtask //wb_to_pci_transactions
7679
 
7680
task iack_cycle ;
7681
    reg `READ_STIM_TYPE   read_data ;
7682
    reg `READ_RETURN_TYPE read_status ;
7683
    reg `WB_TRANSFER_FLAGS flags ;
7684
 
7685
    reg [31:0] temp_var ;
7686
    reg ok ;
7687 45 mihad
    reg ok_wb ;
7688
    reg ok_pci ;
7689
 
7690
    reg [31:0] irq_vector ;
7691 15 mihad
begin
7692
 
7693 45 mihad
    ok     = 1 ;
7694
    ok_wb  = 1 ;
7695
    ok_pci = 1 ;
7696
 
7697 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7698
 
7699
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7700
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7701
 
7702
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7703
    read_data`READ_SEL     = 4'hF ;
7704
 
7705
    flags = 0 ;
7706
 
7707
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7708
 
7709
    irq_vector  = 32'hAAAA_AAAA ;
7710
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7711
 
7712 45 mihad
    // disable both pci blue behavioral targets
7713
    configuration_cycle_write
7714
    (
7715
        0,                          // bus number [7:0]
7716
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7717
        0,                          // function number [2:0]
7718
        1,                          // register number [5:0]
7719
        0,                          // type [1:0]
7720
        4'h1,                       // byte enables [3:0]
7721
        32'h0000_0044               // data to write [31:0]
7722
    ) ;
7723
 
7724
    configuration_cycle_write
7725
    (
7726
        0,                          // bus number [7:0]
7727
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7728
        0,                          // function number [2:0]
7729
        1,                          // register number [5:0]
7730
        0,                          // type [1:0]
7731
        4'h1,                       // byte enables [3:0]
7732
        32'h0000_0044               // data to write [31:0]
7733
    ) ;
7734
 
7735 15 mihad
    fork
7736
    begin
7737
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7738
    end
7739
    begin
7740 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7741
        if ( ok_pci !== 1 )
7742 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7743
    end
7744
    join
7745
 
7746
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7747
    begin
7748 45 mihad
        ok_wb = 0 ;
7749 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7750
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7751
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7752
    end
7753 45 mihad
 
7754
    if ( ok_pci && ok_wb )
7755 15 mihad
        test_ok ;
7756 45 mihad
 
7757
    ok_wb = 1 ;
7758
    ok_pci = 1 ;
7759
    ok = 1 ;
7760 15 mihad
 
7761 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7762
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7763 15 mihad
 
7764
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7765 45 mihad
    // enable pci blue behavioral target 1
7766
    configuration_cycle_write
7767
    (
7768
        0,                          // bus number [7:0]
7769
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7770
        0,                          // function number [2:0]
7771
        1,                          // register number [5:0]
7772
        0,                          // type [1:0]
7773
        4'h1,                       // byte enables [3:0]
7774
        32'h0000_0047               // data to write [31:0]
7775
    ) ;
7776 15 mihad
    fork
7777
    begin
7778
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7779
    end
7780
    begin
7781 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7782
        if ( ok_pci !== 1 )
7783 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7784
    end
7785
    join
7786
 
7787
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7788
    begin
7789 45 mihad
        ok_wb = 0 ;
7790 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7791
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7792
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7793
    end
7794
 
7795
    if ( read_status`READ_DATA !== irq_vector )
7796
    begin
7797
        $display(" Time %t ", $time ) ;
7798
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7799
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7800 45 mihad
        ok_wb = 0 ;
7801 15 mihad
    end
7802
 
7803 45 mihad
    if ( ok_pci && ok_wb )
7804 15 mihad
        test_ok ;
7805
 
7806 45 mihad
    ok_pci = 1 ;
7807
    ok_wb  = 1 ;
7808
    ok     = 1 ;
7809
 
7810 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7811 45 mihad
    irq_vector  = 32'h5555_5555 ;
7812
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7813
 
7814 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7815
    fork
7816
    begin
7817
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7818
    end
7819
    begin
7820 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7821
        if ( ok_pci !== 1 )
7822 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7823
    end
7824
    join
7825
 
7826
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7827
    begin
7828
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7829
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7830
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7831 45 mihad
        ok_wb = 0 ;
7832 15 mihad
    end
7833
 
7834 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7835 15 mihad
    begin
7836
        $display(" Time %t ", $time ) ;
7837 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7838 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7839 45 mihad
        ok_wb = 0 ;
7840 15 mihad
    end
7841
 
7842 45 mihad
    if (ok_pci && ok_wb)
7843 15 mihad
        test_ok ;
7844
 
7845 45 mihad
    ok_pci = 1 ;
7846
    ok_wb  = 1 ;
7847
    ok     = 1 ;
7848 15 mihad
 
7849 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7850
 
7851
    // set target to terminate with target abort
7852
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7853
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7854
 
7855
    fork
7856
    begin
7857
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7858
    end
7859
    begin
7860
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7861
        if ( ok_pci !== 1 )
7862
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7863
    end
7864
    join
7865
 
7866
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7867
    begin
7868
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7869
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7870
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7871
        ok_wb = 0 ;
7872
    end
7873
 
7874
    // set target to terminate with target abort
7875
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7876
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7877
 
7878
    // enable pci blue behavioral target 2
7879
    configuration_cycle_write
7880
    (
7881
        0,                          // bus number [7:0]
7882
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7883
        0,                          // function number [2:0]
7884
        1,                          // register number [5:0]
7885
        0,                          // type [1:0]
7886
        4'h1,                       // byte enables [3:0]
7887
        32'h0000_0047               // data to write [31:0]
7888
    ) ;
7889
 
7890
    // read PCI Device status
7891
    config_read(12'h4, 4'hC, temp_var) ;
7892
    if (temp_var[29] !== 1)
7893
    begin
7894
        $display("Time %t", $time) ;
7895
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7896
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7897
        ok_wb = 0 ;
7898
    end
7899
 
7900
    if (temp_var[28] !== 1)
7901
    begin
7902
        $display("Time %t", $time) ;
7903
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7904
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7905
        ok_wb = 0 ;
7906
    end
7907
 
7908
    // clearing the status bits
7909
        config_write(12'h4, temp_var, 4'hC, ok);
7910
 
7911
    if ( ok && ok_pci && ok_wb )
7912
        test_ok ;
7913
 
7914 15 mihad
end
7915
endtask //iack_cycle
7916
 
7917
task transaction_ordering ;
7918
    reg   [11:0] wb_ctrl_offset ;
7919
    reg   [11:0] wb_ba_offset ;
7920
    reg   [11:0] wb_am_offset ;
7921
    reg   [11:0] pci_ctrl_offset ;
7922
    reg   [11:0] pci_ba_offset ;
7923
    reg   [11:0] pci_am_offset ;
7924
    reg   [11:0] pci_device_ctrl_offset ;
7925
    reg   [11:0] wb_err_cs_offset ;
7926
    reg   [11:0] pci_err_cs_offset ;
7927
    reg   [11:0] icr_offset ;
7928
    reg   [11:0] isr_offset ;
7929
    reg   [11:0] lat_tim_cls_offset ;
7930
 
7931
    reg `WRITE_STIM_TYPE  write_data ;
7932
    reg `READ_STIM_TYPE   read_data ;
7933
    reg `READ_RETURN_TYPE read_status ;
7934
 
7935
    reg `WRITE_RETURN_TYPE write_status ;
7936
    reg `WB_TRANSFER_FLAGS write_flags ;
7937
    reg [31:0] temp_val1 ;
7938
    reg [31:0] temp_val2 ;
7939
    reg        ok   ;
7940
 
7941
    reg [31:0] wb_image_base ;
7942
    reg [31:0] wb_target_address ;
7943
    reg [31:0] pci_image_base ;
7944
    integer i ;
7945
 
7946
    reg     error_monitor_done ;
7947
begin:main
7948
    write_flags`INIT_WAITS = tb_init_waits ;
7949
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7950
 
7951
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7952
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7953
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7954
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7955
 
7956
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7957
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7958
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7959
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7960
 
7961
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7962
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7963
    lat_tim_cls_offset = 12'hC ;
7964
    pci_device_ctrl_offset    = 12'h4 ;
7965
 
7966
    wb_target_address  = `BEH_TAR1_MEM_START ;
7967
    wb_image_base      = 0 ;
7968
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
7969
 
7970
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
7971
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
7972
    write_flags                    = 0 ;
7973
    write_flags`INIT_WAITS         = 0 ;
7974
    write_flags`SUBSEQ_WAITS       = 0 ;
7975
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7976
 
7977
    pci_image_base = Target_Base_Addr_R[1] ;
7978
 
7979
    // enable master & target operation
7980
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
7981
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
7982
    if ( ok !== 1 )
7983
    begin
7984
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
7985
        test_fail("write to PCI Device Control register failed") ;
7986
        disable main ;
7987
    end
7988
 
7989
    // prepare image control register
7990
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
7991
    if ( ok !== 1 )
7992
    begin
7993
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7994
        test_fail("write to WB Image Control register failed") ;
7995
        disable main ;
7996
    end
7997
 
7998
    // prepare base address register
7999
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8000
    if ( ok !== 1 )
8001
    begin
8002
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8003
        test_fail("write to WB Base Address register failed") ;
8004
        disable main ;
8005
    end
8006
 
8007
    // write address mask register
8008
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8009
    if ( ok !== 1 )
8010
    begin
8011
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8012
        test_fail("write to WB Address Mask register failed") ;
8013
        disable main ;
8014
    end
8015
 
8016
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8017
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8018
    if ( ok !== 1 )
8019
    begin
8020
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8021
        test_fail("write to WB Error Control and Status register failed") ;
8022
        disable main ;
8023
    end
8024
 
8025
    // prepare image control register
8026
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8027
    if ( ok !== 1 )
8028
    begin
8029
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8030
        test_fail("write to PCI Image Control register failed") ;
8031
        disable main ;
8032
    end
8033
 
8034
    // prepare base address register
8035
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8036
    if ( ok !== 1 )
8037
    begin
8038
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8039
        test_fail("write to PCI Base Address register failed") ;
8040
        disable main ;
8041
    end
8042
 
8043
    // write address mask register
8044
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8045
    if ( ok !== 1 )
8046
    begin
8047
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8048
        test_fail("write to PCI Address Mask register failed") ;
8049
        disable main ;
8050
    end
8051
 
8052
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8053
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8054
    if ( ok !== 1 )
8055
    begin
8056
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8057
        test_fail("write to PCI Error Control and Status register failed") ;
8058
        disable main ;
8059
    end
8060
 
8061
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8062
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8063
    if ( ok !== 1 )
8064
    begin
8065
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8066
        test_fail("write to Interrupt Control register failed") ;
8067
        disable main ;
8068
    end
8069
 
8070
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8071
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8072
    if ( ok !== 1 )
8073
    begin
8074
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8075
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8076
        disable main ;
8077
    end
8078
 
8079
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8080
 
8081
    // prepare wb_master write and read data
8082
    for ( i = 0 ; i < 4 ; i = i + 1 )
8083
    begin
8084
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8085
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8086
        write_data`WRITE_SEL     = 4'hF ;
8087
 
8088
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8089
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8090
 
8091
        wishbone_master.blk_write_data[i]   = write_data ;
8092
        wishbone_master.blk_read_data_in[i] = read_data ;
8093
    end
8094
 
8095
    // put wishbone slave in acknowledge and pci target in retry mode
8096
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8097
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8098
 
8099
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8100
 
8101
    fork
8102
    begin
8103
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8104
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8105
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8106
        begin
8107
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8108
            test_fail("Bridge didn't post single memory write as expected") ;
8109
        end
8110
 
8111
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8112
        if ( ok !== 1 )
8113
        begin
8114
            $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) ;
8115
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8116
            ok = 0 ;
8117
        end
8118
 
8119
        // now post single write to target - normal progress
8120
        if ( target_mem_image == 1 )
8121
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8122
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8123
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8124
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8125
        else
8126
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8127
 
8128
        do_pause( 1 ) ;
8129
 
8130
    end
8131
    begin:error_monitor_1
8132 35 mihad
        error_monitor_done = 0 ;
8133 15 mihad
        @(error_event_int) ;
8134
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8135
        ok = 0 ;
8136 35 mihad
        error_monitor_done = 1 ;
8137 15 mihad
    end
8138
    begin
8139
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8140
        if ( ok !== 1 )
8141
        begin
8142
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8143
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8144
        end
8145
        else
8146
        begin
8147 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8148
//            while ( FRAME === 0 || IRDY === 0 )
8149
//                @(posedge pci_clock) ;
8150 15 mihad
 
8151
            // enable response in PCI target
8152
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8153
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8154
 
8155
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8156
            if ( ok !== 1 )
8157
            begin
8158
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8159
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8160
            end
8161
        end
8162
 
8163 35 mihad
        #1 ;
8164
        if ( !error_monitor_done )
8165
            disable error_monitor_1 ;
8166 15 mihad
    end
8167
    join
8168
 
8169
    if ( ok )
8170
        test_ok ;
8171
 
8172
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8173
 
8174
    // put WISHBONE slave in retry mode
8175
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8176
 
8177
    fork
8178
    begin
8179
        // now post single write to target - normal progress
8180
        if ( target_mem_image == 1 )
8181
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8182
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8183
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8184
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8185
        else
8186
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8187
 
8188
        do_pause( 1 ) ;
8189
 
8190
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8191
        if ( ok !== 1 )
8192
        begin
8193
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8194
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8195
        end
8196
 
8197
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8198
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8199
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8200
        begin
8201
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8202
            test_fail("Bridge didn't post single memory write as expected") ;
8203
        end
8204
 
8205
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8206
        if ( ok !== 1 )
8207
        begin
8208
            $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) ;
8209
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8210
            ok = 0 ;
8211
        end
8212
 
8213
        wait ( CYC_O === 0 ) ;
8214
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8215
 
8216
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8217
        if ( ok !== 1 )
8218
        begin
8219
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8220
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8221
        end
8222
 
8223 35 mihad
        #1 ;
8224
        if ( !error_monitor_done )
8225
            disable error_monitor_2 ;
8226 15 mihad
    end
8227
    begin:error_monitor_2
8228 35 mihad
        error_monitor_done = 0 ;
8229 15 mihad
        @(error_event_int) ;
8230
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8231
        ok = 0 ;
8232 35 mihad
        error_monitor_done = 1 ;
8233 15 mihad
    end
8234
    join
8235
 
8236
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8237
 
8238
    // put wishbone slave in acknowledge and pci target in retry mode
8239
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8240
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8241
 
8242
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8243
 
8244
    fork
8245
    begin
8246
        write_flags`WB_TRANSFER_SIZE = 3 ;
8247
        write_flags`WB_TRANSFER_CAB  = 1 ;
8248
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8249
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8250
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8251
        begin
8252
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8253
            test_fail("Bridge didn't post burst memory write as expected") ;
8254
        end
8255
 
8256
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8257
        if ( ok !== 1 )
8258
        begin
8259
            $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) ;
8260
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8261
            ok = 0 ;
8262
        end
8263
 
8264
        // now post single write to target - normal progress
8265
        if ( target_mem_image == 1 )
8266
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8267
                        pci_image_base, 32'h5555_5555, 4'h0,
8268
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8269
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8270
        else
8271
        begin
8272
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8273
            do_pause( 1 ) ;
8274
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8275
        end
8276
 
8277
        do_pause( 1 ) ;
8278
 
8279
    end
8280
    begin:error_monitor_3
8281 35 mihad
        error_monitor_done = 0 ;
8282 15 mihad
        @(error_event_int) ;
8283
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8284
        ok = 0 ;
8285 35 mihad
        error_monitor_done = 1 ;
8286 15 mihad
    end
8287
    begin
8288
        if ( target_mem_image == 1 )
8289
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8290
        else
8291
        begin
8292
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8293
            if ( ok )
8294
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8295
        end
8296
 
8297
        if ( ok !== 1 )
8298
        begin
8299
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8300
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8301
        end
8302
        else
8303
        begin
8304 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8305
//            while ( FRAME === 0 || IRDY === 0 )
8306
//                @(posedge pci_clock) ;
8307 15 mihad
 
8308
            // enable response in PCI target
8309
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8310
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8311
 
8312
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8313
            if ( ok !== 1 )
8314
            begin
8315
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8316
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8317
            end
8318
        end
8319
 
8320 35 mihad
        #1 ;
8321
        if ( !error_monitor_done )
8322
            disable error_monitor_3 ;
8323 15 mihad
    end
8324
    join
8325
 
8326
    if ( ok )
8327
        test_ok ;
8328
 
8329
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8330
 
8331
    // put WISHBONE slave in retry mode
8332
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8333
 
8334
    fork
8335
    begin
8336
        // now post single write to target - normal progress
8337
        if ( target_mem_image == 1 )
8338
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8339
                        pci_image_base, 32'h5555_5555, 4'h0,
8340
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8341
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8342
        else
8343
        begin
8344
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8345
            do_pause( 1 ) ;
8346
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8347
        end
8348
 
8349
        do_pause( 1 ) ;
8350
 
8351
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8352
 
8353
        if ( ok !== 1 )
8354
        begin
8355
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8356
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8357
        end
8358
 
8359
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8360
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8361
        write_flags`WB_TRANSFER_CAB      = 1 ;
8362
 
8363
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8364
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8365
        begin
8366
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8367
            test_fail("Bridge didn't post burst memory write as expected") ;
8368
        end
8369
 
8370
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8371
        if ( ok !== 1 )
8372
        begin
8373
            $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) ;
8374
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8375
            ok = 0 ;
8376
        end
8377
 
8378
        @(posedge wb_clock) ;
8379
        while ( CYC_O === 1 )
8380
            @(posedge wb_clock) ;
8381
 
8382
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8383
 
8384
        if ( target_mem_image == 1 )
8385
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8386
        else
8387
        begin
8388
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8389
            if ( ok )
8390
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8391
        end
8392
 
8393 35 mihad
        #1 ;
8394
        if ( !error_monitor_done )
8395
            disable error_monitor_4 ;
8396 15 mihad
    end
8397
    begin:error_monitor_4
8398 35 mihad
        error_monitor_done = 0 ;
8399 15 mihad
        @(error_event_int) ;
8400
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8401
        ok = 0 ;
8402 35 mihad
        error_monitor_done = 1 ;
8403 15 mihad
    end
8404
    join
8405
 
8406
    if ( ok )
8407
        test_ok ;
8408
 
8409
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8410
 
8411
    // put wishbone slave in acknowledge and pci target in retry mode
8412
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8413
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8414
 
8415
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8416
 
8417
    master1_check_received_data = 1 ;
8418
 
8419
    error_monitor_done = 0 ;
8420
    fork
8421
    begin:error_monitor_5
8422
        @(error_event_int or error_monitor_done) ;
8423
        if ( !error_monitor_done )
8424
        begin
8425
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8426
            ok = 0 ;
8427
        end
8428
    end
8429
    begin
8430
 
8431
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8432
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8433
        begin
8434
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8435
            test_fail("Bridge didn't post single memory write as expected") ;
8436
        end
8437
 
8438
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8439
        if ( ok !== 1 )
8440
        begin
8441
            $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) ;
8442
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8443
            ok = 0 ;
8444
        end
8445
 
8446
        // start Read Through pci target
8447
        if ( target_mem_image == 1 )
8448
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8449
                          pci_image_base, 32'h5555_5555,
8450
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8451
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8452
        else
8453
            PCIU_IO_READ
8454
             (
8455
                `Test_Master_1,
8456
                pci_image_base,
8457
                32'h5555_5555,
8458
                4'h0,
8459
                1,
8460
                `Test_Target_Retry_On
8461
             );
8462
 
8463
         do_pause( 1 ) ;
8464
 
8465
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8466
         if ( ok !== 1 )
8467
         begin
8468
            $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) ;
8469
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8470
         end
8471
 
8472
         // repeat the read 4 times - it should be retried all the time by pci target
8473
        for ( i = 0 ; i < 4 ; i = i + 1 )
8474
        begin
8475
            if ( target_mem_image == 1 )
8476
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8477
                            pci_image_base, 32'h5555_5555,
8478
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8479
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8480
            else
8481
                PCIU_IO_READ
8482
                (
8483
                    `Test_Master_1,
8484
                    pci_image_base,
8485
                    32'h5555_5555,
8486
                    4'h0,
8487
                    1,
8488
                    `Test_Target_Retry_On
8489
                );
8490
 
8491
            do_pause( 1 ) ;
8492
        end
8493
 
8494
        // now do posted write through target - it must go through OK
8495
        if ( target_mem_image == 1 )
8496
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8497
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8498
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8499
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8500
        else
8501
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8502
 
8503
        do_pause( 1 ) ;
8504
 
8505
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8506
        if ( ok !== 1 )
8507
        begin
8508
           $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) ;
8509
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8510
        end
8511
 
8512
        // start a read through wb_slave
8513
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8514
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8515
        begin
8516
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8517
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8518
            ok = 0 ;
8519
        end
8520
 
8521 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8522
//        while ( FRAME === 0 || IRDY === 0 )
8523
//            @(posedge pci_clock) ;
8524 15 mihad
 
8525
        // set the target to normal completion
8526
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8527
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8528
 
8529
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8530
        if ( ok !== 1 )
8531
        begin
8532
            $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) ;
8533
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8534
            ok = 0 ;
8535
        end
8536
 
8537
        // now wait for delayed read to finish
8538
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8539
        if ( ok !== 1 )
8540
        begin
8541
            $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) ;
8542
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8543
            ok = 0 ;
8544
        end
8545
 
8546
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8547
        fork
8548
        begin
8549
                if ( target_mem_image == 1 )
8550
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8551
                                pci_image_base, 32'h5555_5555, 4'h0,
8552
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8553
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8554
                else
8555
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8556
 
8557
                do_pause( 1 ) ;
8558
                end
8559
                begin
8560
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8561
                end
8562
                join
8563
 
8564
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8565
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8566
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8567
        begin
8568
            $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) ;
8569
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8570
            ok = 0 ;
8571
        end
8572
 
8573
        fork
8574
        begin
8575
        // now complete a read from PCI Target
8576
            if ( target_mem_image == 1 )
8577
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8578
                            pci_image_base, 32'h5555_5555,
8579
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8580
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8581
            else
8582
                PCIU_IO_READ
8583
                (
8584
                    `Test_Master_1,
8585
                    pci_image_base,
8586
                    32'h5555_5555,
8587
                    4'h0,
8588
                    1,
8589
                    `Test_Target_Normal_Completion
8590
                );
8591
 
8592
            do_pause( 1 ) ;
8593
        end
8594
        begin
8595
            if ( target_mem_image == 1 )
8596
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8597
            else
8598
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8599
        end
8600
        join
8601
 
8602
        @(posedge pci_clock) ;
8603
        repeat( 4 )
8604
            @(posedge wb_clock) ;
8605
 
8606
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8607
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8608
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8609
        begin
8610
            $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) ;
8611
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8612
            ok = 0 ;
8613
        end
8614
 
8615
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8616
        if ( ok !== 1 )
8617
        begin
8618
            $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) ;
8619
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8620
            ok = 0 ;
8621
        end
8622
 
8623
        // finish a read on WISHBONE also
8624
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8625
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8626
        begin
8627
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8628
            test_fail("WB Slave didn't process single delayed read as expected") ;
8629
        end
8630
 
8631
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8632
        begin
8633
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8634
            ok = 0 ;
8635
        end
8636
 
8637
 
8638
        error_monitor_done = 1 ;
8639
    end
8640
    join
8641
 
8642
    if ( ok )
8643
        test_ok ;
8644
 
8645
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8646
 
8647
    // put wishbone slave in retry and pci target in completion mode
8648
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8649
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8650
 
8651
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8652
 
8653
    master1_check_received_data = 1 ;
8654
 
8655
    error_monitor_done = 0 ;
8656
    fork
8657
    begin:error_monitor_6
8658
        @(error_event_int or error_monitor_done) ;
8659
        if ( !error_monitor_done )
8660
        begin
8661
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8662
            ok = 0 ;
8663
        end
8664
    end
8665
    begin
8666
 
8667
        // do a write through Target
8668
        fork
8669
        begin
8670
            if ( target_mem_image == 1 )
8671
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8672
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8673
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8674
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8675
            else
8676
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8677
 
8678
            do_pause( 1 ) ;
8679
        end
8680
        begin
8681
            if ( target_mem_image == 1 )
8682
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8683
            else
8684
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8685
        end
8686
        join
8687
 
8688
        // start a read through WB slave
8689
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8690
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8691
        begin
8692
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8693
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8694
            ok = 0 ;
8695
        end
8696
 
8697
        // now wait for this read to finish on pci
8698
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8699
        if ( ok !== 1 )
8700
        begin
8701
            $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) ;
8702
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8703
            ok = 0 ;
8704
        end
8705
 
8706
        // repeat the read four times - it should be retried
8707
        for ( i = 0 ; i < 4 ; i = i + 1 )
8708
        begin
8709
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8710
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8711
            begin
8712
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8713
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8714
                ok = 0 ;
8715
            end
8716
        end
8717
 
8718
        // posted write through WB Slave - must go through
8719
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8720
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8721
        begin
8722
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8723
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8724
            ok = 0 ;
8725
        end
8726
 
8727
        // write must come through
8728
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8729
        if ( ok !== 1 )
8730
        begin
8731
            $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) ;
8732
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8733
            ok = 0 ;
8734
        end
8735
 
8736
        // do a read through pci target
8737
        if ( target_mem_image == 1 )
8738
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8739
                          pci_image_base + 12, 32'hDEAD_BEAF,
8740
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8741
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8742
        else
8743
            PCIU_IO_READ
8744
             (
8745
                `Test_Master_1,
8746
                pci_image_base + 12,
8747
                32'hDEAD_BEAF,
8748
                4'h0,
8749
                1,
8750
                `Test_Target_Retry_On
8751
             );
8752
 
8753
         do_pause( 1 ) ;
8754
 
8755
        // wait for current cycle to finish on WB
8756 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8757
//        @(posedge wb_clock) ;
8758
//        while( CYC_O === 1 )
8759
//            @(posedge wb_clock) ;
8760 15 mihad
 
8761
        // set slave response to acknowledge
8762
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8763
 
8764
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8765
        if ( ok !== 1 )
8766
        begin
8767
            $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) ;
8768
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8769
        end
8770
 
8771
        // check the read to finish on wb
8772
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8773
        if ( ok !== 1 )
8774
        begin
8775
            $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) ;
8776
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8777
        end
8778
 
8779
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8780
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8781
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8782
        begin
8783
            $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) ;
8784
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8785
            ok = 0 ;
8786
        end
8787
 
8788
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8789
        fork
8790
        begin
8791
            if ( target_mem_image == 1 )
8792
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8793
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8794
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8795
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8796
            else
8797
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8798
        end
8799
        begin
8800
            if ( target_mem_image == 1 )
8801
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8802
            else
8803
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8804
        end
8805
        join
8806
 
8807
        do_pause( 1 ) ;
8808
 
8809
        // complete a read in WB Slave Unit
8810
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8811
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8812
        begin
8813
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8814
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8815
            ok = 0 ;
8816
        end
8817
 
8818
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8819
        begin
8820
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8821
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8822
            ok = 0 ;
8823
        end
8824
 
8825
        // wait for statuses to be propagated from one side of bridge to another
8826
        repeat( 4 )
8827
            @(posedge pci_clock) ;
8828
 
8829
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8830
        fork
8831
        begin
8832
            if ( target_mem_image == 1 )
8833
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8834
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8835
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8836
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8837
            else
8838
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8839
 
8840
            do_pause( 1 ) ;
8841
        end
8842
        begin
8843
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8844
            if ( ok !== 1 )
8845
            begin
8846
                $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) ;
8847
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8848
            end
8849
        end
8850
        join
8851
 
8852
        // finish the last read in PCI Target Unit
8853
        if ( target_mem_image == 1 )
8854
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8855
                          pci_image_base + 12, 32'hDEAD_BEAF,
8856
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8857
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8858
        else
8859
            PCIU_IO_READ
8860
             (
8861
                `Test_Master_1,
8862
                pci_image_base + 12,
8863
                32'hDEAD_BEAF,
8864
                4'h0,
8865
                1,
8866
                `Test_Target_Normal_Completion
8867
             );
8868
 
8869
         do_pause( 1 ) ;
8870
 
8871
         error_monitor_done = 1 ;
8872
    end
8873
    join
8874
 
8875
    if ( ok )
8876
        test_ok ;
8877
 
8878
end
8879
endtask // transaction_ordering
8880
 
8881
task pci_transaction_progress_monitor ;
8882
    input [31:0] address ;
8883
    input [3:0]  bus_command ;
8884
    input [31:0] num_of_transfers ;
8885
    input [31:0] num_of_cycles ;
8886
    input check_transfers ;
8887
    input check_cycles ;
8888
    input doing_fast_back_to_back ;
8889
    output ok ;
8890
    reg in_use ;
8891
    integer deadlock_counter ;
8892
    integer transfer_counter ;
8893
    integer cycle_counter ;
8894
    integer deadlock_max_val ;
8895
begin:main
8896
 
8897
    if ( in_use === 1 )
8898
    begin
8899
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8900
        ok = 0 ;
8901
        disable main ;
8902
    end
8903
 
8904
    // approximate number of cycles on WB bus for maximum transaction length
8905
    deadlock_max_val = tb_init_waits + 100 +
8906
                       `WBW_DEPTH *
8907
                       (tb_subseq_waits + 1 +
8908
                       `ifdef REGISTER_WBS_OUTPUTS
8909
                       1) ;
8910
                       `else
8911
                       0) ;
8912
                       `endif
8913
 
8914
    // time used for maximum transaction length on WB
8915
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8916
 
8917
    // maximum pci clock cycles
8918
    `ifdef PCI33
8919
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8920
    `else
8921
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8922
    `endif
8923
 
8924
    in_use = 1 ;
8925
    ok     = 1 ;
8926
 
8927
    fork
8928
    begin:wait_start
8929
 
8930
        deadlock_counter = 0 ;
8931
 
8932
        @(posedge pci_clock) ;
8933
 
8934
        if ( doing_fast_back_to_back !== 1 )
8935
        begin
8936
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8937
            begin
8938 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8939
                    deadlock_counter = 0 ;
8940
                else
8941
                    deadlock_counter = deadlock_counter + 1 ;
8942 15 mihad
                @(posedge pci_clock) ;
8943
            end
8944
            if ( FRAME !== 1 )
8945
            begin
8946
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8947
                in_use = 0 ;
8948
                ok     = 0 ;
8949
                disable main ;
8950
            end
8951
        end
8952
 
8953
        deadlock_counter = 0 ;
8954
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8955
        begin
8956
            deadlock_counter = deadlock_counter + 1 ;
8957
            @(posedge pci_clock) ;
8958
        end
8959
 
8960
        if ( FRAME !== 0 )
8961
        begin
8962
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8963
            in_use = 0 ;
8964
            ok     = 0 ;
8965
            disable main ;
8966
        end
8967
    end //wait_start
8968
 
8969
    begin:addr_bc_monitor
8970
 
8971
        @(posedge pci_clock) ;
8972
 
8973
        if ( doing_fast_back_to_back !== 1 )
8974
        begin
8975
            while ( FRAME !== 1 )
8976
                @(posedge pci_clock) ;
8977
        end
8978
 
8979
        while( FRAME !== 0 )
8980
            @(posedge pci_clock) ;
8981
 
8982
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
8983
        if ( bus_command !== `BC_IACK )
8984
        begin
8985
            if ( AD !== address )
8986
            begin
8987
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
8988
                $display("Expected address = %h, detected address = %h ", address, AD) ;
8989
                ok = 0 ;
8990
            end
8991
        end
8992
 
8993
        if ( CBE !== bus_command )
8994
        begin
8995
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
8996
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
8997
            ok = 0 ;
8998
        end
8999
    end //addr_bc_monitor
9000
 
9001
    begin:transfer_checker
9002
        transfer_counter = 0 ;
9003
 
9004
        @(posedge pci_clock) ;
9005
 
9006
        if ( doing_fast_back_to_back !== 1 )
9007
        begin
9008
            while ( FRAME !== 1 )
9009
                @(posedge pci_clock) ;
9010
        end
9011
 
9012
        while( FRAME !== 0 )
9013
            @(posedge pci_clock) ;
9014
 
9015
        while( FRAME === 0 )
9016
        begin
9017
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9018
                transfer_counter = transfer_counter + 1 ;
9019
            @(posedge pci_clock) ;
9020
        end
9021
 
9022
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9023
        begin
9024
            @(posedge pci_clock) ;
9025
        end
9026
 
9027
        if ( (TRDY === 0) && (DEVSEL === 0) )
9028
                transfer_counter = transfer_counter + 1 ;
9029
 
9030
        if ( check_transfers === 1 )
9031
        begin
9032
            if ( transfer_counter !== num_of_transfers )
9033
            begin
9034
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9035
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9036
                ok = 0 ;
9037
            end
9038
        end
9039
    end //transfer_checker
9040
    begin:cycle_checker
9041
        if ( check_cycles )
9042
        begin
9043
            cycle_counter = 0 ;
9044
            @(posedge pci_clock) ;
9045
 
9046
            if ( doing_fast_back_to_back !== 1)
9047
            begin
9048
                while ( FRAME !== 1 )
9049
                    @(posedge pci_clock) ;
9050
            end
9051
 
9052
            while( FRAME !== 0 )
9053
                @(posedge pci_clock) ;
9054
 
9055
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9056
            begin
9057
                cycle_counter = cycle_counter + 1 ;
9058
                @(posedge pci_clock) ;
9059
            end
9060
 
9061
            if ( FRAME !== 1 )
9062
            begin
9063
                while ((FRAME === 0) && (MAS0_GNT === 0))
9064
                    @(posedge pci_clock) ;
9065
 
9066
                if ( FRAME !== 1 )
9067
                begin
9068
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9069
                        @(posedge pci_clock) ;
9070
 
9071
                    @(posedge pci_clock) ;
9072
 
9073
                    if ( FRAME !== 1 )
9074
                    begin
9075
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9076
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9077
                        ok = 0 ;
9078
                    end
9079
                end
9080
            end
9081
        end
9082
    end // cycle_checker
9083
    join
9084
 
9085
    in_use = 0 ;
9086
end
9087
endtask //pci_transaction_progress_monitor
9088
 
9089
reg CYC_O_previous ;
9090
always@(posedge wb_clock or posedge reset)
9091
begin
9092
    if ( reset )
9093
        CYC_O_previous <= #1 1'b0 ;
9094
    else
9095
        CYC_O_previous <= #1 CYC_O ;
9096
end
9097
 
9098
task wb_transaction_progress_monitor ;
9099
    input [31:0] address ;
9100
    input        write ;
9101
    input [31:0] num_of_transfers ;
9102
    input check_transfers ;
9103
    output ok ;
9104
    reg in_use ;
9105
    integer deadlock_counter ;
9106
    integer transfer_counter ;
9107
    integer deadlock_max_val ;
9108
begin:main
9109
    if ( in_use === 1 )
9110
    begin
9111
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9112
        ok = 0 ;
9113
        disable main ;
9114
    end
9115
 
9116
    // number of cycles on WB bus for maximum transaction length
9117
    deadlock_max_val = 4 - tb_init_waits + 100 +
9118
                       `PCIW_DEPTH *
9119
                       (4 - tb_subseq_waits + 1) ;
9120
 
9121
    // time used for maximum transaction length on PCI
9122
    `ifdef PCI33
9123
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9124
    `else
9125
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9126
    `endif
9127
 
9128
    // maximum wb clock cycles
9129
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9130
 
9131
    in_use = 1 ;
9132
    ok     = 1 ;
9133
 
9134
    fork
9135
    begin:wait_start
9136
        deadlock_counter = 0 ;
9137
        @(posedge wb_clock) ;
9138
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9139
        begin
9140 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9141
                deadlock_counter = deadlock_counter + 1 ;
9142
            else
9143
                deadlock_counter = 0;
9144 15 mihad
            @(posedge wb_clock) ;
9145
        end
9146
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9147
        begin
9148
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9149
            in_use = 0 ;
9150
            ok     = 0 ;
9151
            disable main ;
9152
        end
9153
 
9154
        deadlock_counter = 0 ;
9155
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9156
        begin
9157
            deadlock_counter = deadlock_counter + 1 ;
9158
            @(posedge wb_clock) ;
9159
        end
9160
 
9161
        if ( CYC_O !== 1 )
9162
        begin
9163
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9164
            in_use = 0 ;
9165
            ok     = 0 ;
9166
            disable main ;
9167
        end
9168
    end //wait_start
9169
    begin:addr_monitor
9170
        @(posedge wb_clock) ;
9171
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9172
            @(posedge wb_clock) ;
9173
 
9174
        while( CYC_O !== 1 )
9175
            @(posedge wb_clock) ;
9176
 
9177
        while (STB_O !== 1 )
9178
            @(posedge wb_clock) ;
9179
 
9180
        if ( WE_O !== write )
9181
        begin
9182
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9183
            if ( write !== 1 )
9184
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9185
            else
9186
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9187
        end
9188
 
9189
        if ( ADR_O !== address )
9190
        begin
9191
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9192
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9193
            ok = 0 ;
9194
        end
9195
    end
9196
    begin:transfer_checker
9197
        transfer_counter = 0 ;
9198
        @(posedge wb_clock) ;
9199
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9200
            @(posedge wb_clock) ;
9201
 
9202
        while( CYC_O !== 1 )
9203
            @(posedge wb_clock) ;
9204
 
9205
        while( CYC_O === 1 )
9206
        begin
9207
            if ( (STB_O === 1) && (ACK_I === 1) )
9208
                transfer_counter = transfer_counter + 1 ;
9209
            @(posedge wb_clock) ;
9210
        end
9211
 
9212
        if ( check_transfers === 1 )
9213
        begin
9214
            if ( transfer_counter !== num_of_transfers )
9215
            begin
9216
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9217
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9218
                ok = 0 ;
9219
            end
9220
        end
9221
    end //transfer_checker
9222
    join
9223
 
9224
    in_use = 0 ;
9225
end
9226
endtask // wb_transaction_progress_monitor
9227
 
9228
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9229
// so they are not re-entered
9230
task wb_transaction_progress_monitor_backup ;
9231
    input [31:0] address ;
9232
    input        write ;
9233
    input [31:0] num_of_transfers ;
9234
    input check_transfers ;
9235
    output ok ;
9236
    reg in_use ;
9237
    integer deadlock_counter ;
9238
    integer transfer_counter ;
9239
    integer deadlock_max_val ;
9240
begin:main
9241
    if ( in_use === 1 )
9242
    begin
9243
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9244
        ok = 0 ;
9245
        disable main ;
9246
    end
9247
 
9248
    // number of cycles on WB bus for maximum transaction length
9249
    deadlock_max_val = 4 - tb_init_waits + 100 +
9250
                       `PCIW_DEPTH *
9251
                       (4 - tb_subseq_waits + 1) ;
9252
 
9253
    // time used for maximum transaction length on PCI
9254
    `ifdef PCI33
9255
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9256
    `else
9257
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9258
    `endif
9259
 
9260
    // maximum wb clock cycles
9261
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9262
 
9263
    in_use = 1 ;
9264
    ok     = 1 ;
9265
 
9266
    fork
9267
    begin:wait_start
9268
        deadlock_counter = 0 ;
9269
        @(posedge wb_clock) ;
9270
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9271
        begin
9272 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9273
                deadlock_counter = deadlock_counter + 1 ;
9274
            else
9275
                deadlock_counter = 0;
9276 15 mihad
            @(posedge wb_clock) ;
9277
        end
9278
        if ( CYC_O !== 0 )
9279
        begin
9280
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9281
            in_use = 0 ;
9282
            ok     = 0 ;
9283
            disable main ;
9284
        end
9285
 
9286
        deadlock_counter = 0 ;
9287
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9288
        begin
9289
            deadlock_counter = deadlock_counter + 1 ;
9290
            @(posedge wb_clock) ;
9291
        end
9292
 
9293
        if ( CYC_O !== 1 )
9294
        begin
9295
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9296
            in_use = 0 ;
9297
            ok     = 0 ;
9298
            disable main ;
9299
        end
9300
    end //wait_start
9301
    begin:addr_monitor
9302
        @(posedge wb_clock) ;
9303
        while ( CYC_O !== 0 )
9304
            @(posedge wb_clock) ;
9305
 
9306
        while( CYC_O !== 1 )
9307
            @(posedge wb_clock) ;
9308
 
9309
        while (STB_O !== 1 )
9310
            @(posedge wb_clock) ;
9311
 
9312
        if ( WE_O !== write )
9313
        begin
9314
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9315
            if ( write !== 1 )
9316
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9317
            else
9318
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9319
        end
9320
 
9321
        if ( ADR_O !== address )
9322
        begin
9323
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9324
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9325
            ok = 0 ;
9326
        end
9327
    end
9328
    begin:transfer_checker
9329
        transfer_counter = 0 ;
9330
        @(posedge wb_clock) ;
9331
        while ( CYC_O !== 0 )
9332
            @(posedge wb_clock) ;
9333
 
9334
        while( CYC_O !== 1 )
9335
            @(posedge wb_clock) ;
9336
 
9337
        while( CYC_O === 1 )
9338
        begin
9339
            if ( (STB_O === 1) && (ACK_I === 1) )
9340
                transfer_counter = transfer_counter + 1 ;
9341
            @(posedge wb_clock) ;
9342
        end
9343
 
9344
        if ( check_transfers === 1 )
9345
        begin
9346
            if ( transfer_counter !== num_of_transfers )
9347
            begin
9348
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9349
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9350
                ok = 0 ;
9351
            end
9352
        end
9353
    end //transfer_checker
9354
    join
9355
 
9356
    in_use = 0 ;
9357
end
9358
endtask // wb_transaction_progress_monitor_backup
9359
 
9360
task wb_transaction_stop ;
9361
    input [31:0] num_of_transfers ;
9362
    integer transfer_counter ;
9363
begin:main
9364
    begin:transfer_checker
9365
        transfer_counter = 0 ;
9366
        @(posedge wb_clock) ;
9367
        while ( CYC_O !== 0 )
9368
            @(posedge wb_clock) ;
9369
 
9370
        while( CYC_O !== 1 )
9371
            @(posedge wb_clock) ;
9372
 
9373
        if ( (STB_O === 1) && (ACK_I === 1) )
9374
            transfer_counter = transfer_counter + 1 ;
9375
 
9376
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9377
        begin
9378
            @(posedge wb_clock) ;
9379
            if ( (STB_O === 1) && (ACK_I === 1) )
9380
                transfer_counter = transfer_counter + 1 ;
9381
        end
9382
    end //transfer_checker
9383
end
9384
endtask // wb_transaction_stop
9385
 
9386
task musnt_respond ;
9387
    output ok ;
9388
    reg in_use ;
9389
    integer i ;
9390
begin:main
9391
    if ( in_use === 1 )
9392
    begin
9393
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9394
        #20 $stop ;
9395
        ok = 0 ;
9396
        disable main ;
9397
    end
9398
 
9399
    in_use = 1 ;
9400
    ok = 1 ;
9401
 
9402
    fork
9403
    begin:wait_start
9404
        @(negedge FRAME) ;
9405
        disable count ;
9406
    end
9407
    begin:count
9408
        i = 0 ;
9409
        while ( i < 1000 )
9410
        begin
9411
            @(posedge pci_clock) ;
9412
            i = i + 1 ;
9413
        end
9414
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9415
        ok = 0 ;
9416
        disable wait_start ;
9417
    end
9418
    join
9419
 
9420
    @(posedge pci_clock) ;
9421
    while ( FRAME === 0 && ok )
9422
    begin
9423
        if ( DEVSEL !== 1 )
9424
        begin
9425
            ok = 0 ;
9426
        end
9427
        @(posedge pci_clock) ;
9428
    end
9429
 
9430
    while ( IRDY === 0 && ok )
9431
    begin
9432
        if ( DEVSEL !== 1 )
9433
        begin
9434
            ok = 0 ;
9435
        end
9436
        @(posedge pci_clock) ;
9437
    end
9438
    in_use = 0 ;
9439
end
9440
endtask
9441
 
9442
function [31:0] wb_to_pci_addr_convert ;
9443
    input [31:0] wb_address ;
9444
    input [31:0] translation_address ;
9445
    input [31:0] translate ;
9446
 
9447
    reg   [31:0] temp_address ;
9448
begin
9449
    if ( translate !== 1 )
9450
    begin
9451
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9452
    end
9453
    else
9454
    begin
9455
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9456
    end
9457
 
9458
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9459
    wb_to_pci_addr_convert = temp_address ;
9460
end
9461
endfunction //wb_to_pci_addr_convert
9462
 
9463 45 mihad
`ifdef HOST
9464 15 mihad
task find_pci_devices ;
9465
    integer device_num ;
9466
    reg     found ;
9467
    reg [11:0] pci_ctrl_offset ;
9468
    reg ok ;
9469
    reg [31:0] data ;
9470 45 mihad
    reg [31:0] expected_data ;
9471
 
9472
    reg [5:0]  reg_num ;
9473 15 mihad
begin:main
9474 45 mihad
 
9475
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9476 15 mihad
    pci_ctrl_offset = 12'h004 ;
9477
 
9478
    // enable master & target operation
9479
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9480
 
9481
    if ( ok !== 1 )
9482
    begin
9483
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9484 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9485 15 mihad
        disable main ;
9486
    end
9487
    // find all possible devices on pci bus by performing configuration cycles
9488 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9489 15 mihad
    begin
9490
        find_device ( device_num, found ) ;
9491
 
9492
        // check pci status register - if device is not present, Received Master Abort bit must be set
9493
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9494
 
9495
        if ( (data[29] !== 0) && (found !== 0) )
9496 45 mihad
        begin
9497 15 mihad
            $display( "Time %t ", $time ) ;
9498
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9499
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9500 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9501
            ok = 0 ;
9502 15 mihad
        end
9503
 
9504
        if ( (data[29] !== 1) && (found !== 1) )
9505
        begin
9506
            $display( "Time %t ", $time ) ;
9507
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9508
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9509 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9510
            ok = 0 ;
9511 15 mihad
        end
9512
 
9513
        // clear Master Abort status if set
9514
        if ( data[29] !== 0 )
9515
        begin
9516
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9517
        end
9518 45 mihad
 
9519
        if (found === 1)
9520
        begin
9521
            // first check if found target is supposed to exist
9522
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9523
            begin
9524
                $display("Time %t", $time) ;
9525
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9526
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9527
                ok = 0 ;
9528
            end
9529
            else
9530
            begin
9531
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9532
                begin
9533
 
9534
                    data = 32'hFFFF_FFFF ;
9535
 
9536
                    expected_data = 0 ;
9537
 
9538
                    if (reg_num == 4)
9539
                    begin
9540
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9541
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9542
                    end
9543
                    else if (reg_num == 5)
9544
                    begin
9545
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9546
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9547
                    end
9548
 
9549
                    // write base address 0
9550
                    generate_configuration_cycle
9551
                    (
9552
                        'h0,            //bus_num
9553
                        device_num,     //device_num
9554
                        'h0,            //func_num
9555
                        reg_num,        //reg_num
9556
                        'h0,            //type
9557
                        4'hF,           // byte_enables
9558
                        data,           //data
9559
                        1'b1            //read0_write1
9560
                    );
9561
 
9562
                    // read data back
9563
                    generate_configuration_cycle
9564
                    (
9565
                        'h0,            //bus_num
9566
                        device_num,     //device_num
9567
                        'h0,            //func_num
9568
                        reg_num,        //reg_num
9569
                        'h0,            //type
9570
                        4'hF,           // byte_enables
9571
                        data,           //data
9572
                        1'b0            //read0_write1
9573
                    );
9574
 
9575
                    if (data !== expected_data)
9576
                    begin
9577
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9578
                        $display("Data read back not as expected!");
9579
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9580
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9581
                        ok = 0 ;
9582
                    end
9583
                end
9584
            end
9585
        end
9586 15 mihad
    end
9587 45 mihad
 
9588
    if (ok)
9589
        test_ok ;
9590 15 mihad
end //main
9591
endtask //find_pci_devices
9592
 
9593
task find_device ;
9594
    input [31:0] device_num ;
9595
    output  found ;
9596
 
9597
    reg [31:0] read_data ;
9598
begin
9599
    found = 1'b0 ;
9600
 
9601
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9602 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9603 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9604
    else
9605
    begin
9606
        $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]) ;
9607
        found = 1'b1 ;
9608
    end
9609
end
9610
endtask //find_device
9611 45 mihad
`endif
9612 15 mihad
 
9613
/*task set_bridge_parameters ;
9614
    reg [11:0] current_offset ;
9615
    reg [2:0] result ;
9616
    reg [31:0] write_data ;
9617
begin
9618
    // set burst size
9619
    // set latency timer
9620
    current_offset = 12'h00C ;
9621
    // set burst size to 16 and latency timer to 8
9622
    write_data     = {24'h0000_08, system_burst_size} ;
9623
    config_write(current_offset, write_data, 4'b1111) ;
9624
 
9625
    // set io image
9626
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9627
    write_data = 32'h0000_000_3 ;
9628
    config_write(current_offset, write_data, 4'b1111) ;
9629
 
9630
 
9631
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9632
    write_data = 32'h0001_000_1 ;
9633
    config_write(current_offset, write_data, 4'b1111) ;
9634
 
9635
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9636
    write_data = 32'hFFFF_0000 ;
9637
    config_write(current_offset, write_data, 4'b1111) ;
9638
 
9639
    // set memory image
9640
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9641
    write_data = 32'h0000_000_7 ;
9642
    config_write(current_offset, write_data, 4'b1111) ;
9643
 
9644
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9645
    write_data = 32'h0002_000_0 ;
9646
    config_write(current_offset, write_data, 4'b1111) ;
9647
 
9648
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9649
    write_data = 32'h0001_0000 ;
9650
    config_write(current_offset, write_data, 4'b1111) ;
9651
 
9652
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9653
    write_data = 32'hFFFF_0000 ;
9654
    config_write(current_offset, write_data, 4'b1111) ;
9655
 
9656
    // set parameters for bridge's target unit
9657
    // image control 0
9658
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9659
    write_data     = 32'h0000_0002 ;
9660
    config_write(current_offset, write_data, 4'b0001) ;
9661
 
9662
    // base_address 0
9663
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9664
    write_data      = 32'h2000_0000 ;
9665
    config_write(current_offset, write_data, 4'b1111) ;
9666
 
9667
    // address mask 0
9668
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9669
    write_data     = 32'hFFFF_F000 ;
9670
    config_write(current_offset, write_data, 4'b1111) ;
9671
 
9672
    // command register - enable response to io and mem space and PCI master
9673
    current_offset = 12'h004 ;
9674
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9675
    config_write(current_offset, write_data, 4'b1111) ;
9676
end
9677
endtask // set_bridge_parameters
9678
*/
9679
 
9680
task configuration_cycle_write ;
9681
    input [7:0]  bus_num ;
9682
    input [4:0]  device_num ;
9683
    input [2:0]  func_num ;
9684
    input [5:0]  reg_num ;
9685
    input [1:0]  type ;
9686
    input [3:0]  byte_enables ;
9687
    input [31:0] data ;
9688
 
9689
    reg [31:0] write_address ;
9690
    reg in_use ;
9691
    reg ok ;
9692
begin:main
9693
 
9694
    if ( in_use === 1 )
9695
    begin
9696 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9697 15 mihad
        disable main ;
9698
    end
9699
 
9700 45 mihad
    if ( (device_num > 20) && (type === 0) )
9701 15 mihad
    begin
9702
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9703
        disable main ;
9704
    end
9705
 
9706
    in_use = 1 ;
9707
 
9708 45 mihad
 
9709
`ifdef HOST
9710
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9711
`else
9712
`ifdef GUEST
9713
 
9714 15 mihad
    if ( type )
9715
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9716
    else
9717
    begin
9718
        write_address = 0 ;
9719
        write_address[10:0] = { func_num, reg_num, type } ;
9720
        write_address[11 + device_num] = 1'b1 ;
9721
    end
9722 45 mihad
 
9723
    fork
9724 15 mihad
    begin
9725 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9726
                            write_address,
9727
                            data, ~byte_enables,
9728
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9729
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9730
        do_pause(1) ;
9731 15 mihad
    end
9732 45 mihad
    begin
9733
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9734
    end
9735
    join
9736
`endif
9737
`endif
9738
 
9739
    in_use = 0 ;
9740
end
9741
endtask // configuration_cycle_write
9742 15 mihad
 
9743 45 mihad
task configuration_cycle_read ;
9744
    input [7:0]  bus_num ;
9745
    input [4:0]  device_num ;
9746
    input [2:0]  func_num ;
9747
    input [5:0]  reg_num ;
9748
    input [1:0]  type ;
9749
    input [3:0]  byte_enables ;
9750
    output [31:0] data ;
9751 15 mihad
 
9752 45 mihad
    reg [31:0] read_address ;
9753
    reg in_use ;
9754 15 mihad
 
9755 45 mihad
    reg master_check_data_prev ;
9756
begin:main
9757 15 mihad
 
9758 45 mihad
    if ( in_use === 1 )
9759 15 mihad
    begin
9760 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9761
        data = 32'hxxxx_xxxx ;
9762
        disable main ;
9763 15 mihad
    end
9764
 
9765 45 mihad
    in_use = 1 ;
9766 15 mihad
 
9767 45 mihad
`ifdef HOST
9768
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9769
`else
9770
`ifdef GUEST
9771
     master_check_data_prev = master1_check_received_data ;
9772 15 mihad
     if ( type )
9773 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9774 15 mihad
     else
9775
     begin
9776 45 mihad
         read_address = 0 ;
9777
         read_address[10:0] = { func_num, reg_num, type } ;
9778
         read_address[11 + device_num] = 1'b1 ;
9779 15 mihad
     end
9780 45 mihad
 
9781
     fork
9782
     begin
9783
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9784
                 read_address,
9785 15 mihad
                 data, ~byte_enables,
9786
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9787
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9788 45 mihad
         do_pause(1) ;
9789
     end
9790
     begin
9791
         @(master1_received_data_valid) ;
9792
         data = master1_received_data ;
9793
     end
9794
     join
9795 15 mihad
 
9796 45 mihad
    master1_check_received_data = master_check_data_prev ;
9797
`endif
9798
`endif
9799
 
9800 15 mihad
    in_use = 0 ;
9801
 
9802 45 mihad
end //main
9803
endtask // configuration_cycle_read
9804
 
9805 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9806
task test_conf_cycle_type1_reference ;
9807
    reg [31:0] address ;
9808
    reg in_use ;
9809
 
9810
    reg master_check_data_prev ;
9811
    reg [31:0] data ;
9812
    reg monitor_ok ;
9813
    reg master_ok ;
9814
begin:main
9815
 
9816
    if ( in_use === 1 )
9817
    begin
9818
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9819
        disable main ;
9820
    end
9821
 
9822
    in_use = 1 ;
9823
 
9824
    master_check_data_prev = master1_check_received_data ;
9825
 
9826
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9827
    address = `TAR0_IDSEL_ADDR ;
9828
 
9829
    address[1:0] = 2'b01 ;
9830
 
9831
    `ifdef HOST
9832
        conf_cyc_type1_target_bus_num = 255 ;
9833
    `endif
9834
    master_ok = 1 ;
9835
    fork
9836
    begin
9837
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9838
        do_pause(1) ;
9839
    end
9840
    begin:error_monitor1
9841
        @(error_event_int) ;
9842
        master_ok = 0 ;
9843
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9844
    end
9845
    begin
9846
        pci_transaction_progress_monitor
9847
        (
9848
            address,                                                // expected address on PCI bus
9849
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9850
            0,                                                      // expected number of succesfull data phases
9851
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9852
            1'b1,                                                   // monitor checking/not checking number of transfers
9853
            1'b0,                                                   // monitor checking/not checking number of cycles
9854
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9855
            monitor_ok                                              // status - 1 success, 0 failure
9856
        ) ;
9857
 
9858
        @(posedge pci_clock);
9859
        #1 ;
9860
 
9861
        if (master_ok)
9862
            disable error_monitor1 ;
9863
 
9864
        if (!monitor_ok)
9865
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9866
    end
9867
    join
9868
 
9869
    if (monitor_ok && master_ok)
9870
        test_ok ;
9871
 
9872
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9873
    master_ok = 1 ;
9874
    fork
9875
    begin
9876
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9877
        do_pause(1) ;
9878
    end
9879
    begin:error_monitor2
9880
        @(error_event_int) ;
9881
        master_ok = 0 ;
9882
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9883
    end
9884
    begin
9885
        pci_transaction_progress_monitor
9886
        (
9887
            address,                                                // expected address on PCI bus
9888
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9889
            0,                                                      // expected number of succesfull data phases
9890
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9891
            1'b1,                                                   // monitor checking/not checking number of transfers
9892
            1'b0,                                                   // monitor checking/not checking number of cycles
9893
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9894
            monitor_ok                                              // status - 1 success, 0 failure
9895
        ) ;
9896
 
9897
        @(posedge pci_clock);
9898
        #1 ;
9899
 
9900
        if (master_ok)
9901
            disable error_monitor2 ;
9902
 
9903
        if (!monitor_ok)
9904
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9905
    end
9906
    join
9907
 
9908
    master1_check_received_data = master_check_data_prev ;
9909
 
9910
    if (monitor_ok && master_ok)
9911
        test_ok ;
9912
 
9913
    in_use = 0 ;
9914
 
9915
end //main
9916
endtask // test_conf_cycle_type1_reference
9917
`endif
9918
 
9919 45 mihad
`ifdef HOST
9920
task generate_configuration_cycle ;
9921 15 mihad
    input [7:0]  bus_num ;
9922
    input [4:0]  device_num ;
9923
    input [2:0]  func_num ;
9924
    input [5:0]  reg_num ;
9925
    input [1:0]  type ;
9926
    input [3:0]  byte_enables ;
9927 45 mihad
    inout [31:0] data ;
9928
    input        read0_write1 ;
9929 15 mihad
 
9930
    reg `READ_STIM_TYPE read_data ;
9931
    reg `WB_TRANSFER_FLAGS  flags ;
9932
    reg `READ_RETURN_TYPE   read_status ;
9933
 
9934
    reg `WRITE_STIM_TYPE   write_data ;
9935
    reg `WRITE_RETURN_TYPE write_status ;
9936
 
9937 45 mihad
    reg [31:0] pci_address ;
9938 15 mihad
    reg in_use ;
9939 45 mihad
    reg ok ;
9940 15 mihad
 
9941
    reg [31:0] temp_var ;
9942
begin:main
9943
 
9944
    if ( in_use === 1 )
9945
    begin
9946 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
9947 15 mihad
        data = 32'hxxxx_xxxx ;
9948
        disable main ;
9949
    end
9950
 
9951 45 mihad
    in_use = 1 ;
9952
 
9953
    if ( type )
9954
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9955
    else
9956 15 mihad
    begin
9957 45 mihad
        pci_address = 0 ;
9958
        pci_address[10:0] = { func_num, reg_num, type } ;
9959
        if (device_num <= 20)
9960
            pci_address[11 + device_num] = 1'b1 ;
9961
    end
9962
 
9963
    // setup flags
9964
    flags = 0 ;
9965
    flags`INIT_WAITS   = tb_init_waits ;
9966
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
9967
 
9968
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
9969
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
9970
 
9971
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
9972
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9973
    write_data`WRITE_SEL      = 4'hF ;
9974
    write_data`WRITE_TAG_STIM = 0 ;
9975
 
9976
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
9977
 
9978
    // check if write succeeded
9979
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
9980
    begin
9981
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
9982 15 mihad
        data = 32'hxxxx_xxxx ;
9983 45 mihad
        in_use = 0 ;
9984 15 mihad
        disable main ;
9985
    end
9986
 
9987 45 mihad
    // setup flags for wb master to handle retries and read and write data
9988
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
9989
 
9990
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
9991
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
9992
    read_data`READ_SEL          = byte_enables ;
9993
    write_data`WRITE_SEL        = byte_enables ;
9994
    read_data`READ_TAG_STIM     = 0 ;
9995
    write_data`WRITE_TAG_STIM   = 0 ;
9996
    write_data`WRITE_DATA       = data ;
9997
 
9998
    ok = 0 ;
9999
 
10000
    fork
10001
    begin
10002
        if (read0_write1 === 0)
10003
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10004
        else
10005
        if (read0_write1 === 1)
10006
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10007
    end
10008
    begin
10009
        pci_transaction_progress_monitor
10010
        (
10011
            pci_address,                                            // expected address on PCI bus
10012
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10013
            1,                                                      // expected number of succesfull data phases
10014
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10015
            1'b0,                                                   // monitor checking/not checking number of transfers
10016
            1'b0,                                                   // monitor checking/not checking number of cycles
10017
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10018
            ok                                                      // status - 1 success, 0 failure
10019
        ) ;
10020
    end
10021
    join
10022
 
10023
    // check if transfer succeeded
10024
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10025
    begin
10026
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10027
        data = 32'hxxxx_xxxx ;
10028
        in_use = 0 ;
10029
        disable main ;
10030
    end
10031
 
10032
    if (!ok)
10033
    begin
10034
        data = 32'hxxxx_xxxx ;
10035
        in_use = 0 ;
10036
        disable main ;
10037
    end
10038
 
10039
    if (read0_write1 === 0)
10040
        data = read_status`READ_DATA ;
10041
 
10042
    in_use = 0 ;
10043
end
10044
endtask // generate_configuration_cycle
10045
 
10046
task test_configuration_cycle_target_abort ;
10047
    reg `READ_STIM_TYPE read_data ;
10048
    reg `WB_TRANSFER_FLAGS  flags ;
10049
    reg `READ_RETURN_TYPE   read_status ;
10050
 
10051
    reg `WRITE_STIM_TYPE   write_data ;
10052
    reg `WRITE_RETURN_TYPE write_status ;
10053
 
10054
    reg [31:0] pci_address ;
10055
    reg in_use ;
10056
    reg ok_pci ;
10057
    reg ok_wb  ;
10058
    reg ok     ;
10059
 
10060
    reg [31:0] temp_var ;
10061
 
10062
begin:main
10063
 
10064
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10065
 
10066
    if ( in_use === 1 )
10067
    begin
10068
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10069
        disable main ;
10070
    end
10071
 
10072 15 mihad
    in_use = 1 ;
10073
 
10074 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10075
 
10076 15 mihad
    // setup flags
10077
    flags = 0 ;
10078 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10079
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10080 15 mihad
 
10081
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10082
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10083
 
10084
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10085 45 mihad
    temp_var                  = 0 ;
10086
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10087
    write_data`WRITE_DATA     = temp_var ;
10088 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10089
    write_data`WRITE_TAG_STIM = 0 ;
10090
 
10091
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10092
 
10093
    // check if write succeeded
10094
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10095
    begin
10096
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10097 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10098
        in_use = 0 ;
10099 15 mihad
        disable main ;
10100
    end
10101
 
10102 45 mihad
    // setup flags for wb master to handle retries and read and write data
10103 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10104
 
10105 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10106
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10107 15 mihad
 
10108 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10109
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10110
    read_data`READ_SEL          = 4'hF ;
10111
    write_data`WRITE_SEL        = 4'hF ;
10112
    read_data`READ_TAG_STIM     = 0 ;
10113
    write_data`WRITE_TAG_STIM   = 0 ;
10114
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10115
 
10116
    ok_pci = 0 ;
10117
    ok_wb  = 1 ;
10118
 
10119
    // set target to terminate with target abort
10120
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10121
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10122
    fork
10123
    begin
10124
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10125
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10126
        begin
10127
            $display("Time %t", $time) ;
10128
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10129
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10130
            ok_wb = 0 ;
10131
        end
10132
 
10133
        config_read( 12'h4, 4'hF, temp_var ) ;
10134
        if ( temp_var[29] !== 0 )
10135
        begin
10136
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10137
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10138
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10139
            ok_wb = 0 ;
10140
        end
10141
 
10142
        if ( temp_var[28] !== 1 )
10143
        begin
10144
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10145
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10146
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10147
            ok_wb = 0 ;
10148
        end
10149
 
10150
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10151
 
10152
        if (ok !== 1)
10153
        begin
10154
            ok_wb = 0 ;
10155
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10156
            $display("Write to PCI Device Status Register failed") ;
10157
            test_fail("Write to PCI Device Status Register failed") ;
10158
        end
10159
 
10160
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10161
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10162
        begin
10163
            $display("Time %t", $time) ;
10164
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10165
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10166
            ok_wb = 0 ;
10167
        end
10168
 
10169
        config_read( 12'h4, 4'hF, temp_var ) ;
10170
        if ( temp_var[29] !== 0 )
10171
        begin
10172
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10173
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10174
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10175
            ok_wb = 0 ;
10176
        end
10177
 
10178
        if ( temp_var[28] !== 1 )
10179
        begin
10180
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10181
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10182
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10183
            ok_wb = 0 ;
10184
        end
10185
 
10186
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10187
 
10188
        if (ok !== 1)
10189
        begin
10190
            ok_wb = 0 ;
10191
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10192
            $display("Write to PCI Device Status Register failed") ;
10193
            test_fail("Write to PCI Device Status Register failed") ;
10194
        end
10195
    end
10196
    begin
10197
        pci_transaction_progress_monitor
10198
        (
10199
            pci_address,                                            // expected address on PCI bus
10200
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10201
            0,                                                      // expected number of succesfull data phases
10202
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10203
            1'b1,                                                   // monitor checking/not checking number of transfers
10204
            1'b0,                                                   // monitor checking/not checking number of cycles
10205
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10206
            ok_pci                                                  // status - 1 success, 0 failure
10207
        ) ;
10208
 
10209
        if (ok_pci)
10210
        begin
10211
            pci_transaction_progress_monitor
10212
            (
10213
                pci_address,                                            // expected address on PCI bus
10214
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10215
                0,                                                      // expected number of succesfull data phases
10216
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10217
                1'b1,                                                   // monitor checking/not checking number of transfers
10218
                1'b0,                                                   // monitor checking/not checking number of cycles
10219
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10220
                ok_pci                                                  // status - 1 success, 0 failure
10221
            ) ;
10222
        end
10223
 
10224
        if (!ok_pci)
10225
        begin
10226
            $display("Time %t", $time) ;
10227
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10228
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10229
        end
10230
    end
10231
    join
10232
 
10233
    if (ok_pci && ok_wb)
10234
    begin
10235
        test_ok ;
10236
    end
10237
 
10238
    in_use = 0 ;
10239
 
10240
    // set target to terminate normally
10241
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10242
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10243
end
10244
endtask // test_configuration_cycle_target_abort
10245
 
10246
task test_configuration_cycle_type1_generation ;
10247
    reg `READ_STIM_TYPE read_data ;
10248
    reg `WB_TRANSFER_FLAGS  flags ;
10249
    reg `READ_RETURN_TYPE   read_status ;
10250
 
10251
    reg `WRITE_STIM_TYPE   write_data ;
10252
    reg `WRITE_RETURN_TYPE write_status ;
10253
 
10254
    reg [31:0] pci_address ;
10255
    reg in_use ;
10256
    reg ok_pci ;
10257
    reg ok_wb  ;
10258
    reg ok     ;
10259
 
10260
    reg [31:0] temp_var ;
10261
 
10262
begin:main
10263
 
10264
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10265
    conf_cyc_type1_target_data = 0 ;
10266
    conf_cyc_type1_target_bus_num = 0;
10267
 
10268
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10269
 
10270
    if ( in_use === 1 )
10271
    begin
10272
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10273
        disable main ;
10274
    end
10275
 
10276
    in_use = 1 ;
10277
 
10278
    pci_address        = 32'hAAAA_AAAA ;
10279
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10280
 
10281
    // setup flags
10282
    flags = 0 ;
10283
    flags`INIT_WAITS   = tb_init_waits ;
10284
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10285
 
10286
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10287
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10288
 
10289
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10290
    write_data`WRITE_DATA     = pci_address ;
10291
    write_data`WRITE_SEL      = 4'hF ;
10292
    write_data`WRITE_TAG_STIM = 0 ;
10293
 
10294
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10295
 
10296
    // check if write succeeded
10297
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10298
    begin
10299
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10300
        test_fail("write to configuration cycle address register was not possible") ;
10301
        in_use = 0 ;
10302
        disable main ;
10303
    end
10304
 
10305
    // setup flags for wb master to handle retries and read and write data
10306
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10307
 
10308
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10309
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10310
 
10311
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10312
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10313
    read_data`READ_SEL          = 4'hF ;
10314
    write_data`WRITE_SEL        = 4'hF ;
10315
    read_data`READ_TAG_STIM     = 0 ;
10316
    write_data`WRITE_TAG_STIM   = 0 ;
10317
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10318
 
10319
    ok_pci = 0 ;
10320
    ok_wb  = 1 ;
10321
 
10322
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10323
    pci_address[31:24] = 0 ;
10324
    fork
10325
    begin
10326
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10327
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10328
        begin
10329
            $display("Time %t", $time) ;
10330
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10331
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10332
            ok_wb = 0 ;
10333
        end
10334
 
10335
        config_read( 12'h4, 4'hF, temp_var ) ;
10336
        if ( temp_var[29] !== 1 )
10337
        begin
10338
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10339
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10340
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10341
            ok_wb = 0 ;
10342
        end
10343
 
10344
        if ( temp_var[28] !== 0 )
10345
        begin
10346
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10347
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10348
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10349
            ok_wb = 0 ;
10350
        end
10351
 
10352
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10353
 
10354
        if (ok !== 1)
10355
        begin
10356
            ok_wb = 0 ;
10357
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10358
            $display("Write to PCI Device Status Register failed") ;
10359
            test_fail("Write to PCI Device Status Register failed") ;
10360
        end
10361
 
10362
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10363
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10364
        begin
10365
            $display("Time %t", $time) ;
10366
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10367
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10368
            ok_wb = 0 ;
10369
        end
10370
 
10371
        config_read( 12'h4, 4'hF, temp_var ) ;
10372
        if ( temp_var[29] !== 1 )
10373
        begin
10374
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10375
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10376
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10377
            ok_wb = 0 ;
10378
        end
10379
 
10380
        if ( temp_var[28] !== 0 )
10381
        begin
10382
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10383
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10384
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10385
            ok_wb = 0 ;
10386
        end
10387
 
10388
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10389
 
10390
        if (ok !== 1)
10391
        begin
10392
            ok_wb = 0 ;
10393
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10394
            $display("Write to PCI Device Status Register failed") ;
10395
            test_fail("Write to PCI Device Status Register failed") ;
10396
        end
10397
    end
10398
    begin
10399
        pci_transaction_progress_monitor
10400
        (
10401
            pci_address,                                            // expected address on PCI bus
10402
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10403
            0,                                                      // expected number of succesfull data phases
10404
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10405
            1'b1,                                                   // monitor checking/not checking number of transfers
10406
            1'b0,                                                   // monitor checking/not checking number of cycles
10407
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10408
            ok_pci                                                  // status - 1 success, 0 failure
10409
        ) ;
10410
 
10411
        if (ok_pci)
10412
        begin
10413
            pci_transaction_progress_monitor
10414
            (
10415
                pci_address,                                            // expected address on PCI bus
10416
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10417
                0,                                                      // expected number of succesfull data phases
10418
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10419
                1'b1,                                                   // monitor checking/not checking number of transfers
10420
                1'b0,                                                   // monitor checking/not checking number of cycles
10421
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10422
                ok_pci                                                  // status - 1 success, 0 failure
10423
            ) ;
10424
        end
10425
 
10426
        if (!ok_pci)
10427
        begin
10428
            $display("Time %t", $time) ;
10429
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10430
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10431
        end
10432
    end
10433
    join
10434
 
10435
    if (ok_pci && ok_wb)
10436
    begin
10437
        test_ok ;
10438
    end
10439
 
10440
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10441
    conf_cyc_type1_target_data = 0 ;
10442
    conf_cyc_type1_target_bus_num = 8'h55;
10443
 
10444
    pci_address      = 32'h5555_5555 ;
10445
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10446
 
10447
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10448
 
10449
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10450
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10451
 
10452
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10453
    write_data`WRITE_DATA     = pci_address ;
10454
    write_data`WRITE_SEL      = 4'hF ;
10455
    write_data`WRITE_TAG_STIM = 0 ;
10456
 
10457
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10458
 
10459
    // check if write succeeded
10460
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10461
    begin
10462
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10463
        test_fail("write to configuration cycle address register was not possible") ;
10464
        in_use = 0 ;
10465
        disable main ;
10466
    end
10467
 
10468
    // setup flags for wb master to handle retries and read and write data
10469
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10470
 
10471
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10472
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10473
 
10474
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10475
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10476
    read_data`READ_SEL          = 4'hF ;
10477
    write_data`WRITE_SEL        = 4'hF ;
10478
    read_data`READ_TAG_STIM     = 0 ;
10479
    write_data`WRITE_TAG_STIM   = 0 ;
10480
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10481
 
10482
    ok_pci = 0 ;
10483
    ok_wb  = 1 ;
10484
 
10485
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10486
    pci_address[31:24] = 0 ;
10487
    fork
10488
    begin
10489
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10490
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10491
        begin
10492
            $display("Time %t", $time) ;
10493
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10494
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10495
            ok_wb = 0 ;
10496
        end
10497
 
10498
        config_read( 12'h4, 4'hF, temp_var ) ;
10499
        if ( temp_var[29] !== 0 )
10500
        begin
10501
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10502
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10503
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10504
            ok_wb = 0 ;
10505
        end
10506
 
10507
        if ( temp_var[28] !== 1 )
10508
        begin
10509
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10510
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10511
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10512
            ok_wb = 0 ;
10513
        end
10514
 
10515
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10516
 
10517
        if (ok !== 1)
10518
        begin
10519
            ok_wb = 0 ;
10520
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10521
            $display("Write to PCI Device Status Register failed") ;
10522
            test_fail("Write to PCI Device Status Register failed") ;
10523
        end
10524
 
10525
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10526
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10527
        begin
10528
            $display("Time %t", $time) ;
10529
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10530
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10531
            ok_wb = 0 ;
10532
        end
10533
 
10534
        config_read( 12'h4, 4'hF, temp_var ) ;
10535
        if ( temp_var[29] !== 0 )
10536
        begin
10537
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10538
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10539
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10540
            ok_wb = 0 ;
10541
        end
10542
 
10543
        if ( temp_var[28] !== 1 )
10544
        begin
10545
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10546
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10547
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10548
            ok_wb = 0 ;
10549
        end
10550
 
10551
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10552
 
10553
        if (ok !== 1)
10554
        begin
10555
            ok_wb = 0 ;
10556
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10557
            $display("Write to PCI Device Status Register failed") ;
10558
            test_fail("Write to PCI Device Status Register failed") ;
10559
        end
10560
    end
10561
    begin
10562
        pci_transaction_progress_monitor
10563
        (
10564
            pci_address,                                            // expected address on PCI bus
10565
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10566
            0,                                                      // expected number of succesfull data phases
10567
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10568
            1'b1,                                                   // monitor checking/not checking number of transfers
10569
            1'b0,                                                   // monitor checking/not checking number of cycles
10570
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10571
            ok_pci                                                  // status - 1 success, 0 failure
10572
        ) ;
10573
 
10574
        if (ok_pci)
10575
        begin
10576
            pci_transaction_progress_monitor
10577
            (
10578
                pci_address,                                            // expected address on PCI bus
10579
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10580
                0,                                                      // expected number of succesfull data phases
10581
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10582
                1'b1,                                                   // monitor checking/not checking number of transfers
10583
                1'b0,                                                   // monitor checking/not checking number of cycles
10584
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10585
                ok_pci                                                  // status - 1 success, 0 failure
10586
            ) ;
10587
        end
10588
 
10589
        if (!ok_pci)
10590
        begin
10591
            $display("Time %t", $time) ;
10592
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10593
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10594
        end
10595
    end
10596
    join
10597
 
10598
    if (ok_pci && ok_wb)
10599
    begin
10600
        test_ok ;
10601
    end
10602
 
10603
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10604
 
10605
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10606
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10607
    conf_cyc_type1_target_bus_num = 8'hAA;
10608
 
10609
    pci_address      = 32'hAAAA_AAAA ;
10610
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10611
 
10612
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10613
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10614
 
10615
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10616
    write_data`WRITE_DATA     = pci_address ;
10617
    write_data`WRITE_SEL      = 4'hF ;
10618
    write_data`WRITE_TAG_STIM = 0 ;
10619
 
10620
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10621
 
10622
    // check if write succeeded
10623
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10624
    begin
10625
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10626
        test_fail("write to configuration cycle address register was not possible") ;
10627
        in_use = 0 ;
10628
        disable main ;
10629
    end
10630
 
10631
    // setup flags for wb master to handle retries and read and write data
10632
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10633
 
10634
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10635
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10636
 
10637
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10638
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10639
    read_data`READ_SEL          = 4'b0101 ;
10640
    write_data`WRITE_SEL        = 4'b1010 ;
10641
    read_data`READ_TAG_STIM     = 0 ;
10642
    write_data`WRITE_TAG_STIM   = 0 ;
10643
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10644
 
10645
    ok_pci = 0 ;
10646
    ok_wb  = 1 ;
10647
 
10648
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10649
    pci_address[31:24] = 0 ;
10650
 
10651
    fork
10652
    begin
10653
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10654
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10655
        begin
10656
            $display("Time %t", $time) ;
10657
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10658
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10659
            ok_wb = 0 ;
10660
        end
10661
 
10662
        config_read( 12'h4, 4'hF, temp_var ) ;
10663
        if ( temp_var[29] !== 0 )
10664
        begin
10665
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10666
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10667
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10668
            ok_wb = 0 ;
10669
        end
10670
 
10671
        if ( temp_var[28] !== 0 )
10672
        begin
10673
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10674
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10675
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10676
            ok_wb = 0 ;
10677
        end
10678
 
10679
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10680
 
10681
        if (ok !== 1)
10682
        begin
10683
            ok_wb = 0 ;
10684
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10685
            $display("Write to PCI Device Status Register failed") ;
10686
            test_fail("Write to PCI Device Status Register failed") ;
10687
        end
10688
 
10689
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10690
        begin
10691
            ok_wb = 0 ;
10692
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10693
            $display("Read Data provided by the bridge was not as expected!") ;
10694
            test_fail("Read Data provided by the bridge was not as expected") ;
10695
        end
10696
 
10697
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10698
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10699
        begin
10700
            $display("Time %t", $time) ;
10701
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10702
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10703
            ok_wb = 0 ;
10704
        end
10705
 
10706
        config_read( 12'h4, 4'hF, temp_var ) ;
10707
        if ( temp_var[29] !== 0 )
10708
        begin
10709
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10710
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10711
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10712
            ok_wb = 0 ;
10713
        end
10714
 
10715
        if ( temp_var[28] !== 0 )
10716
        begin
10717
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10718
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10719
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10720
            ok_wb = 0 ;
10721
        end
10722
 
10723
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10724
 
10725
        if (ok !== 1)
10726
        begin
10727
            ok_wb = 0 ;
10728
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10729
            $display("Write to PCI Device Status Register failed") ;
10730
            test_fail("Write to PCI Device Status Register failed") ;
10731
        end
10732
 
10733
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10734
        begin
10735
            ok_wb = 0 ;
10736
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10737
            $display("Data written by the bridge was not as expected!") ;
10738
            test_fail("Data written by the bridge was not as expected") ;
10739
        end
10740
 
10741
    end
10742
    begin
10743
        ok = 1 ;
10744
        repeat(8)
10745
        begin
10746
            pci_transaction_progress_monitor
10747
            (
10748
                pci_address,                                            // expected address on PCI bus
10749
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10750
                0,                                                      // expected number of succesfull data phases
10751
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10752
                1'b1,                                                   // monitor checking/not checking number of transfers
10753
                1'b0,                                                   // monitor checking/not checking number of cycles
10754
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10755
                ok_pci                                                  // status - 1 success, 0 failure
10756
            ) ;
10757
 
10758
            if (!ok_pci)
10759
            begin
10760
                ok = 0 ;
10761
                $display("Time %t", $time) ;
10762
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10763
            end
10764
        end
10765
 
10766
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10767
 
10768
        pci_transaction_progress_monitor
10769
        (
10770
            pci_address,                                            // expected address on PCI bus
10771
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10772
            1,                                                      // expected number of succesfull data phases
10773
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10774
            1'b1,                                                   // monitor checking/not checking number of transfers
10775
            1'b0,                                                   // monitor checking/not checking number of cycles
10776
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10777
            ok_pci                                                  // status - 1 success, 0 failure
10778
        ) ;
10779
 
10780
        if (!ok_pci)
10781
        begin
10782
            ok = 0 ;
10783
            $display("Time %t", $time) ;
10784
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10785
        end
10786
 
10787
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10788
        repeat(8)
10789
        begin
10790
            pci_transaction_progress_monitor
10791
            (
10792
                pci_address,                                            // expected address on PCI bus
10793
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10794
                0,                                                      // expected number of succesfull data phases
10795
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10796
                1'b1,                                                   // monitor checking/not checking number of transfers
10797
                1'b0,                                                   // monitor checking/not checking number of cycles
10798
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10799
                ok_pci                                                  // status - 1 success, 0 failure
10800
            ) ;
10801
 
10802
            if (!ok_pci)
10803
            begin
10804
                ok = 0 ;
10805
                $display("Time %t", $time) ;
10806
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10807
            end
10808
        end
10809
 
10810
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10811
        pci_transaction_progress_monitor
10812
        (
10813
            pci_address,                                            // expected address on PCI bus
10814
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10815
            1,                                                      // expected number of succesfull data phases
10816
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10817
            1'b1,                                                   // monitor checking/not checking number of transfers
10818
            1'b0,                                                   // monitor checking/not checking number of cycles
10819
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10820
            ok_pci                                                  // status - 1 success, 0 failure
10821
        ) ;
10822
 
10823
        if (!ok_pci)
10824
        begin
10825
            ok = 0 ;
10826
            $display("Time %t", $time) ;
10827
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10828
        end
10829
 
10830
        if (!ok)
10831
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10832
    end
10833
    join
10834
 
10835
    if (ok_pci && ok_wb)
10836
    begin
10837
        test_ok ;
10838
    end
10839
 
10840
    in_use = 0 ;
10841
end
10842
endtask // test_configuration_cycle_type1_generation
10843
`endif
10844
 
10845
task test_initial_conf_values ;
10846
    reg [11:0] register_offset ;
10847
    reg [31:0] expected_value ;
10848
    reg        failed ;
10849
`ifdef HOST
10850
    reg `READ_STIM_TYPE    read_data ;
10851
    reg `WB_TRANSFER_FLAGS flags ;
10852
    reg `READ_RETURN_TYPE  read_status ;
10853
 
10854
    reg `WRITE_STIM_TYPE   write_data ;
10855
    reg `WRITE_RETURN_TYPE write_status ;
10856
begin
10857
    failed     = 0 ;
10858
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10859
    flags      = 0 ;
10860
    read_data  = 0 ;
10861
    write_data = 0 ;
10862
 
10863
    read_data`READ_SEL = 4'hF ;
10864
 
10865
    flags`INIT_WAITS           = tb_init_waits ;
10866
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10867
 
10868
    // test MEM/IO map bit initial value in each PCI BAR
10869
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10870
 
10871
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10872
 
10873 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10874
 
10875 45 mihad
    `ifdef NO_CNF_IMAGE
10876
        `ifdef PCI_IMAGE0
10877
            if (`PCI_AM0)
10878
                expected_value = `PCI_BA0_MEM_IO ;
10879
            else
10880
                expected_value = 32'h0000_0000 ;
10881
        `else
10882
            expected_value = 32'h0000_0000 ;
10883
        `endif
10884
    `else
10885
        expected_value = 32'h0000_0000 ;
10886
    `endif
10887
 
10888 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10889
    begin
10890 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10891
        failed = 1 ;
10892 15 mihad
    end
10893 45 mihad
    else
10894
    begin
10895
        if (read_status`READ_DATA !== expected_value)
10896
        begin
10897
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10898
            failed = 1 ;
10899
        end
10900
    end
10901 15 mihad
 
10902 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10903 15 mihad
 
10904 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10905
 
10906
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10907
 
10908
    if (`PCI_AM1)
10909
        expected_value = `PCI_BA1_MEM_IO ;
10910
    else
10911
        expected_value = 32'h0000_0000 ;
10912
 
10913
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10914
    begin
10915
        test_fail("read from P_BA1 register didn't succeede") ;
10916
        failed = 1 ;
10917
    end
10918
    else
10919
    begin
10920
        if (read_status`READ_DATA !== expected_value)
10921
        begin
10922
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
10923
            failed = 1 ;
10924
        end
10925
    end
10926
 
10927
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
10928
 
10929
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10930
 
10931
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10932
 
10933
    `ifdef PCI_IMAGE2
10934
        if (`PCI_AM2)
10935
            expected_value = `PCI_BA2_MEM_IO ;
10936
        else
10937
            expected_value = 32'h0000_0000 ;
10938 15 mihad
    `else
10939 45 mihad
        expected_value = 32'h0000_0000 ;
10940
    `endif
10941 15 mihad
 
10942 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10943
    begin
10944
        test_fail("read from P_BA2 register didn't succeede") ;
10945
        failed = 1 ;
10946
    end
10947
    else
10948
    begin
10949
        if (read_status`READ_DATA !== expected_value)
10950
        begin
10951
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
10952
            failed = 1 ;
10953
        end
10954
    end
10955 15 mihad
 
10956 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
10957
 
10958
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10959
 
10960
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10961
 
10962
    `ifdef PCI_IMAGE3
10963
        if (`PCI_AM3)
10964
            expected_value = `PCI_BA3_MEM_IO ;
10965
        else
10966
            expected_value = 32'h0000_0000 ;
10967
    `else
10968
        expected_value = 32'h0000_0000 ;
10969 15 mihad
    `endif
10970 45 mihad
 
10971
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10972
    begin
10973
        test_fail("read from P_BA3 register didn't succeede") ;
10974
        failed = 1 ;
10975
    end
10976
    else
10977
    begin
10978
        if (read_status`READ_DATA !== expected_value)
10979
        begin
10980
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
10981
            failed = 1 ;
10982
        end
10983
    end
10984
 
10985
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
10986
 
10987
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10988
 
10989
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10990
 
10991
    `ifdef PCI_IMAGE4
10992
        if (`PCI_AM4)
10993
            expected_value = `PCI_BA4_MEM_IO ;
10994
        else
10995
            expected_value = 32'h0000_0000 ;
10996
    `else
10997
        expected_value = 32'h0000_0000 ;
10998 15 mihad
    `endif
10999
 
11000 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11001
    begin
11002
        test_fail("read from P_BA4 register didn't succeede") ;
11003
        failed = 1 ;
11004
    end
11005
    else
11006
    begin
11007
        if (read_status`READ_DATA !== expected_value)
11008
        begin
11009
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11010
            failed = 1 ;
11011
        end
11012
    end
11013 15 mihad
 
11014 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11015 15 mihad
 
11016 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11017
 
11018
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11019
 
11020
    `ifdef PCI_IMAGE5
11021
        if(`PCI_AM5)
11022
            expected_value = `PCI_BA5_MEM_IO ;
11023
        else
11024
            expected_value = 32'h0000_0000 ;
11025
    `else
11026
        expected_value = 32'h0000_0000 ;
11027
    `endif
11028
 
11029
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11030
    begin
11031
        test_fail("read from P_BA5 register didn't succeede") ;
11032
        failed = 1 ;
11033
    end
11034
    else
11035
    begin
11036
        if (read_status`READ_DATA !== expected_value)
11037
        begin
11038
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11039
            failed = 1 ;
11040
        end
11041
    end
11042
 
11043
    // test Address Mask initial values
11044
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11045
 
11046
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11047
 
11048
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11049
 
11050
    `ifdef NO_CNF_IMAGE
11051
        `ifdef PCI_IMAGE0
11052
            expected_value = {`PCI_AM0, 12'h000};
11053
 
11054
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11055
        `else
11056
            expected_value = 32'h0000_0000 ;
11057
        `endif
11058
    `else
11059
        expected_value = 32'hFFFF_FFFF ;
11060
 
11061
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11062
    `endif
11063
 
11064
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11065
    begin
11066
        test_fail("read from P_AM0 register didn't succeede") ;
11067
        failed = 1 ;
11068
    end
11069
    else
11070
    begin
11071
        if (read_status`READ_DATA !== expected_value)
11072
        begin
11073
            test_fail("AM0 initial value was not set as defined");
11074
            failed = 1 ;
11075
        end
11076
    end
11077
 
11078
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11079
 
11080
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11081
 
11082
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11083
 
11084
    expected_value = {`PCI_AM1, 12'h000};
11085
 
11086
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11087
 
11088
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11089
    begin
11090
        test_fail("read from P_AM1 register didn't succeede") ;
11091
        failed = 1 ;
11092
    end
11093
    else
11094
    begin
11095
        if (read_status`READ_DATA !== expected_value)
11096
        begin
11097
            test_fail("AM1 initial value was not set as defined");
11098
            failed = 1 ;
11099
        end
11100
    end
11101
 
11102
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11103
 
11104
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11105
 
11106
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11107
 
11108
    `ifdef PCI_IMAGE2
11109
        expected_value = {`PCI_AM2, 12'h000};
11110
 
11111
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11112
    `else
11113
        expected_value = 32'h0000_0000 ;
11114
    `endif
11115
 
11116
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11117
    begin
11118
        test_fail("read from P_AM2 register didn't succeede") ;
11119
        failed = 1 ;
11120
    end
11121
    else
11122
    begin
11123
        if (read_status`READ_DATA !== expected_value)
11124
        begin
11125
            test_fail("AM2 initial value was not set as defined");
11126
            failed = 1 ;
11127
        end
11128
    end
11129
 
11130
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11131
 
11132
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11133
 
11134
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11135
 
11136
    `ifdef PCI_IMAGE3
11137
        expected_value = {`PCI_AM3, 12'h000};
11138
 
11139
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11140
    `else
11141
        expected_value = 32'h0000_0000 ;
11142
    `endif
11143
 
11144
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11145
    begin
11146
        test_fail("read from P_AM3 register didn't succeede") ;
11147
        failed = 1 ;
11148
    end
11149
    else
11150
    begin
11151
        if (read_status`READ_DATA !== expected_value)
11152
        begin
11153
            test_fail("AM3 initial value was not set as defined");
11154
            failed = 1 ;
11155
        end
11156
    end
11157
 
11158
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11159
 
11160
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11161
 
11162
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11163
 
11164
    `ifdef PCI_IMAGE4
11165
        expected_value = {`PCI_AM4, 12'h000};
11166
 
11167
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11168
    `else
11169
        expected_value = 32'h0000_0000 ;
11170
    `endif
11171
 
11172
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11173
    begin
11174
        test_fail("read from P_AM4 register didn't succeede") ;
11175
        failed = 1 ;
11176
    end
11177
    else
11178
    begin
11179
        if (read_status`READ_DATA !== expected_value)
11180
        begin
11181
            test_fail("AM4 initial value was not set as defined");
11182
            failed = 1 ;
11183
        end
11184
    end
11185
 
11186
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11187
 
11188
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11189
 
11190
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11191
 
11192
    `ifdef PCI_IMAGE5
11193
        expected_value = {`PCI_AM5, 12'h000};
11194
 
11195
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11196
    `else
11197
        expected_value = 32'h0000_0000 ;
11198
    `endif
11199
 
11200
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11201
    begin
11202
        test_fail("read from P_AM5 register didn't succeede") ;
11203
        failed = 1 ;
11204
    end
11205
    else
11206
    begin
11207
        if (read_status`READ_DATA !== expected_value)
11208
        begin
11209
            test_fail("AM5 initial value was not set as defined");
11210
            failed = 1 ;
11211
        end
11212
    end
11213
 
11214
`endif
11215
 
11216
`ifdef GUEST
11217
    reg [31:0] read_data ;
11218
begin
11219
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11220
    failed    = 0 ;
11221
 
11222
    // check all images' BARs
11223
 
11224
    // BAR0
11225
    configuration_cycle_read
11226
    (
11227
        8'h00,                          // bus number [7:0]
11228
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11229
        3'h0,                           // function number [2:0]
11230
        6'h4,                           // register number [5:0]
11231
        2'h0,                           // type [1:0]
11232
        4'hF,                           // byte enables [3:0]
11233
        read_data                       // data returned from configuration read [31:0]
11234
    ) ;
11235
 
11236
    expected_value = 32'h0000_0000 ;
11237
 
11238
    if( read_data !== expected_value)
11239
    begin
11240
        test_fail("initial value of BAR0 register not as expected") ;
11241
        failed = 1 ;
11242
    end
11243
 
11244
    // BAR1
11245
    configuration_cycle_read
11246
    (
11247
        8'h00,                          // bus number [7:0]
11248
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11249
        3'h0,                           // function number [2:0]
11250
        6'h5,                           // register number [5:0]
11251
        2'h0,                           // type [1:0]
11252
        4'hF,                           // byte enables [3:0]
11253
        read_data                       // data returned from configuration read [31:0]
11254
    ) ;
11255
 
11256
    if (`PCI_AM1)
11257
        expected_value = `PCI_BA1_MEM_IO ;
11258
    else
11259
        expected_value = 32'h0000_0000 ;
11260
 
11261
    if( read_data !== expected_value)
11262
    begin
11263
        test_fail("initial value of BAR1 register not as expected") ;
11264
        failed = 1 ;
11265
    end
11266
 
11267
    // BAR2
11268
    configuration_cycle_read
11269
    (
11270
        8'h00,                          // bus number [7:0]
11271
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11272
        3'h0,                           // function number [2:0]
11273
        6'h6,                           // register number [5:0]
11274
        2'h0,                           // type [1:0]
11275
        4'hF,                           // byte enables [3:0]
11276
        read_data                       // data returned from configuration read [31:0]
11277
    ) ;
11278
 
11279
    `ifdef PCI_IMAGE2
11280
    if (`PCI_AM2)
11281
        expected_value = `PCI_BA2_MEM_IO ;
11282
    else
11283
        expected_value = 32'h0000_0000 ;
11284
    `else
11285
    expected_value = 32'h0 ;
11286
    `endif
11287
 
11288
    if( read_data !== expected_value)
11289
    begin
11290
        test_fail("initial value of BAR2 register not as expected") ;
11291
        failed = 1 ;
11292
    end
11293
 
11294
    // BAR3
11295
    configuration_cycle_read
11296
    (
11297
        8'h00,                          // bus number [7:0]
11298
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11299
        3'h0,                           // function number [2:0]
11300
        6'h7,                           // register number [5:0]
11301
        2'h0,                           // type [1:0]
11302
        4'hF,                           // byte enables [3:0]
11303
        read_data                       // data returned from configuration read [31:0]
11304
    ) ;
11305
 
11306
    `ifdef PCI_IMAGE3
11307
    if(`PCI_AM3)
11308
        expected_value = `PCI_BA3_MEM_IO ;
11309
    else
11310
        expected_value = 32'h0000_0000 ;
11311
    `else
11312
    expected_value = 32'h0 ;
11313
    `endif
11314
 
11315
    if( read_data !== expected_value)
11316
    begin
11317
        test_fail("initial value of BAR3 register not as expected") ;
11318
        failed = 1 ;
11319
    end
11320
 
11321
    // BAR4
11322
    configuration_cycle_read
11323
    (
11324
        8'h00,                          // bus number [7:0]
11325
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11326
        3'h0,                           // function number [2:0]
11327
        6'h8,                           // register number [5:0]
11328
        2'h0,                           // type [1:0]
11329
        4'hF,                           // byte enables [3:0]
11330
        read_data                       // data returned from configuration read [31:0]
11331
    ) ;
11332
 
11333
    `ifdef PCI_IMAGE4
11334
    if (`PCI_AM4)
11335
        expected_value = `PCI_BA4_MEM_IO ;
11336
    else
11337
        expected_value = 32'h0000_0000 ;
11338
    `else
11339
    expected_value = 32'h0 ;
11340
    `endif
11341
 
11342
    if( read_data !== expected_value)
11343
    begin
11344
        test_fail("initial value of BAR4 register not as expected") ;
11345
        failed = 1 ;
11346
    end
11347
 
11348
    // BAR5
11349
    configuration_cycle_read
11350
    (
11351
        8'h00,                          // bus number [7:0]
11352
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11353
        3'h0,                           // function number [2:0]
11354
        6'h9,                           // register number [5:0]
11355
        2'h0,                           // type [1:0]
11356
        4'hF,                           // byte enables [3:0]
11357
        read_data                       // data returned from configuration read [31:0]
11358
    ) ;
11359
 
11360
    `ifdef PCI_IMAGE5
11361
    if(`PCI_AM5)
11362
        expected_value = `PCI_BA5_MEM_IO ;
11363
    else
11364
        expected_value = 32'h0000_0000 ;
11365
    `else
11366
    expected_value = 32'h0 ;
11367
    `endif
11368
 
11369
    if( read_data !== expected_value)
11370
    begin
11371
        test_fail("initial value of BAR5 register not as expected") ;
11372
        failed = 1 ;
11373
    end
11374
 
11375
    // write all 1s to BAR0
11376
    read_data = 32'hFFFF_FFFF ;
11377
 
11378
    // BAR0
11379
    configuration_cycle_write
11380
    (
11381
        8'h00,                          // bus number [7:0]
11382
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11383
        3'h0,                           // function number [2:0]
11384
        6'h4,                           // register number [5:0]
11385
        2'h0,                           // type [1:0]
11386
        4'hF,                           // byte enables [3:0]
11387
        read_data                       // data to write [31:0]
11388
    ) ;
11389
 
11390
    expected_value = 32'hFFFF_FFFF ;
11391
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11392
 
11393
    configuration_cycle_read
11394
    (
11395
        8'h00,                          // bus number [7:0]
11396
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11397
        3'h0,                           // function number [2:0]
11398
        6'h4,                           // register number [5:0]
11399
        2'h0,                           // type [1:0]
11400
        4'hF,                           // byte enables [3:0]
11401
        read_data                       // data to write [31:0]
11402
    ) ;
11403
 
11404
    if ( read_data !== expected_value )
11405
    begin
11406
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11407
        failed = 1 ;
11408
    end
11409
 
11410
    // write all 1s to BAR1
11411
    read_data = 32'hFFFF_FFFF ;
11412
 
11413
    // BAR1
11414
    configuration_cycle_write
11415
    (
11416
        8'h00,                          // bus number [7:0]
11417
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11418
        3'h0,                           // function number [2:0]
11419
        6'h5,                           // register number [5:0]
11420
        2'h0,                           // type [1:0]
11421
        4'hF,                           // byte enables [3:0]
11422
        read_data                       // data to write [31:0]
11423
    ) ;
11424
 
11425
    expected_value = {`PCI_AM1, 12'h000} ;
11426
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11427
    if (`PCI_AM1)
11428
        expected_value[0] = `PCI_BA1_MEM_IO ;
11429
 
11430
    configuration_cycle_read
11431
    (
11432
        8'h00,                          // bus number [7:0]
11433
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11434
        3'h0,                           // function number [2:0]
11435
        6'h5,                           // register number [5:0]
11436
        2'h0,                           // type [1:0]
11437
        4'hF,                           // byte enables [3:0]
11438
        read_data                       // data to write [31:0]
11439
    ) ;
11440
 
11441
    if ( read_data !== expected_value )
11442
    begin
11443
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11444
        failed = 1 ;
11445
    end
11446
 
11447
    // write all 1s to BAR2
11448
    read_data = 32'hFFFF_FFFF ;
11449
 
11450
    // BAR2
11451
    configuration_cycle_write
11452
    (
11453
        8'h00,                          // bus number [7:0]
11454
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11455
        3'h0,                           // function number [2:0]
11456
        6'h6,                           // register number [5:0]
11457
        2'h0,                           // type [1:0]
11458
        4'hF,                           // byte enables [3:0]
11459
        read_data                       // data to write [31:0]
11460
    ) ;
11461
 
11462
`ifdef PCI_IMAGE2
11463
    expected_value = {`PCI_AM2, 12'h000} ;
11464
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11465
    if (`PCI_AM2)
11466
        expected_value[0] = `PCI_BA2_MEM_IO ;
11467
`else
11468
    expected_value = 0 ;
11469
`endif
11470
 
11471
    configuration_cycle_read
11472
    (
11473
        8'h00,                          // bus number [7:0]
11474
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11475
        3'h0,                           // function number [2:0]
11476
        6'h6,                           // register number [5:0]
11477
        2'h0,                           // type [1:0]
11478
        4'hF,                           // byte enables [3:0]
11479
        read_data                       // data to write [31:0]
11480
    ) ;
11481
 
11482
    if ( read_data !== expected_value )
11483
    begin
11484
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11485
        failed = 1 ;
11486
    end
11487
 
11488
    // write all 1s to BAR3
11489
    read_data = 32'hFFFF_FFFF ;
11490
 
11491
    // BAR3
11492
    configuration_cycle_write
11493
    (
11494
        8'h00,                          // bus number [7:0]
11495
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11496
        3'h0,                           // function number [2:0]
11497
        6'h7,                           // register number [5:0]
11498
        2'h0,                           // type [1:0]
11499
        4'hF,                           // byte enables [3:0]
11500
        read_data                       // data to write [31:0]
11501
    ) ;
11502
 
11503
`ifdef PCI_IMAGE3
11504
    expected_value = {`PCI_AM3, 12'h000} ;
11505
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11506
    if(`PCI_AM3)
11507
        expected_value[0] = `PCI_BA3_MEM_IO ;
11508
`else
11509
    expected_value = 0 ;
11510
`endif
11511
 
11512
    configuration_cycle_read
11513
    (
11514
        8'h00,                          // bus number [7:0]
11515
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11516
        3'h0,                           // function number [2:0]
11517
        6'h7,                           // register number [5:0]
11518
        2'h0,                           // type [1:0]
11519
        4'hF,                           // byte enables [3:0]
11520
        read_data                       // data to write [31:0]
11521
    ) ;
11522
 
11523
    if ( read_data !== expected_value )
11524
    begin
11525
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11526
        failed = 1 ;
11527
    end
11528
 
11529
    // write all 1s to BAR4
11530
    read_data = 32'hFFFF_FFFF ;
11531
 
11532
    // BAR4
11533
    configuration_cycle_write
11534
    (
11535
        8'h00,                          // bus number [7:0]
11536
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11537
        3'h0,                           // function number [2:0]
11538
        6'h8,                           // register number [5:0]
11539
        2'h0,                           // type [1:0]
11540
        4'hF,                           // byte enables [3:0]
11541
        read_data                       // data to write [31:0]
11542
    ) ;
11543
 
11544
`ifdef PCI_IMAGE4
11545
    expected_value = {`PCI_AM4, 12'h000} ;
11546
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11547
    if(`PCI_AM4)
11548
        expected_value[0] = `PCI_BA4_MEM_IO ;
11549
`else
11550
    expected_value = 0 ;
11551
`endif
11552
 
11553
    configuration_cycle_read
11554
    (
11555
        8'h00,                          // bus number [7:0]
11556
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11557
        3'h0,                           // function number [2:0]
11558
        6'h8,                           // register number [5:0]
11559
        2'h0,                           // type [1:0]
11560
        4'hF,                           // byte enables [3:0]
11561
        read_data                       // data to write [31:0]
11562
    ) ;
11563
 
11564
    if ( read_data !== expected_value )
11565
    begin
11566
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11567
        failed = 1 ;
11568
    end
11569
 
11570
    // write all 1s to BAR5
11571
    read_data = 32'hFFFF_FFFF ;
11572
 
11573
    // BAR5
11574
    configuration_cycle_write
11575
    (
11576
        8'h00,                          // bus number [7:0]
11577
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11578
        3'h0,                           // function number [2:0]
11579
        6'h9,                           // register number [5:0]
11580
        2'h0,                           // type [1:0]
11581
        4'hF,                           // byte enables [3:0]
11582
        read_data                       // data to write [31:0]
11583
    ) ;
11584
 
11585
`ifdef PCI_IMAGE5
11586
    expected_value = {`PCI_AM5, 12'h000} ;
11587
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11588
    if(`PCI_AM5)
11589
        expected_value[0] = `PCI_BA5_MEM_IO ;
11590
`else
11591
    expected_value = 0 ;
11592
`endif
11593
 
11594
    configuration_cycle_read
11595
    (
11596
        8'h00,                          // bus number [7:0]
11597
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11598
        3'h0,                           // function number [2:0]
11599
        6'h9,                           // register number [5:0]
11600
        2'h0,                           // type [1:0]
11601
        4'hF,                           // byte enables [3:0]
11602
        read_data                       // data to write [31:0]
11603
    ) ;
11604
 
11605
    if ( read_data !== expected_value )
11606
    begin
11607
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11608
        failed = 1 ;
11609
    end
11610
`endif
11611
 
11612
    if (!failed)
11613
        test_ok ;
11614
end
11615
endtask
11616
 
11617 15 mihad
task display_warning;
11618
    input [31:0] error_address ;
11619
    input [31:0] expected_data ;
11620
    input [31:0] actual ;
11621
begin
11622
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11623
end
11624
endtask // display warning
11625
 
11626
/*############################################################################
11627
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11628
=====================
11629
############################################################################*/
11630
 
11631
// Task reslease the PCI bus for 'delay' clocks
11632
task do_pause;
11633
  input  [15:0] delay;
11634
  reg    [15:0] cnt;
11635
  begin
11636
    test_start <= 1'b0;  // no device is allowed to take this
11637
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11638
    begin
11639
      if (~pci_reset_comb)
11640
      begin
11641
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11642
      end
11643
      `NO_ELSE;
11644
    end
11645
  end
11646
endtask // do_pause
11647
 
11648
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11649
task DO_REF;
11650
  input  [79:0] name;
11651
  input  [2:0] master_number;
11652
  input  [PCI_BUS_DATA_RANGE:0] address;
11653
  input  [3:0] command;
11654
  input  [PCI_BUS_DATA_RANGE:0] data;
11655
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11656
  input  [9:0] size;
11657
  input   make_addr_par_error, make_data_par_error;
11658
  input  [7:0] master_wait_states;
11659
  input  [7:0] target_wait_states;
11660
  input  [1:0] target_devsel_speed;
11661
  input   fast_back_to_back;
11662
  input  [2:0] target_termination;
11663
  input   expect_master_abort;
11664
  reg     waiting;
11665
  begin
11666
// Cautiously wait for previous command to be done
11667
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11668
    begin
11669
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11670
      begin
11671
        if (~pci_reset_comb)
11672
        begin
11673
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11674
        end
11675
        `NO_ELSE;
11676
      end
11677
      else
11678
      begin
11679
        waiting = 1'b0;  // ready to do next command
11680
      end
11681
    end
11682
    next_test_name[79:0] <= name[79:0];
11683
    test_master_number <= master_number[2:0];
11684
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11685
    test_command[3:0] <= command[3:0] ;
11686
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11687
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11688
    test_size <= size;
11689
    test_make_addr_par_error <= make_addr_par_error;
11690
    test_make_data_par_error <= make_data_par_error;
11691
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11692
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11693
    test_target_initial_wait_states <= target_wait_states[7:4];
11694
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11695
    test_target_devsel_speed <= target_devsel_speed[1:0];
11696
    test_fast_back_to_back <= fast_back_to_back;
11697
    test_target_termination <= target_termination[2:0];
11698
    test_expect_master_abort <= expect_master_abort;
11699
    test_start <= 1'b1;
11700
    if (~pci_reset_comb)
11701
    begin
11702
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11703
    end
11704
    `NO_ELSE;
11705
// wait for new command to start
11706
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11707
    begin
11708
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11709
      begin
11710
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11711
      end
11712
      else
11713
      begin
11714
        waiting = 1'b0;  // ready to do next command
11715
      end
11716
    end
11717
  end
11718
endtask // DO_REF
11719
 
11720
// Use Macros defined in pci_defines.vh as paramaters
11721
 
11722
// DO_REF (name[79:0], master_number[2:0],
11723
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11724
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11725
//          make_addr_par_error, make_data_par_error,
11726
//          master_wait_states[8:0], target_wait_states[8:0],
11727
//          target_devsel_speed[1:0], fast_back_to_back,
11728
//          target_termination[2:0],
11729
//          expect_master_abort);
11730
//
11731
// Example:
11732
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11733
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11734
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11735
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11736
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11737
 
11738
// Access a location with no high-order bits set, assuring that no device responds
11739
task PCIU_CONFIG_READ_MASTER_ABORT;
11740
  input  [79:0] name;
11741
  input  [2:0] master_number;
11742 51 mihad
  input  [31:0] address ;
11743
  input  [3:0] be ;
11744 15 mihad
  begin
11745 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11746
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11747
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11748 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11749
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11750
  end
11751
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11752
 
11753
// Access a location with no high-order bits set, assuring that no device responds
11754
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11755
  input  [79:0] name;
11756
  input  [2:0] master_number;
11757 51 mihad
  input  [31:0] address ;
11758
  input  [3:0] be ;
11759 15 mihad
  begin
11760 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11761
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11762
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11763 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11764
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11765
  end
11766
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11767
 
11768
// Access a location with no high-order bits set, assuring that no device responds
11769
task PCIU_MEM_READ_MASTER_ABORT;
11770
  input  [79:0] name;
11771
  input  [2:0] master_number;
11772
  input  [9:0] size;
11773
  begin
11774
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11775
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11776
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11777
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11778
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11779
  end
11780
endtask // PCIU_MEM_READ_MASTER_ABORT
11781
 
11782
// Access a location with no high-order bits set, assuring that no device responds
11783
task PCIU_MEM_WRITE_MASTER_ABORT;
11784
  input  [79:0] name;
11785
  input  [2:0] master_number;
11786
  input  [9:0] size;
11787
  begin
11788
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11789
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11790
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11791
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11792
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11793
  end
11794
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11795
 
11796
// Do variable length transfers with various paramaters
11797
task PCIU_CONFIG_READ;
11798
  input  [79:0] name;
11799
  input  [2:0] master_number;
11800
  input  [PCI_BUS_DATA_RANGE:0] address;
11801
  input  [PCI_BUS_DATA_RANGE:0] data;
11802
  input  [3:0] be ;
11803
  input  [9:0] size;
11804
  input  [7:0] master_wait_states;
11805
  input  [7:0] target_wait_states;
11806
  input  [1:0] target_devsel_speed;
11807
  input  [2:0] target_termination;
11808
  begin
11809
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11810
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11811
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11812
              8'h0_0, target_wait_states[7:0],
11813
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11814
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11815
  end
11816
endtask // PCIU_CONFIG_READ
11817
 
11818
task PCIU_CONFIG_WRITE;
11819
  input  [79:0] name;
11820
  input  [2:0] master_number;
11821
  input  [PCI_BUS_DATA_RANGE:0] address;
11822
  input  [PCI_BUS_DATA_RANGE:0] data;
11823
  input  [3:0] be ;
11824
  input  [9:0] size;
11825
  input  [7:0] master_wait_states;
11826
  input  [7:0] target_wait_states;
11827
  input  [1:0] target_devsel_speed;
11828
  input  [2:0] target_termination;
11829
  begin
11830
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11831
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11832
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11833
              8'h0_0, target_wait_states[7:0],
11834
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11835
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11836
  end
11837
endtask // PCIU_CONFIG_WRITE
11838
 
11839
task PCIU_READ;
11840
  input  [2:0] master_number;
11841
  input  [PCI_BUS_DATA_RANGE:0] address;
11842
  input  [3:0] command;
11843
  input  [PCI_BUS_DATA_RANGE:0] data;
11844
  input  [3:0] byte_en;
11845
  input  [9:0] size;
11846
  input  [7:0] master_wait_states;
11847
  input  [7:0] target_wait_states;
11848
  input  [1:0] target_devsel_speed;
11849
  input  [2:0] target_termination;
11850
  reg    [79:0] name;
11851
  begin
11852
    if (command == `BC_MEM_READ)
11853
        name = "MEM_READ  " ;
11854
    else if (command == `BC_MEM_READ_LN)
11855
        name = "MEM_RD_LN " ;
11856
    else if (command == `BC_MEM_READ_MUL )
11857
        name = "MEM_RD_MUL" ;
11858
    else
11859
        name = "WRONG_READ" ;
11860
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11861
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11862
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11863
              8'h0_0, target_wait_states[7:0],
11864
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11865
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11866
  end
11867
endtask // PCIU_READ
11868
 
11869
task PCIU_MEM_READ;
11870
  input  [79:0] name;
11871
  input  [2:0] master_number;
11872
  input  [PCI_BUS_DATA_RANGE:0] address;
11873
  input  [PCI_BUS_DATA_RANGE:0] data;
11874
  input  [9:0] size;
11875
  input  [7:0] master_wait_states;
11876
  input  [7:0] target_wait_states;
11877
  input  [1:0] target_devsel_speed;
11878
  input  [2:0] target_termination;
11879
  begin
11880
 
11881
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11882
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11883
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11884
              8'h0_0, target_wait_states[7:0],
11885
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11886
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11887
  end
11888
endtask // PCIU_MEM_READ
11889
 
11890
task PCIU_IO_READ;
11891
  input  [2:0] master_number;
11892
  input  [PCI_BUS_DATA_RANGE:0] address;
11893
  input  [PCI_BUS_DATA_RANGE:0] data;
11894
  input  [3:0] byte_en ;
11895
  input  [9:0] size;
11896
  input  [2:0] target_termination ;
11897
  begin
11898
 
11899
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11900
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11901
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11902
              8'h0_0, `Test_One_Zero_Target_WS,
11903
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11904
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11905
  end
11906
endtask // PCIU_IO_READ
11907
 
11908
task PCIU_IO_READ_MAKE_PERR;
11909
  input  [2:0] master_number;
11910
  input  [PCI_BUS_DATA_RANGE:0] address;
11911
  input  [PCI_BUS_DATA_RANGE:0] data;
11912
  input  [3:0] byte_en ;
11913
  input  [9:0] size;
11914
  input  [2:0] target_termination ;
11915
  begin
11916
 
11917
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11918
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11919
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11920
              8'h0_0, `Test_One_Zero_Target_WS,
11921
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11922
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11923
  end
11924
endtask // PCIU_IO_READ_MAKE_PERR
11925
 
11926
task PCIU_MEM_READ_LN;
11927
  input  [79:0] name;
11928
  input  [2:0] master_number;
11929
  input  [PCI_BUS_DATA_RANGE:0] address;
11930
  input  [PCI_BUS_DATA_RANGE:0] data;
11931
  input  [9:0] size;
11932
  input  [7:0] master_wait_states;
11933
  input  [7:0] target_wait_states;
11934
  input  [1:0] target_devsel_speed;
11935
  input  [2:0] target_termination;
11936
  begin
11937
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11938
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11939
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11940
              8'h0_0, target_wait_states[7:0],
11941
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11942
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11943
  end
11944
endtask // PCIU_MEM_READ_LN
11945
 
11946
task PCIU_MEM_READ_MUL;
11947
  input  [79:0] name;
11948
  input  [2:0] master_number;
11949
  input  [PCI_BUS_DATA_RANGE:0] address;
11950
  input  [PCI_BUS_DATA_RANGE:0] data;
11951
  input  [9:0] size;
11952
  input  [7:0] master_wait_states;
11953
  input  [7:0] target_wait_states;
11954
  input  [1:0] target_devsel_speed;
11955
  input  [2:0] target_termination;
11956
  begin
11957
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11958
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11959
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11960
              8'h0_0, target_wait_states[7:0],
11961
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11962
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11963
  end
11964
endtask // PCIU_MEM_READ_MUL
11965
 
11966
task PCIU_MEM_READ_MAKE_PERR;
11967
  input  [79:0] name;
11968
  input  [2:0] master_number;
11969
  input  [PCI_BUS_DATA_RANGE:0] address;
11970
  input  [PCI_BUS_DATA_RANGE:0] data;
11971
  input  [9:0] size;
11972
  input  [7:0] master_wait_states;
11973
  input  [7:0] target_wait_states;
11974
  input  [1:0] target_devsel_speed;
11975
  input  [2:0] target_termination;
11976
  begin
11977
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11978
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11979
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11980
              8'h0_0, target_wait_states[7:0],
11981
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11982
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11983
  end
11984
endtask // PCIU_MEM_READ_MAKE_PERR
11985
 
11986
task PCIU_MEM_WRITE;
11987
  input  [79:0] name;
11988
  input  [2:0] master_number;
11989
  input  [PCI_BUS_DATA_RANGE:0] address;
11990
  input  [PCI_BUS_DATA_RANGE:0] data;
11991
  input  [3:0] byte_en;
11992
  input  [9:0] size;
11993
  input  [7:0] master_wait_states;
11994
  input  [7:0] target_wait_states;
11995
  input  [1:0] target_devsel_speed;
11996
  input  [2:0] target_termination;
11997
  begin
11998
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11999
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12000
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12001
              8'h0_0, target_wait_states[7:0],
12002
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12003
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12004
  end
12005
endtask // PCIU_MEM_WRITE
12006
 
12007
task PCIU_IO_WRITE;
12008
  input  [2:0] master_number;
12009
  input  [PCI_BUS_DATA_RANGE:0] address;
12010
  input  [PCI_BUS_DATA_RANGE:0] data;
12011
  input  [3:0] byte_en;
12012
  input  [9:0] size;
12013
  input  [2:0] target_termination ;
12014
  begin
12015
 
12016
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12017
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12018
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12019
              8'h0_0, `Test_One_Zero_Target_WS,
12020
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12021
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12022
  end
12023
endtask // PCIU_IO_WRITE
12024
 
12025
task PCIU_IO_WRITE_MAKE_PERR ;
12026
  input  [2:0] master_number;
12027
  input  [PCI_BUS_DATA_RANGE:0] address;
12028
  input  [PCI_BUS_DATA_RANGE:0] data;
12029
  input  [3:0] byte_en;
12030
  input  [9:0] size;
12031
  input  [2:0] target_termination ;
12032
  begin
12033
 
12034
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12035
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12036
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12037
              8'h0_0, `Test_One_Zero_Target_WS,
12038
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12039
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12040
  end
12041
endtask // PCIU_IO_WRITE
12042
 
12043
task PCIU_MEM_WRITE_MAKE_SERR;
12044
  input  [79:0] name;
12045
  input  [2:0] master_number;
12046
  input  [PCI_BUS_DATA_RANGE:0] address;
12047
  input  [PCI_BUS_DATA_RANGE:0] data;
12048
  input  [9:0] size;
12049
  input  [7:0] master_wait_states;
12050
  input  [7:0] target_wait_states;
12051
  input  [1:0] target_devsel_speed;
12052
  input  [2:0] target_termination;
12053
  begin
12054
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12055
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12056
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12057
              8'h0_0, target_wait_states[7:0],
12058
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12059
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12060
  end
12061
endtask // PCIU_MEM_WRITE_MAKE_SERR
12062
 
12063
task PCIU_MEM_WRITE_MAKE_PERR;
12064
  input  [79:0] name;
12065
  input  [2:0] master_number;
12066
  input  [PCI_BUS_DATA_RANGE:0] address;
12067
  input  [PCI_BUS_DATA_RANGE:0] data;
12068
  input  [9:0] size;
12069
  input  [7:0] master_wait_states;
12070
  input  [7:0] target_wait_states;
12071
  input  [1:0] target_devsel_speed;
12072
  input  [2:0] target_termination;
12073
  begin
12074
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12075
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12076
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12077
              8'h0_0, target_wait_states[7:0],
12078
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12079
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12080
  end
12081
endtask // PCIU_MEM_WRITE
12082
 
12083
/*--------------------------------------------------------------------------
12084
Initialization CASES
12085
--------------------------------------------------------------------------*/
12086
 
12087
// Initialize the basic Config Registers of the PCI bridge target device
12088
task configure_bridge_target;
12089
    reg [11:0] offset ;
12090
    reg [31:0] data ;
12091
    `ifdef HOST
12092
    reg `WRITE_STIM_TYPE   write_data ;
12093
    reg `WB_TRANSFER_FLAGS write_flags ;
12094
    reg `WRITE_RETURN_TYPE write_status ;
12095
    `else
12096
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12097
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12098
    `endif
12099
 
12100
    reg [31:0] temp_var ;
12101
begin
12102
`ifdef HOST //  set Header
12103
    offset  = 12'h4 ; // PCI Header Command register
12104
    data    = 32'h0000_0007 ; // enable master & target operation
12105
 
12106
    write_flags                      = 0 ;
12107
    write_flags`INIT_WAITS           = tb_init_waits ;
12108
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12109
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12110
 
12111
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12112
    write_data`WRITE_SEL      = 4'h1 ;
12113
    write_data`WRITE_TAG_STIM = 0 ;
12114
    write_data`WRITE_DATA     = data ;
12115
 
12116
    next_test_name[79:0] <= "Init_Tar_R";
12117
 
12118
    $display(" bridge target - Enabling master and target operation!");
12119
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12120
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12121
    begin
12122
        $display("Write to configuration space failed! Time %t ", $time) ;
12123
    end
12124
 
12125
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12126
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12127
 
12128
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12129
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12130
 
12131
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12132
    write_data`WRITE_SEL      = 4'hf ;
12133
    write_data`WRITE_TAG_STIM = 0 ;
12134
    write_data`WRITE_DATA     = data ;
12135
 
12136
 `ifdef  NO_CNF_IMAGE
12137
  `ifdef PCI_IMAGE0 //      set P_BA0
12138
 
12139
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12140
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12141
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12142
    begin
12143
        $display("Write to configuration space failed! Time %t ", $time) ;
12144
    end
12145
  `endif
12146
 `else //      set P_BA0
12147
 
12148
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12149
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12150
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12151
    begin
12152
        $display("Write to configuration space failed! Time %t ", $time) ;
12153
    end
12154
 `endif
12155
 
12156
`else // GUEST, set Header, set P_BA0
12157
    data            = 32'h0000_0007 ; // enable master & target operation
12158
    byte_enables    = 4'hF ;
12159
    $display(" bridge target - Enabling master and target operation!");
12160 45 mihad
    configuration_cycle_write(0,                        // bus number
12161
                              `TAR0_IDSEL_INDEX - 11,   // device number
12162
                              0,                        // function number
12163
                              1,                        // register number
12164
                              0,                        // type of configuration cycle
12165
                              byte_enables,             // byte enables
12166
                              data                      // data
12167 15 mihad
                             ) ;
12168
 
12169
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12170
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12171
    byte_enables = 4'hf ;
12172 45 mihad
    configuration_cycle_write(0,                        // bus number
12173
                              `TAR0_IDSEL_INDEX - 11,   // device number
12174
                              0,                        // function number
12175
                              4,                        // register number
12176
                              0,                        // type of configuration cycle
12177
                              byte_enables,             // byte enables
12178
                              data                      // data
12179 15 mihad
                             ) ;
12180
 
12181
`endif
12182
end
12183
endtask // configure_bridge_target
12184
 
12185
// Initialize the basic Config Registers of the PCI bridge target device
12186
task configure_bridge_target_base_addresses;
12187
    reg [11:0] offset ;
12188
    reg [31:0] data ;
12189
    `ifdef HOST
12190
    reg `WRITE_STIM_TYPE   write_data ;
12191
    reg `WB_TRANSFER_FLAGS write_flags ;
12192
    reg `WRITE_RETURN_TYPE write_status ;
12193
    `else
12194
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12195
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12196
    `endif
12197
 
12198
    reg [31:0] temp_var ;
12199
begin
12200
`ifdef HOST //  set Header
12201
    offset  = 12'h4 ; // PCI Header Command register
12202
    data    = 32'h0000_0007 ; // enable master & target operation
12203
 
12204
    write_flags                    = 0 ;
12205
    write_flags`INIT_WAITS         = tb_init_waits ;
12206
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12207
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12208
 
12209
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12210
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12211
 
12212
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12213
    write_data`WRITE_SEL      = 4'h1 ;
12214
    write_data`WRITE_TAG_STIM = 0 ;
12215
    write_data`WRITE_DATA     = data ;
12216
 
12217
    next_test_name[79:0] <= "Init_Tar_R";
12218
 
12219
    $display(" bridge target - Enabling master and target operation!");
12220
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12221
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12222
    begin
12223
        $display("Write to configuration space failed! Time %t ", $time) ;
12224
    end
12225
 
12226
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12227
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12228
 
12229
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12230
    write_data`WRITE_SEL      = 4'hf ;
12231
    write_data`WRITE_TAG_STIM = 0 ;
12232
    write_data`WRITE_DATA     = data ;
12233
 
12234
 `ifdef  NO_CNF_IMAGE
12235
  `ifdef PCI_IMAGE0 //      set P_BA0
12236
 
12237
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12238
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12239
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12240
    begin
12241
        $display("Write to configuration space failed! Time %t ", $time) ;
12242
    end
12243
  `endif
12244
 `else //      set P_BA0
12245
 
12246
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12247
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12248
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12249
    begin
12250
        $display("Write to configuration space failed! Time %t ", $time) ;
12251
    end
12252
 `endif
12253
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12254
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12255
 
12256
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12257
    write_data`WRITE_SEL      = 4'hf ;
12258
    write_data`WRITE_TAG_STIM = 0 ;
12259
    write_data`WRITE_DATA     = data ;
12260
 
12261
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12262
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12263
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12264
    begin
12265
        $display("Write to configuration space failed! Time %t ", $time) ;
12266
    end
12267
 `ifdef PCI_IMAGE2
12268
 
12269
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12270
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12271
 
12272
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12273
    write_data`WRITE_SEL      = 4'hf ;
12274
    write_data`WRITE_TAG_STIM = 0 ;
12275
    write_data`WRITE_DATA     = data ;
12276
 
12277
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12278
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12279
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12280
    begin
12281
        $display("Write to configuration space failed! Time %t ", $time) ;
12282
    end
12283
 `endif
12284
 `ifdef PCI_IMAGE3
12285
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12286
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12287
 
12288
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12289
    write_data`WRITE_SEL      = 4'hf ;
12290
    write_data`WRITE_TAG_STIM = 0 ;
12291
    write_data`WRITE_DATA     = data ;
12292
 
12293
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12294
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12295
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12296
    begin
12297
        $display("Write to configuration space failed! Time %t ", $time) ;
12298
    end
12299
 `endif
12300
 `ifdef PCI_IMAGE4
12301
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12302
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12303
 
12304
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12305
    write_data`WRITE_SEL      = 4'hf ;
12306
    write_data`WRITE_TAG_STIM = 0 ;
12307
    write_data`WRITE_DATA     = data ;
12308
 
12309
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12310
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12311
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12312
    begin
12313
        $display("Write to configuration space failed! Time %t ", $time) ;
12314
    end
12315
 `endif
12316
 `ifdef PCI_IMAGE5
12317
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12318
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12319
 
12320
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12321
    write_data`WRITE_SEL      = 4'hf ;
12322
    write_data`WRITE_TAG_STIM = 0 ;
12323
    write_data`WRITE_DATA     = data ;
12324
 
12325
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12326
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12327
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12328
    begin
12329
        $display("Write to configuration space failed! Time %t ", $time) ;
12330
    end
12331
 `endif
12332
 
12333
`else // GUEST, set Header, set P_BA0
12334
    data            = 32'h0000_0007 ; // enable master & target operation
12335
    byte_enables    = 4'hF ;
12336
    $display(" bridge target - Enabling master and target operation!");
12337 45 mihad
    configuration_cycle_write(0,                        // bus number
12338
                              `TAR0_IDSEL_INDEX - 11,   // device number
12339
                              0,                        // function number
12340
                              1,                        // register number
12341
                              0,                        // type of configuration cycle
12342
                              byte_enables,             // byte enables
12343
                              data                      // data
12344 15 mihad
                             ) ;
12345
 
12346
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12347
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12348
    byte_enables = 4'hf ;
12349 45 mihad
    configuration_cycle_write(0,                        // bus number
12350
                              `TAR0_IDSEL_INDEX - 11,   // device number
12351
                              0,                        // function number
12352
                              4,                        // register number
12353
                              0,                        // type of configuration cycle
12354
                              byte_enables,             // byte enables
12355
                              data                      // data
12356 15 mihad
                             ) ;
12357
 
12358
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12359
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12360
    byte_enables = 4'hf ;
12361 45 mihad
    configuration_cycle_write(0,                        // bus number
12362
                              `TAR0_IDSEL_INDEX - 11,   // device number
12363
                              0,                        // function number
12364
                              5,                        // register number
12365
                              0,                        // type of configuration cycle
12366
                              byte_enables,             // byte enables
12367
                              data                      // data
12368 15 mihad
                             ) ;
12369
 `ifdef PCI_IMAGE2
12370
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12371
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12372
    byte_enables = 4'hf ;
12373 45 mihad
    configuration_cycle_write(0,                        // bus number
12374
                              `TAR0_IDSEL_INDEX - 11,   // device number
12375
                              0,                        // function number
12376
                              6,                        // register number
12377
                              0,                        // type of configuration cycle
12378
                              byte_enables,             // byte enables
12379
                              data                      // data
12380 15 mihad
                             ) ;
12381
 `endif
12382
 `ifdef PCI_IMAGE3
12383
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12384
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12385
    byte_enables = 4'hf ;
12386 45 mihad
    configuration_cycle_write(0,                        // bus number
12387
                              `TAR0_IDSEL_INDEX - 11,   // device number
12388
                              0,                        // function number
12389
                              7,                        // register number
12390
                              0,                        // type of configuration cycle
12391
                              byte_enables,             // byte enables
12392
                              data                      // data
12393 15 mihad
                             ) ;
12394
 `endif
12395
 `ifdef PCI_IMAGE4
12396
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12397
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12398
    byte_enables = 4'hf ;
12399 45 mihad
    configuration_cycle_write(0,                        // bus number
12400
                              `TAR0_IDSEL_INDEX - 11,   // device number
12401
                              0,                        // function number
12402
                              8,                        // register number
12403
                              0,                        // type of configuration cycle
12404
                              byte_enables,             // byte enables
12405
                              data                      // data
12406 15 mihad
                             ) ;
12407
 `endif
12408
 `ifdef PCI_IMAGE5
12409
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12410
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12411
    byte_enables = 4'hf ;
12412 45 mihad
    configuration_cycle_write(0,                        // bus number
12413
                              `TAR0_IDSEL_INDEX - 11,   // device number
12414
                              0,                        // function number
12415
                              9,                        // register number
12416
                              0,                        // type of configuration cycle
12417
                              byte_enables,             // byte enables
12418
                              data                      // data
12419 15 mihad
                             ) ;
12420
 `endif
12421
`endif
12422
end
12423
endtask // configure_bridge_target_base_addresses
12424
 
12425
/*--------------------------------------------------------------------------
12426
Test CASES
12427
--------------------------------------------------------------------------*/
12428
 
12429
// function converts PCI address to WB with the same data as the pci_decoder does
12430
function [31:0] pci_to_wb_addr_convert ;
12431
 
12432
    input [31:0] pci_address ;
12433
    input [31:0] translation_address ;
12434
    input [31:0] translate ;
12435
 
12436
    reg   [31:0] temp_address ;
12437
begin
12438
    if ( translate !== 1 )
12439
    begin
12440
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12441
    end
12442
    else
12443
    begin
12444
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12445
    end
12446
 
12447
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12448
    pci_to_wb_addr_convert = temp_address ;
12449
end
12450
endfunction // pci_to_wb_addr_convert
12451
 
12452
// Test normal write and read to WB slave
12453
task test_normal_wr_rd;
12454
  input  [2:0]  Master_ID;
12455
  input  [PCI_BUS_DATA_RANGE:0] Address;
12456
  input  [PCI_BUS_DATA_RANGE:0] Data;
12457
  input  [3:0]  Be;
12458
  input  [2:0]  Image_num;
12459
  input  [9:0]  Set_size;
12460
  input         Set_addr_translation;
12461
  input         Set_prefetch_enable;
12462
  input  [7:0]  Cache_lsize;
12463
  input         Set_wb_wait_states;
12464
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12465
 
12466
  reg    [31:0] rd_address;
12467
  reg    [31:0] rd_data;
12468
  reg    [3:0]  rd_be;
12469
  reg    [11:0] addr_offset;
12470
  reg    [31:0] read_data;
12471
  reg           continue ;
12472
  reg           ok   ;
12473
  reg    [31:0] expect_address ;
12474
  reg    [31:0] expect_rd_address ;
12475
  reg           expect_we ;
12476
  reg    [9:0]  expect_length_wr ;
12477
  reg    [9:0]  expect_length_rd ;
12478
  reg    [9:0]  expect_length_rd1 ;
12479
  reg    [9:0]  expect_length_rd2 ;
12480
  reg    [3:0]  use_rd_cmd ;
12481
  integer       i ;
12482 35 mihad
  reg           error_monitor_done ;
12483 15 mihad
begin:main
12484
 
12485
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12486
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12487
    $display(" - errors will be reported, but they should not occur!");
12488
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12489
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12490
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12491
    if ( ok !== 1 )
12492
    begin
12493
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12494
        test_fail("write to P_ERR_CS register didn't succeede") ;
12495
        disable main;
12496
    end
12497
 
12498
    `ifdef  ADDR_TRAN_IMPL
12499
 
12500
    // set or clear address translation
12501
    if (Set_addr_translation)
12502
    begin
12503
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12504
        $display(" - address translation will be performed!");
12505
    end
12506
    else
12507
    begin
12508
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12509
        $display(" - address translation will not be performed!");
12510
    end
12511
    // set or clear pre-fetch enable
12512
    if (Set_prefetch_enable)
12513
    begin
12514
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12515
        $display(" - bursts can be performed!");
12516
    end
12517
    else
12518
    begin
12519
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12520
        $display(" - bursts can not be performed!");
12521
    end
12522
 
12523
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12524
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12525
    if ( ok !== 1 )
12526
    begin
12527
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12528
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12529
        disable main;
12530
    end
12531
 
12532
    // predict the address and control signals on WB bus
12533
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12534
    expect_we      = 1'b1 ; // WRITE
12535
 
12536
    `else
12537
 
12538
    // address translation is not implemented
12539
    $display("Address translation is NOT implemented for PCI images!");
12540
    // set or clear pre-fetch enable
12541
    if (Set_prefetch_enable)
12542
    begin
12543
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12544
        $display(" - bursts can be performed!");
12545
    end
12546
    else
12547
    begin
12548
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12549
        $display(" - bursts can not be performed!");
12550
    end
12551
 
12552
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12553
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12554
    if ( ok !== 1 )
12555
    begin
12556
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12557
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12558
        disable main;
12559
    end
12560
 
12561
    // predict the address and control signals on WB bus
12562
    expect_address = Address ;
12563
    expect_we      = 1'b1 ; // WRITE
12564
 
12565
    `endif
12566
 
12567
    // set WB SLAVE parameters
12568
    if (Set_wb_wait_states)
12569
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12570
    else
12571
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12572
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12573
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12574
 
12575
    if ( Set_size > (`PCIW_DEPTH - 2) )
12576
    begin
12577
        expect_length_wr = `PCIW_DEPTH - 2 ;
12578
    end
12579
    else
12580
    begin
12581
        expect_length_wr = Set_size ;
12582
    end
12583
    // write through the PCI bridge to WB slave
12584
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12585
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12586
 
12587
    fork
12588
    begin
12589
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12590
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12591
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12592
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12593
        do_pause( 1 ) ;
12594
    end
12595
    begin
12596
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12597
       if ( ok !== 1 )
12598
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12599
       else
12600
           test_ok ;
12601
    end
12602
    join
12603
 
12604
    // predict the address and control signals on WB bus
12605
    expect_we      = 1'b0 ; // READ
12606
 
12607
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12608
    $display("Memory read through PCI bridge to WB slave!");
12609
 
12610
    if ( expect_length_wr == 1 )
12611
    begin
12612
        if (Set_prefetch_enable)
12613
        begin
12614
            expect_length_rd1 = Cache_lsize ;
12615
            expect_length_rd2 = 0 ;
12616
                // If PCI behavioral master must check received DATA
12617
                master2_check_received_data = 0 ;
12618
                    master1_check_received_data = 0 ;
12619
        end
12620
        else
12621
        begin
12622
            expect_length_rd1 = 1 ;
12623
            expect_length_rd2 = 0 ;
12624
                // If PCI behavioral master must check received DATA
12625
                master2_check_received_data = 1 ;
12626
                    master1_check_received_data = 1 ;
12627
        end
12628
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12629
        expect_length_rd  = expect_length_rd1 ;
12630
    end
12631
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12632
    begin
12633
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12634
        expect_length_rd2 = 0 ;
12635
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12636
        expect_length_rd  = expect_length_rd1 ;
12637
                // If PCI behavioral master must check received DATA
12638
        master2_check_received_data = 1 ;
12639
            master1_check_received_data = 1 ;
12640
    end
12641
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12642
    begin
12643
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12644
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12645
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12646
        expect_length_rd  = expect_length_rd1 ;
12647
                // If PCI behavioral master must check received DATA
12648
                master2_check_received_data = 1 ;
12649
            master1_check_received_data = 1 ;
12650
    end
12651
    else
12652
    begin
12653
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12654
        begin
12655
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12656
            expect_length_rd2 = 0 ;
12657
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12658
            expect_length_rd  = expect_length_rd1 ;
12659
                // If PCI behavioral master must check received DATA
12660
                master2_check_received_data = 0 ;
12661
                    master1_check_received_data = 0 ;
12662
        end
12663
        else
12664
        begin
12665
            if ( expect_length_wr > Cache_lsize )
12666
            begin
12667
                expect_length_rd1 = Cache_lsize ;
12668
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12669
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12670
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12671
                else
12672
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12673
                expect_length_rd  = expect_length_rd1 ;
12674
                        // If PCI behavioral master must check received DATA
12675
                        master2_check_received_data = 1 ;
12676
                            master1_check_received_data = 1 ;
12677
            end
12678
            else
12679
            begin
12680
                expect_length_rd1 = Cache_lsize ;
12681
                expect_length_rd2 = 0 ;
12682
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12683
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12684
                else
12685
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12686
                expect_length_rd  = expect_length_wr ;
12687
                                if ( expect_length_wr == Cache_lsize )
12688
                        begin
12689
                                // If PCI behavioral master must check received DATA
12690
                                master2_check_received_data = 1 ;
12691
                                    master1_check_received_data = 1 ;
12692
                                end
12693
                                else
12694
                                begin
12695
                                // If PCI behavioral master must check received DATA
12696
                                master2_check_received_data = 0 ;
12697
                                    master1_check_received_data = 0 ;
12698
                end
12699
            end
12700
        end
12701
    end
12702
 
12703
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12704
    expect_rd_address = expect_address ;
12705
    rd_data[31:0] = Data[31:0];
12706
    rd_be[3:0] = Be[3:0];
12707
 
12708
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12709
    while (expect_length_rd2 > 0)
12710
    begin
12711
        // do read
12712
        $display("Read %d words!", expect_length_rd);
12713
 
12714
        fork
12715
        begin
12716
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12717
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12718
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12719
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12720
 
12721
            wb_transaction_stop( expect_length_rd - 1) ;
12722
 
12723
            do_pause( 1 ) ;
12724
        end
12725
        begin
12726
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12727
            if ( ok !== 1 )
12728
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12729
 
12730
            repeat( 3 )
12731
                @(posedge pci_clock) ;
12732
 
12733
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12734
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12735
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12736
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12737
 
12738
            do_pause( 1 ) ;
12739
            while ( FRAME === 0 )
12740
                @(posedge pci_clock) ;
12741
 
12742
            while ( IRDY === 0 )
12743
                @(posedge pci_clock) ;
12744
 
12745 35 mihad
            #1 ;
12746
            if ( !error_monitor_done )
12747
                disable monitor_error_event1 ;
12748 15 mihad
        end
12749
        begin:monitor_error_event1
12750 35 mihad
            error_monitor_done = 0 ;
12751 15 mihad
            @(error_event_int) ;
12752
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12753
            ok = 0 ;
12754 35 mihad
            error_monitor_done = 1 ;
12755 15 mihad
        end
12756
        join
12757
 
12758
        // increasing the starting address for PCI master and for WB transaction monitor
12759
        rd_address = rd_address + (4 * expect_length_rd) ;
12760
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12761
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12762
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12763
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12764
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12765
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12766
        for (i=0; i<expect_length_rd; i=i+1)
12767
            rd_be[3:0] = {Be[2:0], Be[3]};
12768
 
12769
        // set parameters for next read
12770
        if ( expect_length_rd2 == 1 )
12771
        begin
12772
                if (Set_prefetch_enable)
12773
                begin
12774
                    expect_length_rd1 = Cache_lsize ;
12775
                    expect_length_rd2 = 0 ;
12776
                        // If PCI behavioral master must check received DATA
12777
                        master2_check_received_data = 0 ;
12778
                            master1_check_received_data = 0 ;
12779
                end
12780
                else
12781
                begin
12782
                    expect_length_rd1 = 1 ;
12783
                    expect_length_rd2 = 0 ;
12784
                        // If PCI behavioral master must check received DATA
12785
                        master2_check_received_data = 1 ;
12786
                            master1_check_received_data = 1 ;
12787
                end
12788
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12789
            expect_length_rd  = expect_length_rd1 ;
12790
        end
12791
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12792
        begin
12793
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12794
            expect_length_rd2 = 0 ;
12795
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12796
            expect_length_rd  = expect_length_rd1 ;
12797
                        // If PCI behavioral master must check received DATA
12798
                        master2_check_received_data = 1 ;
12799
                    master1_check_received_data = 1 ;
12800
        end
12801
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12802
        begin
12803
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12804
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12805
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12806
            expect_length_rd  = expect_length_rd1 ;
12807
                        // If PCI behavioral master must check received DATA
12808
                        master2_check_received_data = 1 ;
12809
                    master1_check_received_data = 1 ;
12810
        end
12811
        else
12812
        begin
12813
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12814
            begin
12815
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12816
                expect_length_rd2 = 0 ;
12817
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12818
                expect_length_rd  = expect_length_rd1 ;
12819
                        // If PCI behavioral master must check received DATA
12820
                        master2_check_received_data = 0 ;
12821
                            master1_check_received_data = 0 ;
12822
            end
12823
            else
12824
            begin
12825
                if ( expect_length_rd2 > Cache_lsize )
12826
                begin
12827
                    expect_length_rd1 = Cache_lsize ;
12828
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12829
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12830
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12831
                    else
12832
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12833
                    expect_length_rd  = expect_length_rd1 ;
12834
                                // If PCI behavioral master must check received DATA
12835
                                master2_check_received_data = 1 ;
12836
                                    master1_check_received_data = 1 ;
12837
                end
12838
                else
12839
                begin
12840
                    expect_length_rd  = expect_length_rd2 ;
12841
                    expect_length_rd1 = Cache_lsize ;
12842
                    expect_length_rd2 = 0 ;
12843
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12844
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12845
                    else
12846
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12847
                                        if ( expect_length_rd2 == Cache_lsize )
12848
                                begin
12849
                                        // If PCI behavioral master must check received DATA
12850
                                        master2_check_received_data = 1 ;
12851
                                            master1_check_received_data = 1 ;
12852
                                        end
12853
                                        else
12854
                                        begin
12855
                                        // If PCI behavioral master must check received DATA
12856
                                        master2_check_received_data = 0 ;
12857
                                            master1_check_received_data = 0 ;
12858
                        end
12859
                end
12860
            end
12861
        end
12862
    end
12863
    // do last read
12864
    $display("Read %d words!", expect_length_rd);
12865
 
12866
    fork
12867
    begin
12868
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12869
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12870
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12871
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12872
 
12873
        wb_transaction_stop(expect_length_rd - 1) ;
12874
        do_pause( 1 ) ;
12875
    end
12876
    begin
12877
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12878
 
12879
        do_pause(3) ;
12880
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12881
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12882
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12883
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12884
        do_pause(1) ;
12885
 
12886
        while ( FRAME === 0 )
12887
            @(posedge pci_clock) ;
12888
 
12889
        while ( IRDY === 0 )
12890
            @(posedge pci_clock) ;
12891
 
12892 35 mihad
        #1 ;
12893
        if ( !error_monitor_done )
12894
            disable monitor_error_event2 ;
12895 15 mihad
    end
12896
    begin:monitor_error_event2
12897 35 mihad
        error_monitor_done = 0 ;
12898 15 mihad
        @(error_event_int) ;
12899
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12900
        ok = 0 ;
12901 35 mihad
        error_monitor_done = 1 ;
12902 15 mihad
    end
12903
    join
12904
 
12905
    if ( ok )
12906
        test_ok ;
12907
 
12908
    // Check that no ERRORs were reported
12909
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12910
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
12911
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12912
    config_read( addr_offset, 4'hF, read_data ) ;
12913
    if ( read_data[8] !== 0 )
12914
    begin
12915
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
12916
        test_fail("error status was set even though no errors occured on WB bus") ;
12917
    end
12918
    else
12919
    begin
12920
        $display("No error was signaled, as expected!");
12921
        test_ok ;
12922
    end
12923
 
12924
end // main
12925
endtask // test_normal_wr_rd
12926
 
12927
// Test erroneous write to WB slave
12928
task test_wb_error_wr;
12929
  input  [2:0]  Master_ID;
12930
  input  [PCI_BUS_DATA_RANGE:0] Address;
12931
  input  [PCI_BUS_DATA_RANGE:0] Data;
12932
  input  [3:0]  Be;
12933
  input  [2:0]  Image_num;
12934
  input  [9:0]  Set_size;
12935
  input         Set_err_and_int_report;
12936
  input         Set_wb_wait_states;
12937
  input  [1:0]  Imm_BefLast_Last_error;
12938
 
12939
  reg    [11:0] addr_offset;
12940
  reg    [31:0] read_data;
12941
  reg           continue ;
12942
  reg           ok   ;
12943
  reg    [9:0]  expect_length ;
12944
  reg    [31:0] expect_address ;
12945
  reg    [0:0]  expect_we ;
12946
  reg    [31:0] rd_address;
12947
  reg    [31:0] rd_data;
12948
  reg    [3:0]  rd_be;
12949
  integer       i ;
12950
begin:main
12951
    if (Set_err_and_int_report)
12952
    begin
12953
        // enable ERROR reporting, because error must be reported and interrupt if required!
12954
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12955
        $display(" - errors will be reported when they will occur!");
12956
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
12957
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12958
        $display(" - interrupt will be reported when error will occur!");
12959
    end
12960
    else
12961
    begin
12962
        // disable ERROR reporting, because error and interrupt must not be reported!
12963
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12964
        $display(" - errors will NOT be reported when they will occur!");
12965
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
12966
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12967
        $display(" - interrupt will NOT be reported when error will occur!");
12968
    end
12969
    // enable/disable ERROR reporting
12970
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
12971
 
12972
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12973
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
12974
    if ( ok !== 1 )
12975
    begin
12976
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12977
        test_fail("PCI Error Control and Status register could not be written") ;
12978
        disable main;
12979
    end
12980
    // enable/disable INTERRUPT reporting
12981
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
12982
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
12983
    if ( ok !== 1 )
12984
    begin
12985
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
12986
        test_fail("Interrupt Control register could not be written") ;
12987
        disable main;
12988
    end
12989
 
12990
    `ifdef  ADDR_TRAN_IMPL
12991
 
12992
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
12993
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12994
    config_read( addr_offset, 4'hF, read_data ) ;
12995
    if ( read_data[2] !== 0 )
12996
    begin
12997
        $display("Address translation is set for PCI image%d!", Image_num);
12998
        // predict the address and control signals on WB bus
12999
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13000
        expect_we      = 1'b1 ; // WRITE
13001
    end
13002
    else
13003
    begin
13004
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13005
        // predict the address and control signals on WB bus
13006
        expect_address = Address ;
13007
        expect_we      = 1'b1 ; // WRITE
13008
    end
13009
 
13010
    `else
13011
 
13012
    // address translation is not implemented
13013
    $display("Address translation is NOT implemented for PCI images!");
13014
    // predict the address and control signals on WB bus
13015
    expect_address = Address ;
13016
    expect_we      = 1'b1 ; // WRITE
13017
 
13018
    `endif
13019
 
13020
    if ( Set_size > (`PCIW_DEPTH - 2) )
13021
    begin
13022
        expect_length = `PCIW_DEPTH - 2 ;
13023
    end
13024
    else
13025
    begin
13026
        expect_length = Set_size ;
13027
    end
13028
 
13029
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13030
    begin
13031
        $display("ERR termination with first data!");
13032
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13033
    end
13034
    else if (Imm_BefLast_Last_error == 1)
13035
    begin
13036
        $display("ERR termination before last data!");
13037
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13038
    end
13039
    else
13040
    begin
13041
        $display("ERR termination with last data!");
13042
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13043
    end
13044
 
13045
    // write through the PCI bridge to WB slave
13046
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13047
    fork
13048
    begin
13049
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13050
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13051
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13052
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13053
        do_pause( 1 ) ;
13054
    end
13055
    begin
13056
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13057
        begin
13058
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13059
            if ( ok !== 1 )
13060
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13061
        end
13062
        else if (Imm_BefLast_Last_error == 1)
13063
        begin
13064
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13065
            if ( ok !== 1 )
13066
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13067
        end
13068
        else
13069
        begin
13070
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13071
            if ( ok !== 1 )
13072
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13073
        end
13074
    end
13075
    begin
13076
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13077
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13078
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13079
        else if (Imm_BefLast_Last_error == 1)
13080
        begin
13081
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13082
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13083
            wb_transaction_stop(expect_length-2) ;
13084
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13085
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13086
        end
13087
        else
13088
        begin
13089
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13090
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13091
            wb_transaction_stop(expect_length-1) ;
13092
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13093
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13094
        end
13095
    end
13096
    join
13097
 
13098
    if ( ok )
13099
        test_ok ;
13100
 
13101
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13102
    begin
13103
        rd_data[31:0] = Data[31:0];
13104
        rd_address[31:0] = expect_address;
13105
        rd_be[3:0] = Be[3:0];
13106
    end
13107
    else if (Imm_BefLast_Last_error == 1)
13108
    begin
13109
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13110
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13111
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13112
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13113
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13114
        rd_be[3:0] = Be[3:0];
13115
        for (i=0; i<(expect_length-2); i=i+1)
13116
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13117
    end
13118
    else
13119
    begin
13120
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13121
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13122
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13123
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13124
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13125
        rd_be[3:0] = Be[3:0];
13126
        for (i=0; i<(expect_length-1); i=i+1)
13127
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13128
    end
13129
 
13130
    master2_check_received_data = 0 ;
13131
    master1_check_received_data = 0 ;
13132
 
13133
    // Check if ERRORs were reported
13134
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13135
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13136
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13137
 
13138
    ok = 1 ;
13139
    config_read( addr_offset, 4'hF, read_data ) ;
13140
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13141
    begin
13142
        $display("Error was signaled and reported, as expected!");
13143
        if (read_data[31:28] === rd_be)
13144
            $display("Byte enables written into P_ERR_CS register are as expected!");
13145
        else
13146
        begin
13147
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13148
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13149
            ok = 0 ;
13150
        end
13151
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13152
            $display("Bus command written into P_ERR_CS register is as expected!");
13153
        else
13154
        begin
13155
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13156
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13157
            ok = 0 ;
13158
        end
13159
 
13160
        if ( ok )
13161
            test_ok ;
13162
 
13163
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13164
 
13165
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13166
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13167
        config_read( addr_offset, 4'hF, read_data ) ;
13168
        if (read_data === rd_data)
13169
        begin
13170
            $display("Data written into P_ERR_DATA register is as expected!");
13171
            test_ok ;
13172
        end
13173
        else
13174
        begin
13175
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13176
            test_fail("PCI Erroneous Data register value was wrong") ;
13177
        end
13178
 
13179
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13180
 
13181
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13182
 
13183
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13184
        config_read( addr_offset, 4'hF, read_data ) ;
13185
        if (read_data === rd_address)
13186
        begin
13187
            $display("Address written into P_ERR_ADDR register is as expected!");
13188
            test_ok ;
13189
        end
13190
        else
13191
        begin
13192
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13193
            test_fail("PCI Erroneous Address register value was wrong") ;
13194
        end
13195
    end
13196
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13197
    begin
13198
        $display("Error was signaled and not reported, as expected!");
13199
        test_ok ;
13200
    end
13201
    else
13202
    begin
13203
        $display("Error was signaled and reported, as NOT expected!");
13204
        test_fail("Error status bit was set event though error reporting was disabled") ;
13205
    end
13206
 
13207
    // Check if Interrupts were reported
13208
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13209
 
13210
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13211
    ok = 1 ;
13212
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13213
    config_read( addr_offset, 4'hF, read_data ) ;
13214
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13215
    begin
13216
        $display("Interrupts was signaled and reported, as expected!");
13217
    end
13218
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13219
    begin
13220
        $display("Interrupts was signaled and not reported, as expected!");
13221
    end
13222
    else
13223
    begin
13224
        $display("Interrupt was signaled and reported, as NOT expected!");
13225
        test_fail("PCI Error Interrupt status was set when not expected") ;
13226
        ok = 0 ;
13227
    end
13228
 
13229
    `ifdef HOST
13230
    repeat( 4 )
13231
        @(posedge wb_clock) ;
13232
 
13233
    if ( INT_O === Set_err_and_int_report )
13234
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13235
    else
13236
    begin
13237
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13238
        test_fail("Interrupt request didn't have expected value") ;
13239
        ok = 0 ;
13240
    end
13241
 
13242
    `else // GUEST
13243
    repeat( 4 )
13244
        @(posedge pci_clock) ;
13245
 
13246
    if ( INTA === !Set_err_and_int_report )
13247
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13248
    else
13249
    begin
13250
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13251
        test_fail("Interrupt request didn't have expected value") ;
13252
        ok = 0 ;
13253
    end
13254
 
13255
    `endif
13256
 
13257
    if ( ok )
13258
        test_ok ;
13259
 
13260
    if (Set_err_and_int_report)
13261
    begin
13262
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13263
        $display("Error and Interrupt must be cleared!");
13264
        // clear  ERROR reporting bit
13265
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13266
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13267
        if ( ok !== 1 )
13268
        begin
13269
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13270
            test_fail("PCI Error Control and Status register could not be written to") ;
13271
            disable main;
13272
        end
13273
 
13274
        // clear INTERRUPT reporting bit
13275
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13276
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13277
        if ( ok !== 1 )
13278
        begin
13279
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13280
            test_fail("Interrupt Status register could not be written to") ;
13281
            disable main;
13282
        end
13283
 
13284
        test_ok ;
13285
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13286
        `ifdef HOST
13287
 
13288
        repeat(4)
13289
            @(posedge wb_clock) ;
13290
        if ( INT_O === 1'b0 )
13291
        begin
13292
            $display("Interrupt pin INT_O was correctly cleared!");
13293
            test_ok ;
13294
        end
13295
        else
13296
        begin
13297
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13298
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13299
            disable main;
13300
        end
13301
 
13302
        `else // GUEST
13303
 
13304
        repeat(4)
13305
            @(posedge pci_clock) ;
13306
        if ( INTA === 1'b1 )
13307
        begin
13308
            $display("Interrupt pin INTA was correctly cleared!");
13309
            test_ok ;
13310
        end
13311
        else
13312
        begin
13313
            $display("Interrupt pin INTA was NOT correctly cleared!");
13314
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13315
            disable main;
13316
        end
13317
 
13318
        `endif
13319
 
13320
    end
13321
    else
13322
    begin
13323
        $display("Error and Interrupt don't need to be cleared!");
13324
    end
13325
end // main
13326
endtask // test_wb_error_wr
13327
 
13328
task test_wb_error_rd;
13329
    reg    [11:0] addr_offset ;
13330
    reg    [11:0] ctrl_offset ;
13331
    reg    [11:0] ba_offset ;
13332
    reg    [11:0] am_offset ;
13333
    reg    [11:0] ta_offset ;
13334
    reg    [31:0] read_data;
13335
    reg           ok   ;
13336
    reg    [9:0]  expect_length ;
13337
    reg    [31:0] expect_address ;
13338
    reg    [0:0]  expect_we ;
13339
    reg    [31:0] rd_address;
13340
    reg    [31:0] rd_data;
13341
    reg    [3:0]  rd_be;
13342
    integer       i ;
13343
    reg           do_mem_aborts ;
13344
    reg           do_io_aborts ;
13345 35 mihad
    reg           error_monitor_done ;
13346 15 mihad
begin:main
13347
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13348
 
13349
    if ( target_mem_image !== -1 )
13350
    begin
13351
        do_mem_aborts = 1 ;
13352
 
13353
        if (target_mem_image === 1)
13354
        begin
13355
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13356
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13357
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13358
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13359
        end
13360
        else if (target_mem_image === 2)
13361
        begin
13362
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13363
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13364
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13365
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13366
        end
13367
        else if (target_mem_image === 3)
13368
        begin
13369
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13370
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13371
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13372
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13373
        end
13374
        else if (target_mem_image === 4)
13375
        begin
13376
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13377
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13378
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13379
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13380
        end
13381
        else if (target_mem_image === 5)
13382
        begin
13383
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13384
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13385
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13386
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13387
        end
13388
    end
13389
    else
13390
        do_mem_aborts = 0 ;
13391
 
13392
    if ( do_mem_aborts )
13393
    begin
13394
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13395
 
13396
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13397
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13398
        if ( ok !== 1 )
13399
        begin
13400
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13401
            test_fail("PCI Error Control and Status register could not be written") ;
13402
            disable main;
13403
        end
13404
 
13405
        // enable INTERRUPT reporting
13406
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13407
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13408
        if ( ok !== 1 )
13409
        begin
13410
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13411
            test_fail("Interrupt Control register could not be written") ;
13412
            disable main;
13413
        end
13414
 
13415
        addr_offset = 12'h010 + (4*target_mem_image) ;
13416
 
13417
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13418
        if ( ok !== 1 )
13419
        begin
13420
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13421
            test_fail("PCI Base Address register could not be written") ;
13422
            disable main;
13423
        end
13424
 
13425
        // disable address translation and enable prefetch so read bursts can be performed
13426
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13427
        if ( ok !== 1 )
13428
        begin
13429
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13430
            test_fail("PCI Image Control register could not be written") ;
13431
            disable main;
13432
        end
13433
 
13434
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13435
        if ( ok !== 1 )
13436
        begin
13437
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13438
            test_fail("PCI Address Mask register could not be written") ;
13439
            disable main;
13440
        end
13441
 
13442
        addr_offset = 12'h00C ;
13443
 
13444
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13445
        if ( ok !== 1 )
13446
        begin
13447
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13448
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13449
            disable main;
13450
        end
13451
 
13452
        // disable PCI master data checking
13453
        master1_check_received_data = 0 ;
13454
 
13455
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13456
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13457
 
13458
 
13459
        // do a single read error terminated on WB bus
13460
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13461
 
13462
        fork
13463
        begin
13464
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13465
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13466
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13467
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13468
 
13469
            do_pause( 1 ) ;
13470
        end
13471
        begin
13472
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13473
 
13474
            if ( ok !== 1 )
13475
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13476
 
13477
            do_pause(3) ;
13478
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13479
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13480
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13481
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13482
            do_pause(1) ;
13483
 
13484
            while ( FRAME === 0 )
13485
                @(posedge pci_clock) ;
13486
 
13487
            while ( IRDY === 0 )
13488
                @(posedge pci_clock) ;
13489
 
13490 35 mihad
            #1 ;
13491
            if ( !error_monitor_done )
13492
                disable monitor_error_event1 ;
13493 15 mihad
        end
13494
        begin:monitor_error_event1
13495 35 mihad
            error_monitor_done = 0 ;
13496 15 mihad
            @(error_event_int) ;
13497
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13498
            ok = 0 ;
13499 35 mihad
            error_monitor_done = 1 ;
13500 15 mihad
        end
13501
        join
13502
 
13503
        if ( ok )
13504
            test_ok ;
13505 26 mihad
 
13506
        @(posedge pci_clock) ;
13507
        @(posedge pci_clock) ;
13508
        @(posedge wb_clock) ;
13509
        @(posedge wb_clock) ;
13510 15 mihad
 
13511
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13512
        addr_offset = 12'h004 ;
13513
        config_read(addr_offset, 4'hF, read_data) ;
13514
        ok = 1 ;
13515
        if ( read_data[27] !== 1 )
13516
        begin
13517
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13518
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13519
            ok = 0 ;
13520
        end
13521
        if ( read_data[28] !== 0 )
13522
        begin
13523
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13524
            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") ;
13525
            ok = 0 ;
13526
        end
13527
        if ( read_data[29] !== 0 )
13528
        begin
13529
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13530
            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") ;
13531
            ok = 0 ;
13532
        end
13533
 
13534
        // clear statuses
13535
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13536
        if ( !ok )
13537
        begin
13538
            test_fail("write to PCI Device Status register failed") ;
13539
            $display("Couldn't write PCI Device Status register") ;
13540
            disable main ;
13541
        end
13542
 
13543
        if ( ok )
13544
            test_ok ;
13545
 
13546
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13547
 
13548
        ok = 1 ;
13549
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13550
 
13551
        config_read(addr_offset, 4'hF, read_data) ;
13552
        if (read_data[8] !== 0)
13553
        begin
13554
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13555
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13556
            ok = 0 ;
13557
        end
13558
        else
13559
            test_ok ;
13560
 
13561
        if ( ok !== 1 )
13562
        begin
13563
            config_write(addr_offset, read_data, 4'hF, ok) ;
13564
            if ( !ok )
13565
            begin
13566
                test_fail("PCI Error Control and Status register could not be written") ;
13567
                disable main ;
13568
            end
13569
        end
13570
 
13571
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13572
        fork
13573
        begin
13574
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13575
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13576
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13577
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13578
 
13579
            do_pause( 1 ) ;
13580
        end
13581
        begin
13582
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13583
 
13584
            if ( ok !== 1 )
13585
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13586
 
13587
            do_pause(3) ;
13588
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13589
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13590
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13591
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13592
            do_pause(1) ;
13593
 
13594
            while ( FRAME === 0 )
13595
                @(posedge pci_clock) ;
13596
 
13597
            while ( IRDY === 0 )
13598
                @(posedge pci_clock) ;
13599
 
13600 35 mihad
            #1 ;
13601
            if ( !error_monitor_done )
13602
                disable monitor_error_event2 ;
13603 15 mihad
        end
13604
        begin:monitor_error_event2
13605 35 mihad
            error_monitor_done = 0 ;
13606 15 mihad
            @(error_event_int) ;
13607
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13608
            ok = 0 ;
13609 35 mihad
            error_monitor_done = 1 ;
13610 15 mihad
        end
13611
        join
13612
 
13613
        if ( ok )
13614
            test_ok ;
13615
 
13616 26 mihad
        @(posedge pci_clock) ;
13617
        @(posedge pci_clock) ;
13618
        @(posedge wb_clock) ;
13619
        @(posedge wb_clock) ;
13620
 
13621 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13622
        addr_offset = 12'h004 ;
13623
        config_read(addr_offset, 4'hF, read_data) ;
13624
        ok = 1 ;
13625
        if ( read_data[27] !== 1 )
13626
        begin
13627
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13628
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13629
            ok = 0 ;
13630
        end
13631
        if ( read_data[28] !== 0 )
13632
        begin
13633
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13634
            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") ;
13635
            ok = 0 ;
13636
        end
13637
        if ( read_data[29] !== 0 )
13638
        begin
13639
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13640
            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") ;
13641
            ok = 0 ;
13642
        end
13643
 
13644
        // clear statuses
13645
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13646
        if ( !ok )
13647
        begin
13648
            test_fail("write to PCI Device Status register failed") ;
13649
            $display("Couldn't write PCI Device Status register") ;
13650
            disable main ;
13651
        end
13652
 
13653
        if ( ok )
13654
            test_ok ;
13655
 
13656
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13657
 
13658
        ok = 1 ;
13659
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13660
 
13661
        config_read(addr_offset, 4'hF, read_data) ;
13662
        if (read_data[8] !== 0)
13663
        begin
13664
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13665
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13666
            ok = 0 ;
13667
        end
13668
        else
13669
            test_ok ;
13670
 
13671
        if ( ok !== 1 )
13672
        begin
13673
            config_write(addr_offset, read_data, 4'hF, ok) ;
13674
            if ( !ok )
13675
            begin
13676
                test_fail("PCI Error Control and Status register could not be written") ;
13677
                disable main ;
13678
            end
13679
        end
13680
 
13681
        // do a single read error terminated on WB bus
13682
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13683
 
13684
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13685
 
13686
        fork
13687
        begin
13688
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13689
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13690
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13691
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13692
 
13693
            do_pause( 1 ) ;
13694
        end
13695
        begin
13696
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13697
 
13698
            if ( ok !== 1 )
13699
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13700
 
13701
            do_pause(3) ;
13702
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13703
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13704
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13705
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13706
            do_pause(1) ;
13707
 
13708
            while ( FRAME === 0 )
13709
                @(posedge pci_clock) ;
13710
 
13711
            while ( IRDY === 0 )
13712
                @(posedge pci_clock) ;
13713
 
13714 35 mihad
            if ( !error_monitor_done )
13715
                disable monitor_error_event3 ;
13716 15 mihad
        end
13717
        begin:monitor_error_event3
13718 35 mihad
            error_monitor_done = 0 ;
13719 15 mihad
            @(error_event_int) ;
13720
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13721
            ok = 0 ;
13722 35 mihad
            error_monitor_done = 1 ;
13723 15 mihad
        end
13724
        join
13725
 
13726
        if ( ok )
13727
            test_ok ;
13728
 
13729 26 mihad
        @(posedge pci_clock) ;
13730
        @(posedge pci_clock) ;
13731
        @(posedge wb_clock) ;
13732
        @(posedge wb_clock) ;
13733
 
13734 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13735
        addr_offset = 12'h004 ;
13736
        config_read(addr_offset, 4'hF, read_data) ;
13737
        ok = 1 ;
13738
        if ( read_data[27] !== 1 )
13739
        begin
13740
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13741
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13742
            ok = 0 ;
13743
        end
13744
        if ( read_data[28] !== 0 )
13745
        begin
13746
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13747
            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") ;
13748
            ok = 0 ;
13749
        end
13750
        if ( read_data[29] !== 0 )
13751
        begin
13752
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13753
            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") ;
13754
            ok = 0 ;
13755
        end
13756
 
13757
        // clear statuses
13758
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13759
        if ( !ok )
13760
        begin
13761
            test_fail("write to PCI Device Status register failed") ;
13762
            $display("Couldn't write PCI Device Status register") ;
13763
            disable main ;
13764
        end
13765
 
13766
        if ( ok )
13767
            test_ok ;
13768
 
13769
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13770
 
13771
        ok = 1 ;
13772
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13773
 
13774
        config_read(addr_offset, 4'hF, read_data) ;
13775
        if (read_data[8] !== 0)
13776
        begin
13777
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13778
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13779
            ok = 0 ;
13780
        end
13781
        else
13782
            test_ok ;
13783
 
13784
        if ( ok !== 1 )
13785
        begin
13786
            config_write(addr_offset, read_data, 4'hF, ok) ;
13787
            if ( !ok )
13788
            begin
13789
                test_fail("PCI Error Control and Status register could not be written") ;
13790
                disable main ;
13791
            end
13792
        end
13793
 
13794
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13795
 
13796
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13797
 
13798
        fork
13799
        begin
13800
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13801
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13802
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13803
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13804
 
13805
            do_pause( 1 ) ;
13806
        end
13807
        begin
13808
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13809
 
13810
            if ( ok !== 1 )
13811
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13812
 
13813
            do_pause(3) ;
13814
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13815
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13816
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13817
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13818
            do_pause(1) ;
13819
 
13820
            while ( FRAME === 0 )
13821
                @(posedge pci_clock) ;
13822
 
13823
            while ( IRDY === 0 )
13824
                @(posedge pci_clock) ;
13825
 
13826 35 mihad
            #1 ;
13827
            if ( !error_monitor_done )
13828
                disable monitor_error_event4 ;
13829 15 mihad
        end
13830
        begin:monitor_error_event4
13831 35 mihad
            error_monitor_done = 0 ;
13832 15 mihad
            @(error_event_int) ;
13833
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13834
            ok = 0 ;
13835 35 mihad
            error_monitor_done = 1 ;
13836 15 mihad
        end
13837
        begin
13838
            wb_transaction_stop( 1 ) ;
13839
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13840
        end
13841
        join
13842
 
13843
        if ( ok )
13844
            test_ok ;
13845
 
13846 26 mihad
        @(posedge pci_clock) ;
13847
        @(posedge pci_clock) ;
13848
        @(posedge wb_clock) ;
13849
        @(posedge wb_clock) ;
13850
 
13851 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13852
        addr_offset = 12'h004 ;
13853
        config_read(addr_offset, 4'hF, read_data) ;
13854
        ok = 1 ;
13855
        if ( read_data[27] !== 1 )
13856
        begin
13857
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13858
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13859
            ok = 0 ;
13860
        end
13861
        if ( read_data[28] !== 0 )
13862
        begin
13863
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13864
            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") ;
13865
            ok = 0 ;
13866
        end
13867
        if ( read_data[29] !== 0 )
13868
        begin
13869
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13870
            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") ;
13871
            ok = 0 ;
13872
        end
13873
 
13874
        // clear statuses
13875
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13876
        if ( !ok )
13877
        begin
13878
            test_fail("write to PCI Device Status register failed") ;
13879
            $display("Couldn't write PCI Device Status register") ;
13880
            disable main ;
13881
        end
13882
 
13883
        if ( ok )
13884
            test_ok ;
13885
 
13886
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13887
 
13888
        ok = 1 ;
13889
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13890
 
13891
        config_read(addr_offset, 4'hF, read_data) ;
13892
        if (read_data[8] !== 0)
13893
        begin
13894
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13895
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13896
            ok = 0 ;
13897
        end
13898
        else
13899
            test_ok ;
13900
 
13901
        if ( ok !== 1 )
13902
        begin
13903
            config_write(addr_offset, read_data, 4'hF, ok) ;
13904
            if ( !ok )
13905
            begin
13906
                test_fail("PCI Error Control and Status register could not be written") ;
13907
                disable main ;
13908
            end
13909
        end
13910
 
13911
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13912
 
13913
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13914
 
13915
        fork
13916
        begin
13917
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13918
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13919
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13920
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13921
 
13922
            do_pause( 1 ) ;
13923
        end
13924
        begin
13925
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13926
 
13927
            if ( ok !== 1 )
13928
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13929
 
13930
            do_pause(3) ;
13931
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13932
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13933
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13934
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13935
            do_pause(1) ;
13936
 
13937
            while ( FRAME === 0 )
13938
                @(posedge pci_clock) ;
13939
 
13940
            while ( IRDY === 0 )
13941
                @(posedge pci_clock) ;
13942
 
13943 35 mihad
            #1 ;
13944
            if ( !error_monitor_done )
13945
                disable monitor_error_event5 ;
13946 15 mihad
        end
13947
        begin:monitor_error_event5
13948 35 mihad
            error_monitor_done = 0 ;
13949 15 mihad
            @(error_event_int) ;
13950
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13951
            ok = 0 ;
13952 35 mihad
            error_monitor_done = 1 ;
13953 15 mihad
        end
13954
        begin
13955
            wb_transaction_stop( 3 ) ;
13956
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13957
        end
13958
        join
13959
 
13960
        if ( ok )
13961
            test_ok ;
13962
 
13963 26 mihad
        @(posedge pci_clock) ;
13964
        @(posedge pci_clock) ;
13965
        @(posedge wb_clock) ;
13966
        @(posedge wb_clock) ;
13967
 
13968 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13969
        addr_offset = 12'h004 ;
13970
        config_read(addr_offset, 4'hF, read_data) ;
13971
        ok = 1 ;
13972
        if ( read_data[27] !== 1 )
13973
        begin
13974
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13975
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13976
            ok = 0 ;
13977
        end
13978
        if ( read_data[28] !== 0 )
13979
        begin
13980
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13981
            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") ;
13982
            ok = 0 ;
13983
        end
13984
        if ( read_data[29] !== 0 )
13985
        begin
13986
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13987
            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") ;
13988
            ok = 0 ;
13989
        end
13990
 
13991
        // clear statuses
13992
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13993
        if ( !ok )
13994
        begin
13995
            test_fail("write to PCI Device Status register failed") ;
13996
            $display("Couldn't write PCI Device Status register") ;
13997
            disable main ;
13998
        end
13999
 
14000
        if ( ok )
14001
            test_ok ;
14002
 
14003
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14004
 
14005
        ok = 1 ;
14006
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14007
 
14008
        config_read(addr_offset, 4'hF, read_data) ;
14009
        if (read_data[8] !== 0)
14010
        begin
14011
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14012
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14013
            ok = 0 ;
14014
        end
14015
        else
14016
            test_ok ;
14017
 
14018
        if ( ok !== 1 )
14019
        begin
14020
            config_write(addr_offset, read_data, 4'hF, ok) ;
14021
            if ( !ok )
14022
            begin
14023
                test_fail("PCI Error Control and Status register could not be written") ;
14024
                disable main ;
14025
            end
14026
        end
14027
 
14028
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14029
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14030
        fork
14031
        begin
14032
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14033
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14034
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14035
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14036
 
14037
            do_pause( 1 ) ;
14038
        end
14039
        begin
14040
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14041
 
14042
            if ( ok !== 1 )
14043
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14044
 
14045
            do_pause(3) ;
14046
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14047
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14048
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14049
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14050
            do_pause(1) ;
14051
 
14052
            while ( FRAME === 0 )
14053
                @(posedge pci_clock) ;
14054
 
14055
            while ( IRDY === 0 )
14056
                @(posedge pci_clock) ;
14057
 
14058 35 mihad
            #1 ;
14059
            if ( !error_monitor_done )
14060
                disable monitor_error_event6 ;
14061 15 mihad
        end
14062
        begin:monitor_error_event6
14063 35 mihad
            error_monitor_done = 0 ;
14064 15 mihad
            @(error_event_int) ;
14065
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14066
            ok = 0 ;
14067 35 mihad
            error_monitor_done = 1 ;
14068 15 mihad
        end
14069
        begin
14070
            wb_transaction_stop( 3 ) ;
14071
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14072
        end
14073
        join
14074
 
14075
        if ( ok )
14076
            test_ok ;
14077
 
14078 26 mihad
        @(posedge pci_clock) ;
14079
        @(posedge pci_clock) ;
14080
        @(posedge wb_clock) ;
14081
        @(posedge wb_clock) ;
14082
 
14083 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14084
        addr_offset = 12'h004 ;
14085
        config_read(addr_offset, 4'hF, read_data) ;
14086
        ok = 1 ;
14087
        if ( read_data[27] !== 1 )
14088
        begin
14089
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14090
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14091
            ok = 0 ;
14092
        end
14093
        if ( read_data[28] !== 0 )
14094
        begin
14095
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14096
            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") ;
14097
            ok = 0 ;
14098
        end
14099
        if ( read_data[29] !== 0 )
14100
        begin
14101
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14102
            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") ;
14103
            ok = 0 ;
14104
        end
14105
 
14106
        // clear statuses
14107
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14108
        if ( !ok )
14109
        begin
14110
            test_fail("write to PCI Device Status register failed") ;
14111
            $display("Couldn't write PCI Device Status register") ;
14112
            disable main ;
14113
        end
14114
 
14115
        if ( ok )
14116
            test_ok ;
14117
 
14118
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14119
 
14120
        ok = 1 ;
14121
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14122
 
14123
        config_read(addr_offset, 4'hF, read_data) ;
14124
        if (read_data[8] !== 0)
14125
        begin
14126
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14127
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14128
            ok = 0 ;
14129
        end
14130
        else
14131
            test_ok ;
14132
 
14133
        if ( ok !== 1 )
14134
        begin
14135
            config_write(addr_offset, read_data, 4'hF, ok) ;
14136
            if ( !ok )
14137
            begin
14138
                test_fail("PCI Error Control and Status register could not be written") ;
14139
                disable main ;
14140
            end
14141
        end
14142
 
14143
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14144
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14145
        fork
14146
        begin
14147
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14148
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14149
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14150
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14151
 
14152
            do_pause( 1 ) ;
14153
        end
14154
        begin
14155
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14156
 
14157
            if ( ok !== 1 )
14158
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14159
 
14160
            do_pause(3) ;
14161
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14162
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14163
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14164
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14165
            do_pause(1) ;
14166
 
14167
            while ( FRAME === 0 )
14168
                @(posedge pci_clock) ;
14169
 
14170
            while ( IRDY === 0 )
14171
                @(posedge pci_clock) ;
14172
 
14173 35 mihad
            #1 ;
14174
            if ( !error_monitor_done )
14175
                disable monitor_error_event7 ;
14176 15 mihad
        end
14177
        begin:monitor_error_event7
14178 35 mihad
            error_monitor_done = 0 ;
14179 15 mihad
            @(error_event_int) ;
14180
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14181
            ok = 0 ;
14182 35 mihad
            error_monitor_done = 1 ;
14183 15 mihad
        end
14184
        begin
14185
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14186
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14187
        end
14188
        join
14189
 
14190
        if ( ok )
14191
            test_ok ;
14192
 
14193 26 mihad
        @(posedge pci_clock) ;
14194
        @(posedge pci_clock) ;
14195
        @(posedge wb_clock) ;
14196
        @(posedge wb_clock) ;
14197
 
14198 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14199
        addr_offset = 12'h004 ;
14200
        config_read(addr_offset, 4'hF, read_data) ;
14201
        ok = 1 ;
14202
        if ( read_data[27] !== 1 )
14203
        begin
14204
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14205
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14206
            ok = 0 ;
14207
        end
14208
        if ( read_data[28] !== 0 )
14209
        begin
14210
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14211
            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") ;
14212
            ok = 0 ;
14213
        end
14214
        if ( read_data[29] !== 0 )
14215
        begin
14216
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14217
            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") ;
14218
            ok = 0 ;
14219
        end
14220
 
14221
        // clear statuses
14222
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14223
        if ( !ok )
14224
        begin
14225
            test_fail("write to PCI Device Status register failed") ;
14226
            $display("Couldn't write PCI Device Status register") ;
14227
            disable main ;
14228
        end
14229
 
14230
        if ( ok )
14231
            test_ok ;
14232
 
14233
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14234
 
14235
        ok = 1 ;
14236
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14237
 
14238
        config_read(addr_offset, 4'hF, read_data) ;
14239
        if (read_data[8] !== 0)
14240
        begin
14241
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14242
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14243
            ok = 0 ;
14244
        end
14245
        else
14246
            test_ok ;
14247
 
14248
        if ( ok !== 1 )
14249
        begin
14250
            config_write(addr_offset, read_data, 4'hF, ok) ;
14251
            if ( !ok )
14252
            begin
14253
                test_fail("PCI Error Control and Status register could not be written") ;
14254
                disable main ;
14255
            end
14256
        end
14257
 
14258
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14259
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14260
        fork
14261
        begin
14262
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14263
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14264
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14265
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14266
 
14267
            do_pause( 1 ) ;
14268
        end
14269
        begin
14270
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14271
 
14272
            if ( ok !== 1 )
14273
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14274
 
14275
            do_pause(3) ;
14276
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14277
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14278
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14279
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14280
            do_pause(1) ;
14281
 
14282
            while ( FRAME === 0 )
14283
                @(posedge pci_clock) ;
14284
 
14285
            while ( IRDY === 0 )
14286
                @(posedge pci_clock) ;
14287
 
14288 35 mihad
            #1 ;
14289
            if ( !error_monitor_done )
14290
                disable monitor_error_event8 ;
14291 15 mihad
        end
14292
        begin:monitor_error_event8
14293 35 mihad
            error_monitor_done = 0 ;
14294 15 mihad
            @(error_event_int) ;
14295
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14296
            ok = 0 ;
14297 35 mihad
            error_monitor_done = 1 ;
14298 15 mihad
        end
14299
        begin
14300
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14301
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14302
        end
14303
        join
14304
 
14305
        if ( ok )
14306
            test_ok ;
14307
 
14308 26 mihad
        @(posedge pci_clock) ;
14309
        @(posedge pci_clock) ;
14310
        @(posedge wb_clock) ;
14311
        @(posedge wb_clock) ;
14312
 
14313 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14314
 
14315
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14316
        addr_offset = 12'h004 ;
14317
        config_read(addr_offset, 4'hF, read_data) ;
14318
        ok = 1 ;
14319
        if ( read_data[27] !== 1 )
14320
        begin
14321
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14322
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14323
            ok = 0 ;
14324
        end
14325
        if ( read_data[28] !== 0 )
14326
        begin
14327
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14328
            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") ;
14329
            ok = 0 ;
14330
        end
14331
        if ( read_data[29] !== 0 )
14332
        begin
14333
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14334
            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") ;
14335
            ok = 0 ;
14336
        end
14337
 
14338
        // clear statuses
14339
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14340
        if ( !ok )
14341
        begin
14342
            test_fail("write to PCI Device Status register failed") ;
14343
            $display("Couldn't write PCI Device Status register") ;
14344
            disable main ;
14345
        end
14346
 
14347
        if ( ok )
14348
            test_ok ;
14349
 
14350
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14351
 
14352
        ok = 1 ;
14353
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14354
 
14355
        config_read(addr_offset, 4'hF, read_data) ;
14356
        if (read_data[8] !== 0)
14357
        begin
14358
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14359
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14360
            ok = 0 ;
14361
        end
14362
        else
14363
            test_ok ;
14364
 
14365
        if ( ok !== 1 )
14366
        begin
14367
            config_write(addr_offset, read_data, 4'hF, ok) ;
14368
            if ( !ok )
14369
            begin
14370
                test_fail("PCI Error Control and Status register could not be written") ;
14371
                disable main ;
14372
            end
14373
        end
14374
 
14375
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14376
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14377
        fork
14378
        begin
14379
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14380
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14381
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14382
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14383
 
14384
            do_pause( 1 ) ;
14385
        end
14386
        begin
14387
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14388
 
14389
            if ( ok !== 1 )
14390
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14391
 
14392
            do_pause(3) ;
14393
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14394
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14395
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14396
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14397
            do_pause(1) ;
14398
 
14399
            while ( FRAME === 0 )
14400
                @(posedge pci_clock) ;
14401
 
14402
            while ( IRDY === 0 )
14403
                @(posedge pci_clock) ;
14404
 
14405 35 mihad
            #1 ;
14406
            if ( !error_monitor_done )
14407
                disable monitor_error_event9 ;
14408 15 mihad
        end
14409
        begin:monitor_error_event9
14410 35 mihad
            error_monitor_done = 0 ;
14411 15 mihad
            @(error_event_int) ;
14412
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14413
            ok = 0 ;
14414 35 mihad
            error_monitor_done = 1 ;
14415 15 mihad
        end
14416
        begin
14417
            wb_transaction_stop( 3 ) ;
14418
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14419
        end
14420
        join
14421
 
14422
        if ( ok )
14423
            test_ok ;
14424
 
14425
        // now check all other statuses too
14426
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14427
        ok = 1 ;
14428
 
14429
        addr_offset = 12'h004 ;
14430
        config_read(addr_offset, 4'hF, read_data) ;
14431
        if (read_data[31] !== 0)
14432
        begin
14433
            $display("Detected Parity Error bit set for no reason") ;
14434
            test_fail("Detected Parity Error bit was set for no reason") ;
14435
            ok = 0 ;
14436
        end
14437
 
14438
        if (read_data[30] !== 0)
14439
        begin
14440
            $display("Signaled System Error bit set for no reason") ;
14441
            test_fail("Signaled System Error bit was set for no reason") ;
14442
            ok = 0 ;
14443
        end
14444
 
14445
        if (read_data[29] !== 0)
14446
        begin
14447
            $display("Received Master Abort bit set for no reason") ;
14448
            test_fail("Received Master Abort bit was set for no reason") ;
14449
            ok = 0 ;
14450
        end
14451
 
14452
        if (read_data[28] !== 0)
14453
        begin
14454
            $display("Received Target Abort bit set for no reason");
14455
            test_fail("Received Target Abort bit was set for no reason") ;
14456
            ok = 0 ;
14457
        end
14458
 
14459
        if (read_data[27] !== 0)
14460
        begin
14461
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14462
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14463
            ok = 0 ;
14464
        end
14465
 
14466
        if (read_data[24] !== 0)
14467
        begin
14468
            $display("Master Data Parity Error bit set for no reason") ;
14469
            test_fail("Master Data Parity Error bit was set for no reason") ;
14470
            ok = 0 ;
14471
        end
14472
 
14473
        if ( ok )
14474
            test_ok ;
14475
 
14476
        test_name = "DISABLE IMAGE" ;
14477 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14478 15 mihad
        if ( ok !== 1 )
14479
        begin
14480
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14481
            test_fail("PCI Address Mask register could not be written") ;
14482
            disable main;
14483
        end
14484
    end
14485
 
14486
    if ( target_io_image !== -1 )
14487
    begin
14488
        do_io_aborts = 1 ;
14489
 
14490
        if (target_io_image === 1)
14491
        begin
14492
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14493
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14494
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14495
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14496
        end
14497
        else if (target_io_image === 2)
14498
        begin
14499
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14500
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14501
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14502
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14503
        end
14504
        else if (target_io_image === 3)
14505
        begin
14506
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14507
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14508
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14509
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14510
        end
14511
        else if (target_io_image === 4)
14512
        begin
14513
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14514
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14515
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14516
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14517
        end
14518
        else if (target_io_image === 5)
14519
        begin
14520
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14521
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14522
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14523
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14524
        end
14525
    end
14526
    else
14527
        do_io_aborts = 0 ;
14528
 
14529
    if ( do_io_aborts )
14530
    begin
14531
 
14532
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14533
 
14534
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14535
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14536
        if ( ok !== 1 )
14537
        begin
14538
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14539
            test_fail("PCI Error Control and Status register could not be written") ;
14540
            disable main;
14541
        end
14542
 
14543
        // enable INTERRUPT reporting
14544
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14545
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14546
        if ( ok !== 1 )
14547
        begin
14548
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14549
            test_fail("Interrupt Control register could not be written") ;
14550
            disable main;
14551
        end
14552
 
14553
        addr_offset = 12'h010 + (4*target_io_image) ;
14554
 
14555
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14556
        if ( ok !== 1 )
14557
        begin
14558
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14559
            test_fail("PCI Base Address register could not be written") ;
14560
            disable main;
14561
        end
14562
 
14563
        // disable address translation and enable prefetch so read bursts can be performed
14564
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14565
        if ( ok !== 1 )
14566
        begin
14567
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14568
            test_fail("PCI Image Control register could not be written") ;
14569
            disable main;
14570
        end
14571
 
14572
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14573
        if ( ok !== 1 )
14574
        begin
14575
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14576
            test_fail("PCI Address Mask register could not be written") ;
14577
            disable main;
14578
        end
14579
 
14580
        addr_offset = 12'h00C ;
14581
 
14582
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14583
        if ( ok !== 1 )
14584
        begin
14585
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14586
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14587
            disable main;
14588
        end
14589
 
14590
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14591
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14592
 
14593
        // do a single read error terminated on WB bus
14594
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14595
 
14596
        fork
14597
        begin
14598
            PCIU_IO_READ
14599
             (
14600
                `Test_Master_1,
14601
                Target_Base_Addr_R[target_io_image],
14602
                32'hAAAA_5555,
14603
                4'h0,
14604
                1,
14605
                `Test_Target_Retry_On
14606
             );
14607
 
14608
            do_pause( 1 ) ;
14609
        end
14610
        begin
14611
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14612
 
14613
            if ( ok !== 1 )
14614
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14615
 
14616
            do_pause(3) ;
14617
 
14618
            PCIU_IO_READ
14619
             (
14620
                `Test_Master_1,
14621
                Target_Base_Addr_R[target_io_image],
14622
                32'hAAAA_5555,
14623
                4'h0,
14624
                1,
14625
                `Test_Target_Abort_On
14626
             );
14627
 
14628
            do_pause( 1 ) ;
14629
 
14630
            while ( FRAME === 0 )
14631
                @(posedge pci_clock) ;
14632
 
14633
            while ( IRDY === 0 )
14634
                @(posedge pci_clock) ;
14635
 
14636 35 mihad
            #1 ;
14637
            if ( !error_monitor_done )
14638
                disable monitor_error_event10 ;
14639 15 mihad
        end
14640
        begin:monitor_error_event10
14641 35 mihad
            error_monitor_done = 0 ;
14642 15 mihad
            @(error_event_int) ;
14643
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14644
            ok = 0 ;
14645 35 mihad
            error_monitor_done = 1 ;
14646 15 mihad
        end
14647
        join
14648
 
14649
        if ( ok )
14650
            test_ok ;
14651
 
14652 26 mihad
        @(posedge pci_clock) ;
14653
        @(posedge pci_clock) ;
14654
        @(posedge wb_clock) ;
14655
        @(posedge wb_clock) ;
14656
 
14657 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14658
        addr_offset = 12'h004 ;
14659
        config_read(addr_offset, 4'hF, read_data) ;
14660
        ok = 1 ;
14661
        if ( read_data[27] !== 1 )
14662
        begin
14663
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14664
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14665
            ok = 0 ;
14666
        end
14667
        if ( read_data[28] !== 0 )
14668
        begin
14669
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14670
            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") ;
14671
            ok = 0 ;
14672
        end
14673
        if ( read_data[29] !== 0 )
14674
        begin
14675
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14676
            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") ;
14677
            ok = 0 ;
14678
        end
14679
 
14680
        // clear statuses
14681
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14682
        if ( !ok )
14683
        begin
14684
            test_fail("write to PCI Device Status register failed") ;
14685
            $display("Couldn't write PCI Device Status register") ;
14686
            disable main ;
14687
        end
14688
 
14689
        if ( ok )
14690
            test_ok ;
14691
 
14692
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14693
 
14694
        ok = 1 ;
14695
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14696
 
14697
        config_read(addr_offset, 4'hF, read_data) ;
14698
        if (read_data[8] !== 0)
14699
        begin
14700
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14701
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14702
            ok = 0 ;
14703
        end
14704
        else
14705
            test_ok ;
14706
 
14707
        if ( ok !== 1 )
14708
        begin
14709
            config_write(addr_offset, read_data, 4'hF, ok) ;
14710
            if ( !ok )
14711
            begin
14712
                test_fail("PCI Error Control and Status register could not be written") ;
14713
                disable main ;
14714
            end
14715
        end
14716
 
14717
        test_name = "DISABLE IMAGE" ;
14718 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14719 15 mihad
        if ( ok !== 1 )
14720
        begin
14721
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14722
            test_fail("PCI Address Mask register could not be written") ;
14723
            disable main;
14724
        end
14725
 
14726
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14727
 
14728
    end
14729
end // main
14730
endtask // test_wb_error_rd
14731
 
14732
task test_target_abort ;
14733
    input [2:0]  image_num ;
14734
    reg   [11:0] pci_ctrl_offset ;
14735
    reg   [11:0] ctrl_offset ;
14736
    reg   [11:0] ba_offset ;
14737
    reg   [11:0] am_offset ;
14738
    reg   [11:0] ta_offset ;
14739
    reg   [31:0] pci_address ;
14740
    reg   [3:0]  byte_enables ;
14741
    reg          ok ;
14742 35 mihad
    reg          error_monitor_done ;
14743 15 mihad
begin:main
14744
    pci_ctrl_offset = 12'h4 ;
14745
    if (image_num === 0)
14746
    begin
14747
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14748
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14749
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14750
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14751
    end
14752
    else if (image_num === 1)
14753
    begin
14754
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14755
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14756
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14757
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14758
    end
14759
    else if (image_num === 2)
14760
    begin
14761
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14762
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14763
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14764
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14765
    end
14766
    else if (image_num === 3)
14767
    begin
14768
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14769
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14770
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14771
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14772
    end
14773
    else if (image_num === 4)
14774
    begin
14775
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14776
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14777
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14778
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14779
    end
14780
    else if (image_num === 5)
14781
    begin
14782
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14783
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14784
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14785
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14786
    end
14787
 
14788
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14789
 
14790
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14791
    if ( ok !== 1 )
14792
    begin
14793
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14794
        test_fail("PCI Base Address register could not be written") ;
14795
        disable main ;
14796
    end
14797
 
14798
    // Set Address Mask of IMAGE
14799
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14800
    if ( ok !== 1 )
14801
    begin
14802
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14803
        test_fail("PCI Address Mask register could not be written") ;
14804
        disable main ;
14805
    end
14806
 
14807
    // Set Translation Address of IMAGE
14808
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14809
    if ( ok !== 1 )
14810
    begin
14811
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14812
        test_fail("PCI Translation Address Register could not be written") ;
14813
        disable main ;
14814
    end
14815
 
14816
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14817
    if ( ok !== 1 )
14818
    begin
14819
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14820
        test_fail("PCI Image Control register could not be written") ;
14821
        disable main ;
14822
    end
14823
 
14824
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14825
 
14826
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14827
 
14828
    pci_address  = Target_Base_Addr_R[image_num] ;
14829
    byte_enables = 4'b0001 ;
14830
 
14831
    fork
14832
    begin
14833
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14834
        do_pause ( 1 ) ;
14835
    end
14836
    begin:monitor_error_event1
14837 35 mihad
        error_monitor_done = 0 ;
14838 15 mihad
        @(error_event_int) ;
14839
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14840
        ok = 0 ;
14841 35 mihad
        error_monitor_done = 1 ;
14842 15 mihad
    end
14843
    begin
14844
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14845
        @(posedge pci_clock) ;
14846 35 mihad
        #1 ;
14847
        if ( !error_monitor_done )
14848
            disable monitor_error_event1 ;
14849 15 mihad
    end
14850
    join
14851
 
14852
    if ( ok )
14853
        test_ok ;
14854
 
14855
    ok = 1 ;
14856
 
14857
    fork
14858
    begin
14859
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14860
        do_pause ( 1 ) ;
14861
    end
14862
    begin:monitor_error_event2
14863 35 mihad
        error_monitor_done = 0 ;
14864 15 mihad
        @(error_event_int) ;
14865
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14866
        ok = 0 ;
14867 35 mihad
        error_monitor_done = 1 ;
14868 15 mihad
    end
14869
    begin
14870
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14871
        @(posedge pci_clock) ;
14872 35 mihad
        #1 ;
14873
        if ( !error_monitor_done )
14874
            disable monitor_error_event2 ;
14875 15 mihad
    end
14876
    join
14877
 
14878
    if ( ok )
14879
        test_ok ;
14880
 
14881
    ok = 1 ;
14882
 
14883
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14884
    byte_enables = 4'b0011 ;
14885
 
14886
    fork
14887
    begin
14888
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14889
        do_pause ( 1 ) ;
14890
    end
14891
    begin:monitor_error_event3
14892 35 mihad
        error_monitor_done = 0 ;
14893 15 mihad
        @(error_event_int) ;
14894
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14895
        ok = 0 ;
14896 35 mihad
        error_monitor_done = 1 ;
14897 15 mihad
    end
14898
    begin
14899
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14900
        @(posedge pci_clock) ;
14901 35 mihad
        if ( !error_monitor_done )
14902
            disable monitor_error_event3 ;
14903 15 mihad
    end
14904
    join
14905
 
14906
    if ( ok )
14907
        test_ok ;
14908
 
14909
    ok = 1 ;
14910
 
14911
    byte_enables = 4'b0000 ;
14912
 
14913
    fork
14914
    begin
14915
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14916
        do_pause ( 1 ) ;
14917
    end
14918
    begin:monitor_error_event4
14919 35 mihad
        error_monitor_done = 0 ;
14920 15 mihad
        @(error_event_int) ;
14921
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14922
        ok = 0 ;
14923 35 mihad
        error_monitor_done = 1 ;
14924 15 mihad
    end
14925
    begin
14926
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14927
        @(posedge pci_clock) ;
14928 35 mihad
        #1 ;
14929
        if ( !error_monitor_done )
14930
            disable monitor_error_event4 ;
14931 15 mihad
    end
14932
    join
14933
 
14934
    if ( ok )
14935
        test_ok ;
14936
 
14937
    ok = 1 ;
14938
 
14939
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
14940
    byte_enables = 4'b0111 ;
14941
 
14942
    fork
14943
    begin
14944
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14945
        do_pause ( 1 ) ;
14946
    end
14947
    begin:monitor_error_event5
14948 35 mihad
        error_monitor_done = 0 ;
14949 15 mihad
        @(error_event_int) ;
14950
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14951
        ok = 0 ;
14952 35 mihad
        error_monitor_done = 1 ;
14953 15 mihad
    end
14954
    begin
14955
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14956
        @(posedge pci_clock) ;
14957 35 mihad
        #1 ;
14958
        if ( !error_monitor_done )
14959
            disable monitor_error_event5 ;
14960 15 mihad
    end
14961
    join
14962
 
14963
    if ( ok )
14964
        test_ok ;
14965
 
14966
    ok = 1 ;
14967
 
14968
    byte_enables = 4'b0010 ;
14969
 
14970
    fork
14971
    begin
14972
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14973
        do_pause ( 1 ) ;
14974
    end
14975
    begin:monitor_error_event6
14976 35 mihad
        error_monitor_done = 0 ;
14977 15 mihad
        @(error_event_int) ;
14978
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14979
        ok = 0 ;
14980 35 mihad
        error_monitor_done = 1 ;
14981 15 mihad
    end
14982
    begin
14983
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14984
        @(posedge pci_clock) ;
14985 35 mihad
        #1 ;
14986
        if ( !error_monitor_done )
14987
            disable monitor_error_event6 ;
14988 15 mihad
    end
14989
    join
14990
 
14991
    if ( ok )
14992
        test_ok ;
14993
 
14994
    ok = 1 ;
14995
    byte_enables = 4'b0001 ;
14996
 
14997
    fork
14998
    begin
14999
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15000
        do_pause ( 1 ) ;
15001
    end
15002
    begin:monitor_error_event7
15003 35 mihad
        error_monitor_done = 0 ;
15004 15 mihad
        @(error_event_int) ;
15005
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15006
        ok = 0 ;
15007 35 mihad
        error_monitor_done = 1 ;
15008 15 mihad
    end
15009
    begin
15010
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15011
        @(posedge pci_clock) ;
15012 35 mihad
        #1 ;
15013
        if ( !error_monitor_done )
15014
            disable monitor_error_event7 ;
15015 15 mihad
    end
15016
    join
15017
 
15018
    if ( ok )
15019
        test_ok ;
15020
 
15021
    ok = 1 ;
15022
    byte_enables = 4'b0000 ;
15023
 
15024
    fork
15025
    begin
15026
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15027
        do_pause ( 1 ) ;
15028
    end
15029
    begin:monitor_error_event8
15030 35 mihad
        error_monitor_done = 0 ;
15031 15 mihad
        @(error_event_int) ;
15032
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15033
        ok = 0 ;
15034 35 mihad
        error_monitor_done = 1 ;
15035 15 mihad
    end
15036
    begin
15037
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15038
        @(posedge pci_clock) ;
15039 35 mihad
        #1 ;
15040
        if ( !error_monitor_done )
15041
            disable monitor_error_event8 ;
15042 15 mihad
    end
15043
    join
15044
 
15045
    if ( ok )
15046
        test_ok ;
15047
 
15048
    ok = 1 ;
15049
 
15050
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15051
    byte_enables = 4'b0110 ;
15052
 
15053
    fork
15054
    begin
15055
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15056
        do_pause ( 1 ) ;
15057
    end
15058
    begin:monitor_error_event9
15059 35 mihad
        error_monitor_done = 0 ;
15060 15 mihad
        @(error_event_int) ;
15061
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15062
        ok = 0 ;
15063 35 mihad
        error_monitor_done = 1 ;
15064 15 mihad
    end
15065
    begin
15066
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15067
        @(posedge pci_clock) ;
15068 35 mihad
        #1 ;
15069
        if ( !error_monitor_done )
15070
            disable monitor_error_event9 ;
15071 15 mihad
    end
15072
    join
15073
 
15074
    if ( ok )
15075
        test_ok ;
15076
 
15077
    ok = 1 ;
15078
    fork
15079
    begin
15080
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15081
        do_pause ( 1 ) ;
15082
    end
15083
    begin:monitor_error_event10
15084 35 mihad
        error_monitor_done = 0 ;
15085 15 mihad
        @(error_event_int) ;
15086
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15087
        ok = 0 ;
15088 35 mihad
        error_monitor_done = 1 ;
15089 15 mihad
    end
15090
    begin
15091
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15092
        @(posedge pci_clock) ;
15093 35 mihad
 
15094
        #1 ;
15095
        if ( !error_monitor_done )
15096
            disable monitor_error_event10 ;
15097 15 mihad
    end
15098
    join
15099
 
15100
    if ( ok )
15101
        test_ok ;
15102
 
15103
    ok = 1 ;
15104
 
15105
    byte_enables = 4'b0001 ;
15106
 
15107
    fork
15108
    begin
15109
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15110
        do_pause ( 1 ) ;
15111
    end
15112
    begin:monitor_error_event11
15113 35 mihad
        error_monitor_done = 0 ;
15114 15 mihad
        @(error_event_int) ;
15115
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15116
        ok = 0 ;
15117 35 mihad
        error_monitor_done = 1 ;
15118 15 mihad
    end
15119
    begin
15120
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15121
        @(posedge pci_clock) ;
15122 35 mihad
        #1 ;
15123
        if ( !error_monitor_done )
15124
            disable monitor_error_event11 ;
15125 15 mihad
    end
15126
    join
15127
 
15128
    if ( ok )
15129
        test_ok ;
15130
 
15131
    ok = 1 ;
15132
 
15133
    byte_enables = 4'b0101 ;
15134
 
15135
    fork
15136
    begin
15137
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15138
        do_pause ( 1 ) ;
15139
    end
15140
    begin:monitor_error_event12
15141 35 mihad
        error_monitor_done = 0 ;
15142 15 mihad
        @(error_event_int) ;
15143
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15144
        ok = 0 ;
15145 35 mihad
        error_monitor_done = 1 ;
15146 15 mihad
    end
15147
    begin
15148
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15149
        @(posedge pci_clock) ;
15150 35 mihad
        #1 ;
15151
        if ( !error_monitor_done )
15152
            disable monitor_error_event12 ;
15153 15 mihad
    end
15154
    join
15155
 
15156
    if ( ok )
15157
        test_ok ;
15158
 
15159
    ok = 1 ;
15160
 
15161
    byte_enables = 4'b0011 ;
15162
 
15163
    fork
15164
    begin
15165
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15166
        do_pause ( 1 ) ;
15167
    end
15168
    begin:monitor_error_event13
15169 35 mihad
        error_monitor_done = 0 ;
15170 15 mihad
        @(error_event_int) ;
15171
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15172
        ok = 0 ;
15173 35 mihad
        error_monitor_done = 1 ;
15174 15 mihad
    end
15175
    begin
15176
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15177
        @(posedge pci_clock) ;
15178 35 mihad
        #1 ;
15179
        if ( !error_monitor_done )
15180
            disable monitor_error_event13 ;
15181 15 mihad
    end
15182
    join
15183
 
15184
    if ( ok )
15185
        test_ok ;
15186
 
15187
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15188
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15189
    ok = 1 ;
15190
    if ( pci_address[27] !== 1 )
15191
    begin
15192
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15193
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15194
        ok = 0 ;
15195
    end
15196
    if ( pci_address[28] !== 0 )
15197
    begin
15198
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15199
        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") ;
15200
        ok = 0 ;
15201
    end
15202
    if ( pci_address[29] !== 0 )
15203
    begin
15204
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15205
        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") ;
15206
        ok = 0 ;
15207
    end
15208
 
15209
    // clear statuses
15210
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15211
    if ( !ok )
15212
    begin
15213
        test_fail("write to PCI Device Status register failed") ;
15214
        $display("Couldn't write PCI Device Status register") ;
15215
        disable main ;
15216
    end
15217
 
15218
    if ( ok )
15219
        test_ok ;
15220
 
15221
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15222
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15223
    if ( pci_address[8] !== 0 )
15224
    begin
15225
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15226
    end
15227
    else
15228
        test_ok ;
15229
 
15230
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15231
 
15232
    test_name = "DISABLE IMAGE" ;
15233
 
15234 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15235 15 mihad
    if ( ok !== 1 )
15236
    begin
15237
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15238
        test_fail("PCI Address Mask register could not be written") ;
15239
        disable main ;
15240
    end
15241
end
15242
endtask // test_target_abort
15243
 
15244
task test_target_io_wr_rd ;
15245
    input [2:0]  image_num ;
15246
    input        translate_address ;
15247
    input [11:0] img_ctrl_offset ;
15248
    reg   [31:0] expect_address ;
15249
    reg   [31:0] pci_address ;
15250
    reg          translation ;
15251
    reg   [31:0] read_data ;
15252
    reg   [3:0]  byte_enables ;
15253
    reg          ok ;
15254
    reg          pci_ok ;
15255
    reg          wb_ok ;
15256
    integer      i ;
15257 35 mihad
    reg          error_monitor_done ;
15258 15 mihad
begin:main
15259
    `ifdef ADDR_TRAN_IMPL
15260
        translation = translate_address ;
15261
    `else
15262
        translation = 0 ;
15263
    `endif
15264
 
15265
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15266
 
15267
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15268
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15269
    if ( translation )
15270
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15271
    else
15272
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15273
 
15274
    if ( !ok )
15275
    begin
15276
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15277
        test_fail("PCI Image Control register could not be written") ;
15278
    end
15279
 
15280
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15281
    pci_address  = Target_Base_Addr_R[image_num] ;
15282
    byte_enables = 4'b0000 ;
15283
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15284
 
15285
    fork
15286
    begin
15287
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15288
        do_pause ( 1 ) ;
15289
    end
15290
    begin
15291
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15292
        if ( wb_ok !== 1 )
15293
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15294
 
15295 35 mihad
        #1 ;
15296
        if ( !error_monitor_done )
15297
            disable monitor_pci_error_1 ;
15298 15 mihad
    end
15299
    begin:monitor_pci_error_1
15300 35 mihad
        error_monitor_done = 0 ;
15301 15 mihad
        pci_ok = 1 ;
15302
        @(error_event_int) ;
15303
        pci_ok = 0 ;
15304
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15305 35 mihad
        error_monitor_done = 1 ;
15306 15 mihad
    end
15307
    join
15308
 
15309
    byte_enables = 4'b1111 ;
15310
    for ( i = 0 ; i < 4 ; i = i + 1 )
15311
    begin:loop_1
15312
        byte_enables[i] = 0 ;
15313
        if ( i > 0 )
15314
            byte_enables[i - 1] = 1 ;
15315
        fork
15316
        begin
15317
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15318
            do_pause ( 1 ) ;
15319
        end
15320
        begin
15321
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15322
            if ( wb_ok !== 1 )
15323
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15324
 
15325 35 mihad
            #1 ;
15326
            if ( !error_monitor_done )
15327
                disable monitor_pci_error_2 ;
15328 15 mihad
        end
15329
        begin:monitor_pci_error_2
15330 35 mihad
            error_monitor_done = 0 ;
15331 15 mihad
            pci_ok = 1 ;
15332
            @(error_event_int) ;
15333
            pci_ok = 0 ;
15334
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15335 35 mihad
            error_monitor_done = 1 ;
15336 15 mihad
        end
15337
        join
15338
 
15339
        if ( !pci_ok || !wb_ok )
15340
            disable loop_1 ;
15341
 
15342
        pci_address = pci_address + 1 ;
15343
        expect_address = expect_address + 1 ;
15344
    end
15345
 
15346
    if ( pci_ok && wb_ok )
15347
        test_ok ;
15348
 
15349
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15350
    pci_address  = Target_Base_Addr_R[image_num] ;
15351
    byte_enables = 4'b1100 ;
15352
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15353
 
15354
    master1_check_received_data = 1 ;
15355
    fork
15356
    begin
15357
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15358
        do_pause( 1 ) ;
15359
    end
15360
    begin
15361
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15362
        if ( wb_ok !== 1 )
15363
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15364
 
15365
        do_pause ( 2 ) ;
15366
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15367
        do_pause ( 16 ) ;
15368
 
15369 35 mihad
        #1 ;
15370
        if ( !error_monitor_done )
15371
            disable monitor_pci_error_3 ;
15372 15 mihad
    end
15373
    begin:monitor_pci_error_3
15374 35 mihad
        error_monitor_done = 0 ;
15375 15 mihad
        pci_ok = 1 ;
15376
        @(error_event_int) ;
15377
        pci_ok = 0 ;
15378
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15379 35 mihad
        error_monitor_done = 1 ;
15380 15 mihad
    end
15381
    join
15382
 
15383
    if ( !pci_ok || !wb_ok )
15384
    begin
15385
        disable main ;
15386
    end
15387
 
15388
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15389
    byte_enables = 4'b0011 ;
15390
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15391
 
15392
    master1_check_received_data = 1 ;
15393
    fork
15394
    begin
15395
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15396
        do_pause( 1 ) ;
15397
    end
15398
    begin
15399
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15400
        if ( wb_ok !== 1 )
15401
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15402
 
15403
        do_pause ( 2 ) ;
15404
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15405
        do_pause ( 16 ) ;
15406
 
15407 35 mihad
        #1 ;
15408
        if ( !error_monitor_done )
15409
            disable monitor_pci_error_4 ;
15410 15 mihad
    end
15411
    begin:monitor_pci_error_4
15412 35 mihad
        error_monitor_done = 0 ;
15413 15 mihad
        pci_ok = 1 ;
15414
        @(error_event_int) ;
15415
        pci_ok = 0 ;
15416
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15417 35 mihad
        error_monitor_done = 1 ;
15418 15 mihad
    end
15419
    join
15420
 
15421
    if ( !pci_ok || !wb_ok )
15422
    begin
15423
        disable main ;
15424
    end
15425
 
15426
    pci_address  = Target_Base_Addr_R[image_num] ;
15427
    byte_enables = 4'b0000 ;
15428
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15429
 
15430
    master1_check_received_data = 1 ;
15431
    fork
15432
    begin
15433
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15434
        do_pause( 1 ) ;
15435
    end
15436
    begin
15437
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15438
        if ( wb_ok !== 1 )
15439
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15440
 
15441
        do_pause ( 2 ) ;
15442
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15443
        do_pause ( 16 ) ;
15444
 
15445 35 mihad
        #1 ;
15446
        if ( !error_monitor_done )
15447
            disable monitor_pci_error_5 ;
15448 15 mihad
    end
15449
    begin:monitor_pci_error_5
15450 35 mihad
        error_monitor_done = 0 ;
15451 15 mihad
        pci_ok = 1 ;
15452
        @(error_event_int) ;
15453
        pci_ok = 0 ;
15454
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15455 35 mihad
        error_monitor_done = 1 ;
15456 15 mihad
    end
15457
    join
15458
 
15459
    if ( pci_ok && wb_ok )
15460
        test_ok ;
15461
end
15462
endtask // test_target_io_wr_rd
15463
 
15464
task test_target_io_err_wr ;
15465
    input [2:0]  image_num ;
15466
    input        translate_address ;
15467
    input [11:0] img_ctrl_offset ;
15468
    input        enable_error_report ;
15469
    input        enable_error_interrupt ;
15470
 
15471
    reg   [31:0] expect_address ;
15472
    reg   [31:0] pci_address ;
15473
    reg          translation ;
15474
    reg   [31:0] read_data ;
15475
    reg   [3:0]  byte_enables ;
15476
    reg          ok ;
15477
    reg          pci_ok ;
15478
    reg          wb_ok ;
15479
    integer      i ;
15480
    reg   [11:0] offset ;
15481 35 mihad
    reg          error_monitor_done ;
15482 15 mihad
begin:main
15483
    `ifdef ADDR_TRAN_IMPL
15484
        translation = translate_address ;
15485
    `else
15486
        translation = 0 ;
15487
    `endif
15488
 
15489
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15490
 
15491
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15492
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15493
    if ( translation )
15494
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15495
    else
15496
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15497
 
15498
    if ( !ok )
15499
    begin
15500
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15501
        test_fail("PCI Image Control register could not be written") ;
15502
    end
15503
 
15504
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15505
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15506
    if ( enable_error_report )
15507
    begin
15508
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15509
        if ( !ok )
15510
        begin
15511
            test_fail("PCI Error Control and Status register could not be written") ;
15512
            disable main ;
15513
        end
15514
    end
15515
    else
15516
    begin
15517
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15518
        if ( !ok )
15519
        begin
15520
            test_fail("PCI Error Control and Status register could not be written") ;
15521
            disable main ;
15522
        end
15523
    end
15524
 
15525
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15526
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15527
    if ( enable_error_interrupt )
15528
    begin
15529
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15530
        if ( !ok )
15531
        begin
15532
            test_fail("Interrupt Control register could not be written") ;
15533
            disable main ;
15534
        end
15535
    end
15536
    else
15537
    begin
15538
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15539
        if ( !ok )
15540
        begin
15541
            test_fail("Interrupt Control register could not be written") ;
15542
            disable main ;
15543
        end
15544
    end
15545
 
15546
    pci_address  = Target_Base_Addr_R[image_num] ;
15547
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15548
 
15549
    byte_enables = 4'b1111 ;
15550
 
15551
    for ( i = 0 ; i < 4 ; i = i + 1 )
15552
    begin:loop_1
15553
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15554
        byte_enables[i] = 0 ;
15555
        if ( i > 0 )
15556
            byte_enables[i - 1] = 1 ;
15557
 
15558
        fork
15559
        begin
15560
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15561
            do_pause ( 1 ) ;
15562
        end
15563
        begin
15564
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15565
            if ( wb_ok !== 1 )
15566
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15567
 
15568 35 mihad
            #1 ;
15569
            if ( !error_monitor_done )
15570
                disable monitor_pci_error_2 ;
15571 15 mihad
        end
15572
        begin:monitor_pci_error_2
15573 35 mihad
            error_monitor_done = 0 ;
15574 15 mihad
            pci_ok = 1 ;
15575
            @(error_event_int) ;
15576
            pci_ok = 0 ;
15577
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15578 35 mihad
            error_monitor_done = 1 ;
15579 15 mihad
        end
15580
        join
15581
 
15582
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15583
        `ifdef HOST
15584
 
15585
            repeat ( 4 )
15586
                @( posedge wb_clock ) ;
15587
 
15588
            if ( enable_error_interrupt && enable_error_report )
15589
            begin
15590
                if ( INT_O !== 1 )
15591
                begin
15592
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15593
                end
15594
            end
15595
            else
15596
            begin
15597
                if ( INT_O !== 0 )
15598
                begin
15599
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15600
                end
15601
            end
15602
        `else
15603
            repeat ( 4 )
15604
                @( posedge pci_clock ) ;
15605
 
15606
            if ( enable_error_interrupt && enable_error_report )
15607
            begin
15608
                if ( INTA !== 0 )
15609
                begin
15610
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15611
                end
15612
            end
15613
            else
15614
            begin
15615
                if ( INTA !== 1 )
15616
                begin
15617
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15618
                end
15619
            end
15620
        `endif
15621
 
15622
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15623
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15624
        config_read( offset, 4'hF, read_data ) ;
15625
        ok = 1 ;
15626
        if ( enable_error_report )
15627
        begin
15628
            if ( read_data[8] !== 1 )
15629
            begin
15630
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15631
                ok = 0 ;
15632
            end
15633
 
15634
            if ( read_data[9] !== 0 )
15635
            begin
15636
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15637
                ok = 0 ;
15638
            end
15639
 
15640
            if ( read_data[31:28] !== byte_enables )
15641
            begin
15642
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15643
                ok = 0 ;
15644
            end
15645
 
15646
            if ( read_data[27:24] !== `BC_IO_WRITE )
15647
            begin
15648
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15649
                ok = 0 ;
15650
            end
15651
 
15652
            if ( ok )
15653
                test_ok ;
15654
 
15655
            test_name = "CLEAR ERROR STATUS" ;
15656
            config_write( offset, read_data, 4'hF, ok ) ;
15657
            if ( !ok )
15658
                test_fail("PCI Error Control and Status register could not be written") ;
15659
 
15660
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15661
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15662
            config_read ( offset, 4'hf, read_data ) ;
15663
 
15664
            if ( read_data !== expect_address )
15665
            begin
15666
                test_fail("value in Erroneous Address register was incorrect") ;
15667
                ok = 0 ;
15668
            end
15669
 
15670
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15671
            config_read ( offset, 4'hf, read_data ) ;
15672
 
15673
            if ( read_data !== 32'hAAAA_AAAA )
15674
            begin
15675
                test_fail("value in Erroneous Data register was incorrect") ;
15676
                ok = 0 ;
15677
            end
15678
 
15679
            if ( ok )
15680
                test_ok ;
15681
 
15682
        end
15683
        else
15684
        begin
15685
            if ( read_data[8] !== 0 )
15686
            begin
15687
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15688
                ok = 0 ;
15689
            end
15690
            else
15691
                test_ok ;
15692
        end
15693
 
15694
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15695
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15696
        ok = 1 ;
15697
 
15698
        config_read ( offset, 4'hF, read_data ) ;
15699
        if ( enable_error_report && enable_error_interrupt )
15700
        begin
15701
            if ( read_data[2] !== 1 )
15702
            begin
15703
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15704
                ok = 0 ;
15705
            end
15706
 
15707
            test_name = "CLEARING INTERRUPT STATUS" ;
15708
            config_write( offset, read_data, 4'hF, ok ) ;
15709
            if ( !ok )
15710
                test_fail("Interrupt Status register could not be written") ;
15711
        end
15712
        else
15713
        begin
15714
            if ( read_data[2] !== 0 )
15715
            begin
15716
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15717
                ok = 0 ;
15718
            end
15719
        end
15720
 
15721
        if ( ok )
15722
            test_ok ;
15723
 
15724
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15725
        `ifdef HOST
15726
 
15727
            repeat ( 4 )
15728
                @( posedge wb_clock ) ;
15729
 
15730
            if ( INT_O !== 0 )
15731
            begin
15732
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15733
            end
15734
            else
15735
                test_ok ;
15736
 
15737
        `else
15738
            repeat ( 4 )
15739
                @( posedge pci_clock ) ;
15740
 
15741
            if ( INTA !== 1 )
15742
            begin
15743
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15744
            end
15745
            else
15746
                test_ok ;
15747
 
15748
        `endif
15749
 
15750
        pci_address = pci_address + 1 ;
15751
        expect_address = expect_address + 1 ;
15752
    end
15753
 
15754
end
15755
endtask // test_target_io_err_wr
15756
 
15757
task test_pci_image ;
15758
    input [2:0]  image_num ;
15759
    reg   [11:0] pci_ctrl_offset ;
15760
    reg   [11:0] ctrl_offset ;
15761
    reg   [11:0] ba_offset ;
15762
    reg   [11:0] am_offset ;
15763
    reg   [11:0] ta_offset ;
15764
    reg   [7:0]  cache_lsize ;
15765
    reg          ok ;
15766
    reg          test_io ;
15767
    reg          test_mem ;
15768
begin
15769
    pci_ctrl_offset = 12'h4 ;
15770
    if (image_num === 0)
15771
    begin
15772
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15773
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15774
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15775
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15776
    end
15777
    else if (image_num === 1)
15778
    begin
15779
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15780
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15781
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15782
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15783
    end
15784
    else if (image_num === 2)
15785
    begin
15786
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15787
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15788
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15789
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15790
    end
15791
    else if (image_num === 3)
15792
    begin
15793
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15794
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15795
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15796
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15797
    end
15798
    else if (image_num === 4)
15799
    begin
15800
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15801
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15802
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15803
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15804
    end
15805
    else if (image_num === 5)
15806
    begin
15807
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15808
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15809
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15810
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15811
    end
15812
 
15813
    `ifdef HOST
15814
        test_io  = 1 ;
15815
        test_mem = 1 ;
15816
    `else
15817
        if (image_num == 1)
15818
            test_io = `PCI_BA1_MEM_IO ;
15819
        else if ( image_num == 2 )
15820
            test_io = `PCI_BA2_MEM_IO ;
15821
        else if ( image_num == 3 )
15822
            test_io = `PCI_BA3_MEM_IO ;
15823
        else if ( image_num == 4 )
15824
            test_io = `PCI_BA4_MEM_IO ;
15825
        else if ( image_num == 5 )
15826
            test_io = `PCI_BA5_MEM_IO ;
15827
 
15828
        test_mem = !test_io ;
15829
    `endif
15830
 
15831
    $display(" ");
15832
    $display("########################################################################") ;
15833
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15834
    test_name = "PCI IMAGE SETTINGS" ;
15835
 
15836
    // Set Base Address of IMAGE
15837
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15838
    if ( ok !== 1 )
15839
    begin
15840
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15841
        test_fail("PCI Base Address register could not be written") ;
15842
    end
15843
 
15844
    // Set Address Mask of IMAGE
15845
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15846
    if ( ok !== 1 )
15847
    begin
15848
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15849
        test_fail("PCI Address Mask register could not be written") ;
15850
    end
15851
 
15852
    // Set Translation Address of IMAGE
15853
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15854
    if ( ok !== 1 )
15855
    begin
15856
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15857
        test_fail("PCI Translation Address register could not be written") ;
15858
    end
15859
 
15860
// Following are defines for byte enable signals !
15861
//      Byte Masks
15862
//      `Test_Byte_0                            (4'b1110)
15863
//      `Test_Byte_1                            (4'b1101)
15864
//      `Test_Byte_2                            (4'b1011)
15865
//      `Test_Byte_3                            (4'b0111)
15866
//      `Test_Half_0                            (4'b1100)
15867
//      `Test_Half_1                            (4'b0011)
15868
//      `Test_All_Bytes                         (4'b0000)
15869
 
15870
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15871
    // Set Cache Line Size
15872
    cache_lsize = 8'h4 ;
15873
 
15874
    $display(" ");
15875
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15876
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15877
    if ( ok !== 1 )
15878
    begin
15879
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15880
        test_fail("PCI Device Control and Status register could not be written") ;
15881
    end
15882
 
15883
    if (test_mem)
15884
    begin
15885
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15886
        // Task test_normal_wr_rd has the following parameters:
15887
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15888
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15889
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15890
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15891
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15892
 
15893
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15894
        // Set Cache Line Size
15895
        cache_lsize = 8'h4 ;
15896
 
15897
        $display(" ");
15898
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15899
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15900
        if ( ok !== 1 )
15901
        begin
15902
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15903
            test_fail("Cache Line Size register could not be written" ) ;
15904
        end
15905
 
15906
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15907
        // Task test_normal_wr_rd has the following parameters:
15908
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15909
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15910
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15911
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
15912
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
15913
 
15914
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15915
        // Set Cache Line Size
15916
        cache_lsize = 8'h8 ;
15917
 
15918
        $display(" ");
15919
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15920
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15921
        if ( ok !== 1 )
15922
        begin
15923
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15924
            test_fail("Cache Line Size register could not be written" ) ;
15925
        end
15926
 
15927
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
15928
        // Task test_normal_wr_rd has the following parameters:
15929
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15930
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15931
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15932
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
15933
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15934
 
15935
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15936
        // Set Cache Line Size
15937
        cache_lsize = 8'h4 ;
15938
 
15939
        $display(" ");
15940
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15941
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15942
        if ( ok !== 1 )
15943
        begin
15944
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15945
            test_fail("Cache Line Size register could not be written" ) ;
15946
        end
15947
 
15948
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
15949
        // Task test_normal_wr_rd has the following parameters:
15950
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15951
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15952
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15953
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
15954
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15955
 
15956
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15957
        $display(" ");
15958
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
15959
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15960
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15961
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
15962
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
15963
 
15964
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15965
        $display(" ");
15966
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
15967
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15968
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15969
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
15970
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
15971
 
15972
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15973
        $display(" ");
15974
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
15975
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15976
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15977
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
15978
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
15979
 
15980
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
15981
        $display(" ");
15982
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
15983
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15984
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15985
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
15986
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
15987
    end
15988
 
15989
    if ( test_io )
15990
    begin
15991
        test_name = "PCI IMAGE SETTINGS" ;
15992
 
15993
        // Set Base Address of IMAGE
15994
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
15995
        if ( ok !== 1 )
15996
        begin
15997
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15998
            test_fail("PCI Base Address register could not be written") ;
15999
        end
16000
 
16001
        // Set Address Mask of IMAGE
16002
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16003
        if ( ok !== 1 )
16004
        begin
16005
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16006
            test_fail("PCI Address Mask register could not be written") ;
16007
        end
16008
 
16009
        // Set Translation Address of IMAGE
16010
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16011
        if ( ok !== 1 )
16012
        begin
16013
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16014
            test_fail("PCI Translation Address register could not be written") ;
16015
        end
16016
 
16017
        // Set Cache Line Size
16018
        cache_lsize = 8'h4 ;
16019
 
16020
        $display(" ");
16021
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16022
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16023
        if ( ok !== 1 )
16024
        begin
16025
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16026
            test_fail("Cache Line Size register could not be written" ) ;
16027
        end
16028
 
16029
        test_target_io_wr_rd
16030
        (
16031
            image_num,    // image number
16032
            0,            // test with address translation
16033
            ctrl_offset   // image control register offset
16034
        ) ;
16035
 
16036
        test_target_io_wr_rd
16037
        (
16038
            image_num,    // image number
16039
            1,            // test with address translation
16040
            ctrl_offset   // image control register offset
16041
        ) ;
16042
 
16043
        test_target_io_err_wr
16044
        (
16045
            image_num,      // image number
16046
            0,              // address translation on/off
16047
            ctrl_offset,    // image control register offset
16048
            0,              // enable error reporting
16049
 
16050
        ) ;
16051
 
16052
        test_target_io_err_wr
16053
        (
16054
            image_num,      // image number
16055
            1,              // address translation on/off
16056
            ctrl_offset,    // image control register offset
16057
            0,              // enable error reporting
16058
            1               // enable error interrupts
16059
        ) ;
16060
 
16061
        test_target_io_err_wr
16062
        (
16063
            image_num,      // image number
16064
            0,              // address translation on/off
16065
            ctrl_offset,    // image control register offset
16066
            1,              // enable error reporting
16067
 
16068
        ) ;
16069
 
16070
        test_target_io_err_wr
16071
        (
16072
            image_num,      // image number
16073
            1,              // address translation on/off
16074
            ctrl_offset,    // image control register offset
16075
            1,              // enable error reporting
16076
            1               // enable error interrupts
16077
        ) ;
16078
    end
16079
 
16080
    // Test master abort with NON supported commands
16081
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16082
 
16083
    // disable the image
16084 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16085 15 mihad
end
16086
endtask //test_pci_image
16087
 
16088
task target_fast_back_to_back ;
16089
    reg   [11:0] pci_ctrl_offset ;
16090
    reg   [11:0] ctrl_offset ;
16091
    reg   [11:0] ba_offset ;
16092
    reg   [11:0] am_offset ;
16093
    reg   [11:0] ta_offset ;
16094
    reg   [11:0] cls_offset ;
16095
    reg          do_mem_fb2b ;
16096
    reg          do_io_fb2b ;
16097
    reg          ok ;
16098
begin:main
16099
 
16100
    if ( target_mem_image !== -1 )
16101
    begin
16102
        do_mem_fb2b = 1 ;
16103
 
16104
        if (target_mem_image === 1)
16105
        begin
16106
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16107
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16108
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16109
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16110
        end
16111
        else if (target_mem_image === 2)
16112
        begin
16113
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16114
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16115
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16116
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16117
        end
16118
        else if (target_mem_image === 3)
16119
        begin
16120
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16121
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16122
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16123
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16124
        end
16125
        else if (target_mem_image === 4)
16126
        begin
16127
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16128
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16129
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16130
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16131
        end
16132
        else if (target_mem_image === 5)
16133
        begin
16134
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16135
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16136
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16137
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16138
        end
16139
    end
16140
    else
16141
        do_mem_fb2b = 0 ;
16142
 
16143
    pci_ctrl_offset = 12'h4 ;
16144
    cls_offset      = 12'h00C ;
16145
 
16146
    if ( do_mem_fb2b )
16147
    begin
16148
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16149
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16150
        if ( ok !== 1 )
16151
        begin
16152
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16153
            test_fail("PCI Base Address register could not be written") ;
16154
            disable main ;
16155
        end
16156
 
16157
        // Set Address Mask of IMAGE
16158
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16159
        if ( ok !== 1 )
16160
        begin
16161
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16162
            test_fail("PCI Address Mask register could not be written") ;
16163
            disable main ;
16164
        end
16165
 
16166
        // Set Translation Address of IMAGE
16167
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16168
        if ( ok !== 1 )
16169
        begin
16170
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16171
            test_fail("PCI Translation Address Register could not be written") ;
16172
            disable main ;
16173
        end
16174
 
16175
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16176
        if ( ok !== 1 )
16177
        begin
16178
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16179
            test_fail("PCI Image Control register could not be written") ;
16180
            disable main ;
16181
        end
16182
 
16183
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16184
        if ( ok !== 1 )
16185
        begin
16186
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16187
            test_fail("Cache Line Size register could not be written") ;
16188
            disable main ;
16189
        end
16190
 
16191
        // enable master 1 fast_b2b
16192 45 mihad
        configuration_cycle_write(0,                        // bus number
16193
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16194
                                  0,                        // function number
16195
                                  1,                        // register number
16196
                                  0,                        // type of configuration cycle
16197
                                  4'b1111,                  // byte enables
16198
                                  32'hFFFF_FFFF             // data
16199 15 mihad
                                 ) ;
16200
 
16201
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16202
 
16203
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16204
        fork
16205
        begin
16206
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16207
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16208
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16209
                  0, `Test_One_Zero_Target_WS,
16210
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16211
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16212
 
16213
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16214
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16215
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16216
                  0, `Test_One_Zero_Target_WS,
16217
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16218
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16219
            do_pause(5) ;
16220
 
16221
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16222
        end
16223
        begin:wb_monitor1
16224
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16225
            if ( ok !== 1 )
16226
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16227
 
16228
            disable monitor_error_event1 ;
16229
        end
16230
        begin:monitor_error_event1
16231
            @(error_event_int) ;
16232
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16233
            ok = 0 ;
16234
            disable wb_monitor1 ;
16235
        end
16236
        join
16237
 
16238
        if ( ok )
16239
            test_ok ;
16240
 
16241
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16242
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16243
        fork
16244
        begin
16245
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16246
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16247
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16248
                  0, `Test_One_Zero_Target_WS,
16249
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16250
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16251
 
16252
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16253
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16254
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16255
                  0, `Test_One_Zero_Target_WS,
16256
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16257
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16258
            do_pause(5) ;
16259
 
16260
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16261
 
16262
        end
16263
        begin:wb_monitor2
16264
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16265
            if ( ok !== 1 )
16266
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16267
            else
16268
            begin
16269
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16270
                if ( ok !== 1 )
16271
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16272
            end
16273
 
16274
            disable monitor_error_event2 ;
16275
        end
16276
        begin:monitor_error_event2
16277
            @(error_event_int) ;
16278
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16279
            ok = 0 ;
16280
            disable wb_monitor2 ;
16281
        end
16282
        join
16283
 
16284
        if ( ok )
16285
            test_ok ;
16286
 
16287
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16288
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16289
        fork
16290
        begin
16291
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16292
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16293
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16294
                  0, `Test_One_Zero_Target_WS,
16295
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16296
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16297
 
16298
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16299
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16300
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16301
                  0, `Test_One_Zero_Target_WS,
16302
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16303
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16304
            do_pause(5) ;
16305
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16306
 
16307
        end
16308
        begin:wb_monitor3
16309
            fork
16310
            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
            begin
16316
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16317
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16318
                if ( ok !== 1 )
16319
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16320
            end
16321
            join
16322
 
16323
            if ( ok )
16324
            begin
16325
                fork
16326
                begin
16327
                    do_pause(3) ;
16328
 
16329
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16330
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16331
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16332
                        0, `Test_One_Zero_Target_WS,
16333
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16334
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16335
 
16336
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16337
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16338
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16339
                            0, `Test_One_Zero_Target_WS,
16340
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16341
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16342
 
16343
                    do_pause(1) ;
16344
                end
16345
                begin
16346
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16347
                    if ( ok !== 1 )
16348
                    begin
16349
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16350
                        disable monitor_error_event3 ;
16351
                    end
16352
                    else
16353
                    begin
16354
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16355
                        if ( ok !== 1 )
16356
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16357
                    end
16358
                end
16359 26 mihad
                begin
16360
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16361
                        if ( ok !== 1 )
16362
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16363
                end
16364 15 mihad
                join
16365
            end
16366
            disable monitor_error_event3 ;
16367
        end
16368
        begin:monitor_error_event3
16369
            @(error_event_int) ;
16370
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16371
            ok = 0 ;
16372
            disable wb_monitor3 ;
16373
        end
16374
        join
16375
 
16376
        if ( ok )
16377
            test_ok ;
16378
 
16379
        test_name = "DISABLING MEM IMAGE" ;
16380 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16381 15 mihad
        if ( ok !== 1 )
16382
        begin
16383
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16384
            test_fail("PCI Address Mask register could not be written") ;
16385
            disable main ;
16386
        end
16387
    end
16388
 
16389
    if ( target_io_image !== -1 )
16390
    begin
16391
        do_io_fb2b = 1 ;
16392
 
16393
        if (target_io_image === 1)
16394
        begin
16395
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16396
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16397
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16398
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16399
        end
16400
        else if (target_io_image === 2)
16401
        begin
16402
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16403
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16404
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16405
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16406
        end
16407
        else if (target_io_image === 3)
16408
        begin
16409
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16410
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16411
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16412
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16413
        end
16414
        else if (target_io_image === 4)
16415
        begin
16416
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16417
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16418
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16419
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16420
        end
16421
        else if (target_io_image === 5)
16422
        begin
16423
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16424
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16425
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16426
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16427
        end
16428
    end
16429
    else
16430
        do_io_fb2b = 0 ;
16431
 
16432
    if ( do_io_fb2b )
16433
    begin
16434
 
16435
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16436
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16437
        if ( ok !== 1 )
16438
        begin
16439
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16440
            test_fail("PCI Base Address register could not be written") ;
16441
            disable main ;
16442
        end
16443
 
16444
        // Set Address Mask of IMAGE
16445
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16446
        if ( ok !== 1 )
16447
        begin
16448
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16449
            test_fail("PCI Address Mask register could not be written") ;
16450
            disable main ;
16451
        end
16452
 
16453
        // Set Translation Address of IMAGE
16454
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16455
        if ( ok !== 1 )
16456
        begin
16457
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16458
            test_fail("PCI Translation Address Register could not be written") ;
16459
            disable main ;
16460
        end
16461
 
16462
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16463
        if ( ok !== 1 )
16464
        begin
16465
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16466
            test_fail("PCI Image Control register could not be written") ;
16467
            disable main ;
16468
        end
16469
 
16470
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16471
        if ( ok !== 1 )
16472
        begin
16473
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16474
            test_fail("Cache Line Size register could not be written") ;
16475
            disable main ;
16476
        end
16477
 
16478
        // enable master 1 fast_b2b
16479 45 mihad
        configuration_cycle_write(0,                        // bus number
16480
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16481
                                  0,                        // function number
16482
                                  1,                        // register number
16483
                                  0,                        // type of configuration cycle
16484
                                  4'b1111,                  // byte enables
16485
                                  32'hFFFF_FFFF             // data
16486 15 mihad
                                 ) ;
16487
 
16488
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16489
 
16490
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16491
        fork
16492
        begin
16493
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16494
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16495
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16496
                  0, `Test_One_Zero_Target_WS,
16497
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16498
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16499
 
16500
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16501
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16502
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16503
                  0, `Test_One_Zero_Target_WS,
16504
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16505
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16506
            do_pause(5) ;
16507
 
16508
        end
16509
        begin:wb_monitor4
16510
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16511
            if ( ok !== 1 )
16512
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16513
 
16514
            if ( ok )
16515
            begin
16516
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16517
                if ( ok !== 1 )
16518
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16519
            end
16520
 
16521
            disable monitor_error_event4 ;
16522
        end
16523
        begin:monitor_error_event4
16524
            @(error_event_int) ;
16525
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16526
            ok = 0 ;
16527
            disable wb_monitor4 ;
16528
        end
16529
        join
16530
 
16531
        if ( ok )
16532
            test_ok ;
16533
 
16534
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16535
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16536
        fork
16537
        begin
16538
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16539
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16540
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16541
                  0, `Test_One_Zero_Target_WS,
16542
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16543
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16544
 
16545
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16546
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16547
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16548
                  0, `Test_One_Zero_Target_WS,
16549
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16550
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16551
            do_pause(5) ;
16552
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16553
        end
16554
        begin:wb_monitor5
16555
            fork
16556
            begin
16557
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16558
                if ( ok !== 1 )
16559
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16560
            end
16561
            begin
16562
                wb_transaction_stop( 1 ) ;
16563
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16564
                if ( ok !== 1 )
16565
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16566
            end
16567
            join
16568
 
16569
            if ( ok )
16570
            begin
16571
                fork
16572
                begin
16573
                    do_pause(3) ;
16574
 
16575
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16576
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16577
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16578
                            0, `Test_One_Zero_Target_WS,
16579
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16580
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16581
 
16582
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16583
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16584
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16585
                            0, `Test_One_Zero_Target_WS,
16586
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16587
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16588
 
16589
                    do_pause(1) ;
16590
                end
16591
                begin
16592
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16593
                    if ( ok !== 1 )
16594
                    begin
16595
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16596
                        disable monitor_error_event5 ;
16597
                    end
16598
                    else
16599
                    begin
16600
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16601
                        if ( ok !== 1 )
16602
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16603
                    end
16604
                end
16605
                join
16606
            end
16607
            disable monitor_error_event5 ;
16608
        end
16609
        begin:monitor_error_event5
16610
            @(error_event_int) ;
16611
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16612
            ok = 0 ;
16613
            disable wb_monitor5 ;
16614
        end
16615
        join
16616
 
16617
        if ( ok )
16618
            test_ok ;
16619
 
16620
        test_name = "DISABLING IO IMAGE" ;
16621 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16622 15 mihad
        if ( ok !== 1 )
16623
        begin
16624
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16625
            test_fail("PCI Address Mask register could not be written") ;
16626
            disable main ;
16627
        end
16628
    end
16629
 
16630
end
16631
endtask //target_fast_back_to_back
16632
 
16633
task target_disconnects ;
16634
    reg   [11:0] pci_ctrl_offset ;
16635
    reg   [11:0] ctrl_offset ;
16636
    reg   [11:0] ba_offset ;
16637
    reg   [11:0] am_offset ;
16638
    reg   [11:0] ta_offset ;
16639
    reg   [11:0] cls_offset ;
16640
    reg          pci_ok ;
16641
    reg          wb_ok ;
16642
    reg          ok ;
16643
    reg   [31:0] pci_address ;
16644
    reg   [31:0] data ;
16645
    reg   [3:0]  byte_enables ;
16646
    reg   [9:0]  expect_length ;
16647
 
16648
    reg          do_mem_disconnects ;
16649
    reg          do_io_disconnects ;
16650 35 mihad
    reg          error_monitor_done ;
16651 15 mihad
begin:main
16652
    if ( target_mem_image !== -1 )
16653
    begin
16654
        do_mem_disconnects = 1 ;
16655
 
16656
        if (target_mem_image === 1)
16657
        begin
16658
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16659
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16660
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16661
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16662
        end
16663
        else if (target_mem_image === 2)
16664
        begin
16665
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16666
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16667
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16668
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16669
        end
16670
        else if (target_mem_image === 3)
16671
        begin
16672
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16673
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16674
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16675
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16676
        end
16677
        else if (target_mem_image === 4)
16678
        begin
16679
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16680
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16681
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16682
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16683
        end
16684
        else if (target_mem_image === 5)
16685
        begin
16686
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16687
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16688
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16689
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16690
        end
16691
    end
16692
    else
16693
        do_mem_disconnects = 0 ;
16694
 
16695
    pci_ctrl_offset = 12'h4 ;
16696
    cls_offset = 12'h00C ;
16697
 
16698
    master1_check_received_data = 0 ;
16699
    master2_check_received_data = 0 ;
16700
 
16701
    `ifdef HOST
16702
        `ifdef NO_CNF_IMAGE
16703
        `else
16704
            `define TEST_BURST_CONFIG_READ
16705
        `endif
16706
    `else
16707
        `define TEST_BURST_CONFIG_READ
16708
        `define TEST_BURST_CONFIG_WRITE
16709
    `endif
16710
 
16711
    `ifdef TEST_BURST_CONFIG_WRITE
16712
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16713
 
16714
        data = 32'h0000_08_08 ;
16715
 
16716 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16717 15 mihad
        byte_enables = 4'b0000 ;
16718
 
16719
        fork
16720
        begin
16721
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16722
                    PCI_COMMAND_MEMORY_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 ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16731
                    PCI_COMMAND_MEMORY_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
            do_pause( 1 ) ;
16738
            while ( FRAME !== 1 || IRDY !== 1 )
16739
                @(posedge pci_clock) ;
16740
 
16741 35 mihad
            #1 ;
16742
            if ( !error_monitor_done )
16743
                disable monitor_error_event1 ;
16744 15 mihad
        end
16745
        begin:monitor_error_event1
16746 35 mihad
            error_monitor_done = 0 ;
16747 15 mihad
            ok = 1 ;
16748
            @(error_event_int) ;
16749
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16750
            ok = 0 ;
16751 35 mihad
            error_monitor_done = 1 ;
16752 15 mihad
        end
16753
        join
16754
 
16755
        config_read(pci_address, 4'hF, data) ;
16756
        if ( data [15:0] !== 16'h04_04 )
16757
        begin
16758
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16759
        end
16760
        else if ( ok )
16761
            test_ok ;
16762
 
16763 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16764
 
16765
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16766 15 mihad
        data         = 32'h0000_0808 ;
16767
        byte_enables = 4'h0 ;
16768
        fork
16769
        begin
16770
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16771
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16772
                    byte_enables,
16773
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16774
                    8'h0_0, `Test_One_Zero_Target_WS,
16775
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16776
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16777
 
16778
            data = 32'h0000_04_04 ;
16779
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16780
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16781
                    byte_enables,
16782
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16783
                    8'h0_0, `Test_One_Zero_Target_WS,
16784
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16785
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16786
 
16787
            do_pause( 1 ) ;
16788
            while ( FRAME !== 1 || IRDY !== 1 )
16789
                @(posedge pci_clock) ;
16790
 
16791 35 mihad
            #1 ;
16792
            if ( !error_monitor_done )
16793
                disable monitor_error_event2 ;
16794 15 mihad
        end
16795
        begin:monitor_error_event2
16796 35 mihad
            error_monitor_done = 0 ;
16797 15 mihad
            ok = 1 ;
16798
            @(error_event_int) ;
16799
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16800
            ok = 0 ;
16801 35 mihad
            error_monitor_done = 1 ;
16802 15 mihad
        end
16803
        join
16804
 
16805
        config_read(pci_address, 4'hF, data) ;
16806
        if ( data [15:0] !== 16'h04_04 )
16807
        begin
16808
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16809
        end
16810
        else if ( ok )
16811
            test_ok ;
16812
    `endif
16813
 
16814
    `ifdef TEST_BURST_CONFIG_READ
16815
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16816
 
16817
        data = 32'h0000_04_04 ;
16818
 
16819 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16820 15 mihad
        byte_enables = 4'b0000 ;
16821
 
16822
        fork
16823
        begin
16824
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16825
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16826
                    byte_enables,
16827
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16828
                    8'h0_0, `Test_One_Zero_Target_WS,
16829
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16830
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16831
            do_pause( 1 ) ;
16832
 
16833
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16834
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16835
                    byte_enables,
16836
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16837
                    8'h0_0, `Test_One_Zero_Target_WS,
16838
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16839
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16840
            do_pause( 1 ) ;
16841
 
16842
            while ( FRAME !== 1 || IRDY !== 1 )
16843
                @(posedge pci_clock) ;
16844
 
16845 35 mihad
            if ( !error_monitor_done )
16846
                disable monitor_error_event3 ;
16847 15 mihad
        end
16848
        begin:monitor_error_event3
16849 35 mihad
            error_monitor_done = 0 ;
16850 15 mihad
            ok = 1 ;
16851
            @(error_event_int) ;
16852
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16853
            ok = 0 ;
16854 35 mihad
            error_monitor_done = 1 ;
16855 15 mihad
        end
16856
        join
16857
 
16858
        if ( ok )
16859
            test_ok ;
16860
 
16861 45 mihad
 
16862
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16863
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16864 15 mihad
        fork
16865
        begin
16866
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16867
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16868
                    byte_enables,
16869
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16870
                    8'h0_0, `Test_One_Zero_Target_WS,
16871
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16872
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16873
            do_pause( 1 ) ;
16874
 
16875
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16876
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16877
                    byte_enables,
16878
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16879
                    8'h0_0, `Test_One_Zero_Target_WS,
16880
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16881
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16882
            do_pause( 1 ) ;
16883
 
16884
            while ( FRAME !== 1 || IRDY !== 1 )
16885
                @(posedge pci_clock) ;
16886
 
16887 35 mihad
            #1 ;
16888
            if ( !error_monitor_done )
16889
                disable monitor_error_event4 ;
16890 15 mihad
        end
16891
        begin:monitor_error_event4
16892 35 mihad
            error_monitor_done = 0 ;
16893 15 mihad
            ok = 1 ;
16894
            @(error_event_int) ;
16895
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16896
            ok = 0 ;
16897 35 mihad
            error_monitor_done = 1 ;
16898 15 mihad
        end
16899
        join
16900
 
16901
        if ( ok )
16902
            test_ok ;
16903
    `endif
16904
 
16905
    `ifdef TEST_BURST_CONFIG_READ
16906
        `undef TEST_BURST_CONFIG_READ
16907
    `endif
16908
 
16909
    `ifdef TEST_BURST_CONFIG_WRITE
16910
        `undef TEST_BURST_CONFIG_WRITE
16911
    `endif
16912
 
16913
    master1_check_received_data = 1 ;
16914
    master2_check_received_data = 1 ;
16915
 
16916
    if ( do_mem_disconnects )
16917
    begin
16918
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
16919
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16920
        if ( ok !== 1 )
16921
        begin
16922
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16923
            test_fail("PCI Base Address register could not be written") ;
16924
            disable main ;
16925
        end
16926
 
16927
        // Set Address Mask of IMAGE
16928
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16929
        if ( ok !== 1 )
16930
        begin
16931
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16932
            test_fail("PCI Address Mask register could not be written") ;
16933
            disable main ;
16934
        end
16935
 
16936
        // Set Translation Address of IMAGE
16937
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16938
        if ( ok !== 1 )
16939
        begin
16940
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16941
            test_fail("PCI Translation Address Register could not be written") ;
16942
            disable main ;
16943
        end
16944
 
16945
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16946
        if ( ok !== 1 )
16947
        begin
16948
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16949
            test_fail("PCI Image Control register could not be written") ;
16950
            disable main ;
16951
        end
16952
 
16953
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
16954
        if ( ok !== 1 )
16955
        begin
16956
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16957
            test_fail("Cache Line Size register could not be written") ;
16958
            disable main ;
16959
        end
16960
 
16961
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16962
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16963
        data = 32'hAAAA_AAAA ;
16964
        byte_enables = 4'h0 ;
16965
        expect_length = `PCIW_DEPTH - 2 ;
16966
 
16967
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
16968
        fork
16969
        begin
16970
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
16971
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16972
                        byte_enables,
16973
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
16974
                        8'h0_0, `Test_One_Zero_Target_WS,
16975
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
16976
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16977
            do_pause( 3 ) ;
16978
 
16979
            while ( FRAME !== 1 || IRDY !== 1 )
16980
                @(posedge pci_clock) ;
16981
 
16982 35 mihad
            #1 ;
16983
            if ( !error_monitor_done )
16984
                disable monitor_error_event5 ;
16985 15 mihad
        end
16986
        begin:monitor_error_event5
16987 35 mihad
            error_monitor_done = 0 ;
16988 15 mihad
            pci_ok = 1 ;
16989
            @(error_event_int) ;
16990
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
16991
            pci_ok = 0 ;
16992 35 mihad
            error_monitor_done = 1 ;
16993 15 mihad
        end
16994
        begin
16995
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
16996
            if ( wb_ok !== 1 )
16997
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
16998
        end
16999
        join
17000
 
17001
        if ( wb_ok && pci_ok )
17002
            test_ok ;
17003
 
17004
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17005
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17006
        data = 32'hAAAA_AAAA ;
17007
        byte_enables = 4'h0 ;
17008
        expect_length = `PCIW_DEPTH - 2 ;
17009
 
17010
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17011
        fork
17012
        begin
17013
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17014
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17015
                        byte_enables,
17016
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
17017
                        8'h0_0, `Test_One_Zero_Target_WS,
17018
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17019
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17020
            do_pause( 3 ) ;
17021
 
17022
            while ( FRAME !== 1 || IRDY !== 1 )
17023
                @(posedge pci_clock) ;
17024
 
17025 35 mihad
            #1 ;
17026
            if ( !error_monitor_done )
17027
                disable monitor_error_event6 ;
17028 15 mihad
        end
17029
        begin:monitor_error_event6
17030 35 mihad
            error_monitor_done = 0 ;
17031 15 mihad
            pci_ok = 1 ;
17032
            @(error_event_int) ;
17033
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17034
            pci_ok = 0 ;
17035 35 mihad
            error_monitor_done = 1 ;
17036 15 mihad
        end
17037
        begin
17038
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17039
            if ( wb_ok !== 1 )
17040
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17041
        end
17042
        join
17043
 
17044
        if ( wb_ok && pci_ok )
17045
            test_ok ;
17046
 
17047
        master1_check_received_data = 1 ;
17048
//        master2_check_received_data = 0 ;
17049
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17050
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17051
        data = 32'hAAAA_AAAA ;
17052
        byte_enables = 4'h0 ;
17053
        expect_length = 4 ;
17054
 
17055
        fork
17056
        begin
17057
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17058
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17059
                        byte_enables,
17060
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17061
                        8'h0_0, `Test_One_Zero_Target_WS,
17062
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17063
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17064
            do_pause( 1 ) ;
17065
 
17066
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17067
            if ( wb_ok !== 1 )
17068
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17069
 
17070
            do_pause(2) ;
17071
 
17072
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17073
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17074
                        byte_enables,
17075
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17076
                        8'h0_0, `Test_One_Zero_Target_WS,
17077
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17078
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17079
            do_pause( 3 ) ;
17080
 
17081
            while ( FRAME !== 1 || IRDY !== 1 )
17082
                @(posedge pci_clock) ;
17083
 
17084 35 mihad
            #1 ;
17085
            if ( !error_monitor_done )
17086
                disable monitor_error_event7 ;
17087 15 mihad
        end
17088
        begin:monitor_error_event7
17089 35 mihad
            error_monitor_done = 0 ;
17090 15 mihad
            pci_ok = 1 ;
17091
            @(error_event_int) ;
17092
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17093
            pci_ok = 0 ;
17094 35 mihad
            error_monitor_done = 1 ;
17095 15 mihad
        end
17096
        join
17097
 
17098
        if ( wb_ok && pci_ok )
17099
            test_ok ;
17100
 
17101
        master1_check_received_data = 1 ;
17102
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17103
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17104
        data = 32'hAAAA_AAAA ;
17105
        byte_enables = 4'h0 ;
17106
        expect_length = 4 ;
17107
 
17108
        fork
17109
        begin
17110
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17111
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17112
                        byte_enables,
17113
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17114
                        8'h0_0, `Test_One_Zero_Target_WS,
17115
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17116
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17117
            do_pause( 1 ) ;
17118
 
17119
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17120
            if ( wb_ok !== 1 )
17121
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17122
 
17123
            do_pause(2) ;
17124
 
17125
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17126
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17127
                        byte_enables,
17128
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17129
                        8'h0_0, `Test_One_Zero_Target_WS,
17130
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17131
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17132
            do_pause( 3 ) ;
17133
 
17134
            while ( FRAME !== 1 || IRDY !== 1 )
17135
                @(posedge pci_clock) ;
17136
 
17137 35 mihad
            #1 ;
17138
            if ( !error_monitor_done )
17139
                disable monitor_error_event8 ;
17140 15 mihad
        end
17141
        begin:monitor_error_event8
17142 35 mihad
            error_monitor_done = 0 ;
17143 15 mihad
            pci_ok = 1 ;
17144
            @(error_event_int) ;
17145
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17146
            pci_ok = 0 ;
17147 35 mihad
            error_monitor_done = 1 ;
17148 15 mihad
        end
17149
        join
17150
 
17151
        if ( wb_ok && pci_ok )
17152
            test_ok ;
17153
 
17154
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17155
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17156
        data = 32'hDEAF_BEAF ;
17157
        byte_enables = 4'h0 ;
17158
        expect_length = 1 ;
17159
 
17160
        fork
17161
        begin
17162
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17163
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17164
                        byte_enables,
17165
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17166
                        8'h0_0, `Test_One_Zero_Target_WS,
17167
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17168
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17169
            do_pause( 3 ) ;
17170
 
17171
            while ( FRAME !== 1 || IRDY !== 1 )
17172
                @(posedge pci_clock) ;
17173
 
17174 35 mihad
            #1 ;
17175
            if ( !error_monitor_done )
17176
                disable monitor_error_event9 ;
17177 15 mihad
        end
17178
        begin:monitor_error_event9
17179 35 mihad
            error_monitor_done = 0 ;
17180 15 mihad
            pci_ok = 1 ;
17181
            @(error_event_int) ;
17182
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17183
            pci_ok = 0 ;
17184 35 mihad
            error_monitor_done = 1 ;
17185 15 mihad
        end
17186
        begin
17187
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17188
            if ( wb_ok !== 1 )
17189
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17190
        end
17191
        join
17192
 
17193
        if ( wb_ok && pci_ok )
17194
            test_ok ;
17195
 
17196
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17197
        data = 32'hDEAD_BEAF ;
17198
        byte_enables = 4'h0 ;
17199
        expect_length = 1 ;
17200
 
17201
        fork
17202
        begin
17203
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17204
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17205
                        byte_enables,
17206
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17207
                        8'h0_0, `Test_One_Zero_Target_WS,
17208
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17209
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17210
            do_pause( 3 ) ;
17211
 
17212
            while ( FRAME !== 1 || IRDY !== 1 )
17213
                @(posedge pci_clock) ;
17214
 
17215 35 mihad
            #1 ;
17216
            if ( !error_monitor_done )
17217
                disable monitor_error_event10 ;
17218 15 mihad
        end
17219
        begin:monitor_error_event10
17220 35 mihad
            error_monitor_done = 0 ;
17221 15 mihad
            pci_ok = 1 ;
17222
            @(error_event_int) ;
17223
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17224
            pci_ok = 0 ;
17225 35 mihad
            error_monitor_done = 1 ;
17226 15 mihad
        end
17227
        begin
17228
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17229
            if ( wb_ok !== 1 )
17230
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17231
        end
17232
        join
17233
 
17234
        if ( wb_ok && pci_ok )
17235
            test_ok ;
17236
 
17237
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17238
        data = 32'hAAAA_AAAA ;
17239
        byte_enables = 4'h0 ;
17240
        expect_length = 1 ;
17241
 
17242
        fork
17243
        begin
17244
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17245
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17246
                        byte_enables,
17247
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17248
                        8'h0_0, `Test_One_Zero_Target_WS,
17249
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17250
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17251
            do_pause( 3 ) ;
17252
 
17253
            while ( FRAME !== 1 || IRDY !== 1 )
17254
                @(posedge pci_clock) ;
17255
 
17256 35 mihad
            #1 ;
17257
            if ( !error_monitor_done )
17258
                disable monitor_error_event11 ;
17259 15 mihad
        end
17260
        begin:monitor_error_event11
17261 35 mihad
            error_monitor_done = 0 ;
17262 15 mihad
            pci_ok = 1 ;
17263
            @(error_event_int) ;
17264
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17265
            pci_ok = 0 ;
17266 35 mihad
            error_monitor_done = 1 ;
17267 15 mihad
        end
17268
        begin
17269
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17270
            if ( wb_ok !== 1 )
17271
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17272
        end
17273
        join
17274
 
17275
        if ( wb_ok && pci_ok )
17276
            test_ok ;
17277
 
17278
        master1_check_received_data = 1 ;
17279
 
17280
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17281
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17282
        data = 32'hDEAF_BEAF ;
17283
        byte_enables = 4'h0 ;
17284
        expect_length = 1 ;
17285
 
17286
        fork
17287
        begin
17288
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17289
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17290
                        byte_enables,
17291
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17292
                        8'h0_0, `Test_One_Zero_Target_WS,
17293
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17294
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17295
            do_pause( 1 ) ;
17296
 
17297
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17298
            if ( wb_ok !== 1 )
17299
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17300
 
17301
            do_pause(3) ;
17302
 
17303
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17304
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17305
                        byte_enables,
17306
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17307
                        8'h0_0, `Test_One_Zero_Target_WS,
17308
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17309
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17310
            do_pause( 3 ) ;
17311
 
17312
            while ( FRAME !== 1 || IRDY !== 1 )
17313
                @(posedge pci_clock) ;
17314
 
17315 35 mihad
            #1 ;
17316
            if ( !error_monitor_done )
17317
                disable monitor_error_event12 ;
17318 15 mihad
        end
17319
        begin:monitor_error_event12
17320 35 mihad
            error_monitor_done = 0 ;
17321 15 mihad
            pci_ok = 1 ;
17322
            @(error_event_int) ;
17323
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17324
            pci_ok = 0 ;
17325 35 mihad
            error_monitor_done = 1 ;
17326 15 mihad
        end
17327
        join
17328
 
17329
        if ( wb_ok && pci_ok )
17330
            test_ok ;
17331
 
17332
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17333
        data = 32'hDEAD_BEAF ;
17334
        byte_enables = 4'h0 ;
17335
        expect_length = 1 ;
17336
 
17337
        fork
17338
        begin
17339
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17340
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17341
                        byte_enables,
17342
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17343
                        8'h0_0, `Test_One_Zero_Target_WS,
17344
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17345
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17346
            do_pause( 1 ) ;
17347
 
17348
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17349
            if ( wb_ok !== 1 )
17350
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17351
 
17352
            do_pause(3) ;
17353
 
17354
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17355
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17356
                        byte_enables,
17357
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17358
                        8'h0_0, `Test_One_Zero_Target_WS,
17359
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17360
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17361
            do_pause( 3 ) ;
17362
 
17363
            while ( FRAME !== 1 || IRDY !== 1 )
17364
                @(posedge pci_clock) ;
17365
 
17366 35 mihad
            #1 ;
17367
            if ( !error_monitor_done )
17368
                disable monitor_error_event13 ;
17369 15 mihad
        end
17370
        begin:monitor_error_event13
17371 35 mihad
            error_monitor_done = 0 ;
17372 15 mihad
            pci_ok = 1 ;
17373
            @(error_event_int) ;
17374
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17375
            pci_ok = 0 ;
17376 35 mihad
            error_monitor_done = 1 ;
17377 15 mihad
        end
17378
        join
17379
 
17380
        if ( wb_ok && pci_ok )
17381
            test_ok ;
17382
 
17383
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17384
        data = 32'hAAAA_AAAA ;
17385
        byte_enables = 4'h0 ;
17386
        expect_length = 1 ;
17387
 
17388
        fork
17389
        begin
17390
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17391
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17392
                        byte_enables,
17393
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17394
                        8'h0_0, `Test_One_Zero_Target_WS,
17395
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17396
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17397
            do_pause( 1 ) ;
17398
 
17399
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17400
            if ( wb_ok !== 1 )
17401
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17402
 
17403
            do_pause(3) ;
17404
 
17405
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17406
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17407
                        byte_enables,
17408
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17409
                        8'h0_0, `Test_One_Zero_Target_WS,
17410
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17411
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17412
            do_pause( 3 ) ;
17413
 
17414
            while ( FRAME !== 1 || IRDY !== 1 )
17415
                @(posedge pci_clock) ;
17416
 
17417 35 mihad
            #1 ;
17418
            if ( !error_monitor_done )
17419
                disable monitor_error_event14 ;
17420 15 mihad
        end
17421
        begin:monitor_error_event14
17422 35 mihad
            error_monitor_done = 0 ;
17423 15 mihad
            pci_ok = 1 ;
17424
            @(error_event_int) ;
17425
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17426
            pci_ok = 0 ;
17427 35 mihad
            error_monitor_done = 1 ;
17428 15 mihad
        end
17429
        join
17430
 
17431
        if ( wb_ok && pci_ok )
17432
            test_ok ;
17433
 
17434
        // disable the image
17435
        test_name = "DISABLING MEMORY IMAGE" ;
17436 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17437 15 mihad
        if ( ok !== 1 )
17438
        begin
17439
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17440
            test_fail("PCI Address Mask register could not be written") ;
17441
            disable main ;
17442
        end
17443
    end
17444
//*
17445
    if ( target_io_image !== -1 )
17446
    begin
17447
        do_io_disconnects = 1 ;
17448
 
17449
        if (target_io_image === 1)
17450
        begin
17451
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17452
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17453
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17454
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17455
        end
17456
        else if (target_io_image === 2)
17457
        begin
17458
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17459
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17460
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17461
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17462
        end
17463
        else if (target_io_image === 3)
17464
        begin
17465
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17466
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17467
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17468
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17469
        end
17470
        else if (target_io_image === 4)
17471
        begin
17472
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17473
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17474
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17475
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17476
        end
17477
        else if (target_io_image === 5)
17478
        begin
17479
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17480
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17481
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17482
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17483
        end
17484
    end
17485
    else
17486
        do_io_disconnects = 0 ;
17487
 
17488
    if ( do_io_disconnects )
17489
    begin
17490
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17491
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17492
        if ( ok !== 1 )
17493
        begin
17494
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17495
            test_fail("PCI Base Address register could not be written") ;
17496
            disable main ;
17497
        end
17498
 
17499
        // Set Address Mask of IMAGE
17500
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17501
        if ( ok !== 1 )
17502
        begin
17503
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17504
            test_fail("PCI Address Mask register could not be written") ;
17505
            disable main ;
17506
        end
17507
 
17508
        // Set Translation Address of IMAGE
17509
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17510
        if ( ok !== 1 )
17511
        begin
17512
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17513
            test_fail("PCI Translation Address Register could not be written") ;
17514
            disable main ;
17515
        end
17516
 
17517
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17518
        if ( ok !== 1 )
17519
        begin
17520
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17521
            test_fail("PCI Image Control register could not be written") ;
17522
            disable main ;
17523
        end
17524
 
17525
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17526
        if ( ok !== 1 )
17527
        begin
17528
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17529
            test_fail("Cache Line Size register could not be written") ;
17530
            disable main ;
17531
        end
17532
 
17533
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17534
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17535
        data = 32'h5555_5555 ;
17536
        byte_enables = 4'h0 ;
17537
        expect_length = 1 ;
17538
 
17539
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17540
 
17541
        fork
17542
        begin
17543
            PCIU_IO_WRITE
17544
            (
17545
                `Test_Master_1,             // which master
17546
                pci_address,                // to what address
17547
                data,                       // data
17548
                byte_enables,               // byte enable
17549
                expect_length + 1,          // length to request
17550
                `Test_Target_Retry_On       // expected target termination
17551
            ) ;
17552
 
17553
            do_pause( 3 ) ;
17554
 
17555
            while ( FRAME !== 1 || IRDY !== 1 )
17556
                @(posedge pci_clock) ;
17557
 
17558 35 mihad
            #1 ;
17559
            if ( !error_monitor_done )
17560
                disable monitor_error_event15 ;
17561 15 mihad
        end
17562
        begin:monitor_error_event15
17563 35 mihad
            error_monitor_done = 0 ;
17564 15 mihad
            pci_ok = 1 ;
17565
            @(error_event_int) ;
17566
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17567
            pci_ok = 0 ;
17568 35 mihad
            error_monitor_done = 1 ;
17569 15 mihad
        end
17570
        begin
17571
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17572
            if ( wb_ok !== 1 )
17573
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17574
        end
17575
        join
17576
 
17577
        if ( wb_ok && pci_ok )
17578
            test_ok ;
17579
 
17580
        data = 32'hAAAA_AAAA ;
17581
        fork
17582
        begin
17583
            PCIU_IO_WRITE
17584
            (
17585
                `Test_Master_1,             // which master
17586
                pci_address,                // to what address
17587
                data,                       // data
17588
                byte_enables,               // byte enable
17589
                expect_length + 2,          // length to request
17590
                `Test_Target_Retry_Before   // expected target termination
17591
            ) ;
17592
 
17593
            do_pause( 3 ) ;
17594
 
17595
            while ( FRAME !== 1 || IRDY !== 1 )
17596
                @(posedge pci_clock) ;
17597
 
17598 35 mihad
            #1 ;
17599
            if ( !error_monitor_done )
17600
                disable monitor_error_event16 ;
17601 15 mihad
        end
17602
        begin:monitor_error_event16
17603 35 mihad
            error_monitor_done = 0 ;
17604 15 mihad
            pci_ok = 1 ;
17605
            @(error_event_int) ;
17606
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17607
            pci_ok = 0 ;
17608 35 mihad
            error_monitor_done = 1 ;
17609 15 mihad
        end
17610
        begin
17611
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17612
            if ( wb_ok !== 1 )
17613
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17614
        end
17615
        join
17616
 
17617
        if ( wb_ok && pci_ok )
17618
            test_ok ;
17619
 
17620
        master2_check_received_data = 1 ;
17621
 
17622
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17623
 
17624
        fork
17625
        begin
17626
 
17627
             PCIU_IO_READ
17628
             (
17629
                `Test_Master_2,
17630
                pci_address[PCI_BUS_DATA_RANGE:0],
17631
                data,
17632
                byte_enables,
17633
                2,
17634
                `Test_Target_Retry_Before
17635
             );
17636
 
17637
            do_pause( 1 ) ;
17638
 
17639
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17640
            if ( wb_ok !== 1 )
17641
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17642
 
17643
            do_pause(3) ;
17644
 
17645
            PCIU_IO_READ
17646
             (
17647
                `Test_Master_2,
17648
                pci_address[PCI_BUS_DATA_RANGE:0],
17649
                data,
17650
                byte_enables,
17651
                expect_length + 1,
17652
                `Test_Target_Retry_On
17653
             );
17654
 
17655
            do_pause( 3 ) ;
17656
 
17657
            while ( FRAME !== 1 || IRDY !== 1 )
17658
                @(posedge pci_clock) ;
17659
 
17660 35 mihad
            #1 ;
17661
            if ( !error_monitor_done )
17662
                disable monitor_error_event17 ;
17663 15 mihad
        end
17664
        begin:monitor_error_event17
17665 35 mihad
            error_monitor_done = 0 ;
17666 15 mihad
            pci_ok = 1 ;
17667
            @(error_event_int) ;
17668
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17669
            pci_ok = 0 ;
17670 35 mihad
            error_monitor_done = 1 ;
17671 15 mihad
        end
17672
        join
17673
 
17674
        if ( wb_ok && pci_ok )
17675
            test_ok ;
17676
 
17677
        fork
17678
        begin
17679
 
17680
             PCIU_IO_READ
17681
             (
17682
                `Test_Master_2,
17683
                pci_address[PCI_BUS_DATA_RANGE:0],
17684
                data,
17685
                byte_enables,
17686
                2,
17687
                `Test_Target_Retry_Before
17688
             );
17689
 
17690
            do_pause( 1 ) ;
17691
 
17692
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17693
            if ( wb_ok !== 1 )
17694
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17695
 
17696
            do_pause(3) ;
17697
 
17698
            PCIU_IO_READ
17699
             (
17700
                `Test_Master_2,
17701
                pci_address[PCI_BUS_DATA_RANGE:0],
17702
                data,
17703
                byte_enables,
17704
                expect_length + 2,
17705
                `Test_Target_Retry_Before
17706
             );
17707
 
17708
            do_pause( 3 ) ;
17709
 
17710
            while ( FRAME !== 1 || IRDY !== 1 )
17711
                @(posedge pci_clock) ;
17712
 
17713 35 mihad
            #1 ;
17714
            if ( !error_monitor_done )
17715
                disable monitor_error_event18 ;
17716 15 mihad
        end
17717
        begin:monitor_error_event18
17718 35 mihad
            error_monitor_done = 0 ;
17719 15 mihad
            pci_ok = 1 ;
17720
            @(error_event_int) ;
17721
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17722
            pci_ok = 0 ;
17723 35 mihad
            error_monitor_done = 1 ;
17724 15 mihad
        end
17725
        join
17726
 
17727
        if ( wb_ok && pci_ok )
17728
            test_ok ;
17729
 
17730
        test_name = "DISABLING IO IMAGE" ;
17731 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17732 15 mihad
        if ( ok !== 1 )
17733
        begin
17734
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17735
            test_fail("PCI Address Mask register could not be written") ;
17736
            disable main ;
17737
        end
17738
    end
17739
//*/
17740
end
17741
endtask // target_disconnects
17742
 
17743
task target_unsupported_cmds ;
17744
        input [31:0] Address;
17745
        input [2:0]  image_num ;
17746
    reg          ok ;
17747
begin:main
17748
 
17749
    $display("  ") ;
17750
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17751
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17752 45 mihad
 
17753
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17754
    configuration_cycle_write
17755
    (
17756
        0,                        // bus number
17757
        `TAR1_IDSEL_INDEX - 11,   // device number
17758
        0,                        // function number
17759
        1,                        // register number
17760
        0,                        // type of configuration cycle
17761
        4'b0001,                  // byte enables
17762
        32'h0000_0044             // data
17763
    ) ;
17764
 
17765
    configuration_cycle_write
17766
    (
17767
        0,                        // bus number
17768
        `TAR2_IDSEL_INDEX - 11,   // device number
17769
        0,                        // function number
17770
        1,                        // register number
17771
        0,                        // type of configuration cycle
17772
        4'b0001,                  // byte enables
17773
        32'h0000_0044             // data
17774
    ) ;
17775
 
17776 15 mihad
    ipci_unsupported_commands_master.master_reference
17777
    (
17778
        Address,                // first part of address in dual address cycle
17779
        Address,                // second part of address in dual address cycle
17780
        `BC_IACK,                       // dual address cycle command
17781
        `BC_IACK,               // normal command
17782
        4'h0,               // byte enables
17783
        32'h1234_5678,      // data
17784
        1'b0,               // make address parity error on first phase of dual address
17785
        1'b0,               // make address parity error on second phase of dual address
17786
        ok                  // result of operation
17787
    ) ;
17788
    if ( ok )
17789
        test_ok ;
17790
    else
17791
    begin
17792
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17793
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17794
    end
17795
 
17796
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17797
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17798
    ipci_unsupported_commands_master.master_reference
17799
    (
17800
        Address,                // first part of address in dual address cycle
17801
        Address,                // second part of address in dual address cycle
17802
        `BC_SPECIAL,            // dual address cycle command
17803
        `BC_SPECIAL,            // normal command
17804
        4'h0,               // byte enables
17805
        32'h1234_5678,      // data
17806
        1'b0,               // make address parity error on first phase of dual address
17807
        1'b0,               // make address parity error on second phase of dual address
17808
        ok                  // result of operation
17809
    ) ;
17810
    if ( ok )
17811
        test_ok ;
17812
    else
17813
    begin
17814
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17815
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17816
    end
17817
 
17818
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17819
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17820
    ipci_unsupported_commands_master.master_reference
17821
    (
17822
        Address,                // first part of address in dual address cycle
17823
        Address,                // second part of address in dual address cycle
17824
        `BC_RESERVED0,          // dual address cycle command
17825
        `BC_RESERVED0,      // normal command
17826
        4'h0,               // byte enables
17827
        32'h1234_5678,      // data
17828
        1'b0,               // make address parity error on first phase of dual address
17829
        1'b0,               // make address parity error on second phase of dual address
17830
        ok                  // result of operation
17831
    ) ;
17832
    if ( ok )
17833
        test_ok ;
17834
    else
17835
    begin
17836
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17837
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17838
    end
17839
 
17840
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17841
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17842
    ipci_unsupported_commands_master.master_reference
17843
    (
17844
        Address,                // first part of address in dual address cycle
17845
        Address,                // second part of address in dual address cycle
17846
        `BC_RESERVED1,          // dual address cycle command
17847
        `BC_RESERVED1,      // normal command
17848
        4'h0,               // byte enables
17849
        32'h1234_5678,      // data
17850
        1'b0,               // make address parity error on first phase of dual address
17851
        1'b0,               // make address parity error on second phase of dual address
17852
        ok                  // result of operation
17853
    ) ;
17854
    if ( ok )
17855
        test_ok ;
17856
    else
17857
    begin
17858
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17859
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17860
    end
17861
 
17862
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17863
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17864
    ipci_unsupported_commands_master.master_reference
17865
    (
17866
        Address,                // first part of address in dual address cycle
17867
        Address,                // second part of address in dual address cycle
17868
        `BC_RESERVED2,          // dual address cycle command
17869
        `BC_RESERVED2,      // normal command
17870
        4'h0,               // byte enables
17871
        32'h1234_5678,      // data
17872
        1'b0,               // make address parity error on first phase of dual address
17873
        1'b0,               // make address parity error on second phase of dual address
17874
        ok                  // result of operation
17875
    ) ;
17876
    if ( ok )
17877
        test_ok ;
17878
    else
17879
    begin
17880
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17881
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17882
    end
17883
 
17884
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17885
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17886
    ipci_unsupported_commands_master.master_reference
17887
    (
17888
        Address,                // first part of address in dual address cycle
17889
        Address,                // second part of address in dual address cycle
17890
        `BC_RESERVED3,          // dual address cycle command
17891
        `BC_RESERVED3,      // normal command
17892
        4'h0,               // byte enables
17893
        32'h1234_5678,      // data
17894
        1'b0,               // make address parity error on first phase of dual address
17895
        1'b0,               // make address parity error on second phase of dual address
17896
        ok                  // result of operation
17897
    ) ;
17898
    if ( ok )
17899
        test_ok ;
17900
    else
17901
    begin
17902
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17903
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17904
    end
17905
 
17906
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17907
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17908
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17909
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17910
    ipci_unsupported_commands_master.master_reference
17911
    (
17912
        Address,                // first part of address in dual address cycle
17913
        Address,                // second part of address in dual address cycle
17914
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
17915
        `BC_MEM_WRITE,      // normal command
17916
        4'h0,               // byte enables;
17917
        32'h1234_5678,      // data
17918
        1'b0,               // make address parity error on first phase of dual address
17919
        1'b0,               // make address parity error on second phase of dual address
17920
        ok                  // result of operation
17921
    ) ;
17922
    if ( ok )
17923
        test_ok ;
17924
    else
17925
    begin
17926
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17927
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
17928
    end
17929
 
17930 45 mihad
    // enable pci blue behavioral targets 1 and 2
17931
    configuration_cycle_write
17932
    (
17933
        0,                        // bus number
17934
        `TAR1_IDSEL_INDEX - 11,   // device number
17935
        0,                        // function number
17936
        1,                        // register number
17937
        0,                        // type of configuration cycle
17938
        4'b0001,                  // byte enables
17939
        32'h0000_0047             // data
17940
    ) ;
17941
 
17942
    configuration_cycle_write
17943
    (
17944
        0,                        // bus number
17945
        `TAR2_IDSEL_INDEX - 11,   // device number
17946
        0,                        // function number
17947
        1,                        // register number
17948
        0,                        // type of configuration cycle
17949
        4'b0001,                  // byte enables
17950
        32'h0000_0047             // data
17951
    ) ;
17952 15 mihad
end
17953
endtask // target_unsupported_cmds
17954
 
17955
task target_completion_expiration ;
17956
    reg   [11:0] pci_ctrl_offset ;
17957
    reg   [11:0] pci_ba_offset ;
17958
    reg   [11:0] pci_am_offset ;
17959
    reg   [11:0] pci_device_ctrl_offset ;
17960
    reg   [11:0] pci_err_cs_offset ;
17961
    reg   [11:0] icr_offset ;
17962
    reg   [11:0] isr_offset ;
17963
    reg   [11:0] lat_tim_cls_offset ;
17964
 
17965
    reg [31:0] temp_val1 ;
17966
    reg [31:0] temp_val2 ;
17967
    reg        ok   ;
17968 33 mihad
    reg        ok_wb ;
17969
    reg        ok_pci ;
17970 15 mihad
 
17971
    reg [31:0] pci_image_base ;
17972
    integer i ;
17973 33 mihad
    integer clocks_after_completion ;
17974
    reg     error_monitor_done ;
17975
    reg     test_mem ;
17976 15 mihad
 
17977
begin:main
17978
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17979
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
17980
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
17981
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
17982
 
17983
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
17984
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
17985
    lat_tim_cls_offset = 12'hC ;
17986
    pci_device_ctrl_offset    = 12'h4 ;
17987
 
17988 33 mihad
    `ifdef HOST
17989
        test_mem = 1'b1 ;
17990
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
17991
    `else
17992
        test_mem = !`PCI_BA1_MEM_IO ;
17993
        pci_image_base = Target_Base_Addr_R[1] ;
17994
    `endif
17995 15 mihad
 
17996
    // enable master & target operation
17997
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
17998
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
17999
    if ( ok !== 1 )
18000
    begin
18001
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18002
        test_fail("write to PCI Device Control register failed") ;
18003
        disable main ;
18004
    end
18005
 
18006
    // prepare image control register
18007 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18008 15 mihad
    if ( ok !== 1 )
18009
    begin
18010
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18011
        test_fail("write to PCI Image Control register failed") ;
18012
        disable main ;
18013
    end
18014
 
18015
    // prepare base address register
18016
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18017
    if ( ok !== 1 )
18018
    begin
18019
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18020
        test_fail("write to PCI Base Address register failed") ;
18021
        disable main ;
18022
    end
18023
 
18024
    // write address mask register
18025
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18026
    if ( ok !== 1 )
18027
    begin
18028
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18029
        test_fail("write to PCI Address Mask register failed") ;
18030
        disable main ;
18031
    end
18032
 
18033
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18034
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18035
    if ( ok !== 1 )
18036
    begin
18037
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18038
        test_fail("write to PCI Error Control and Status register failed") ;
18039
        disable main ;
18040
    end
18041
 
18042 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18043 15 mihad
    if ( ok !== 1 )
18044
    begin
18045
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18046
        test_fail("write to Interrupt Control register failed") ;
18047
        disable main ;
18048
    end
18049
 
18050
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18051
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18052
    if ( ok !== 1 )
18053
    begin
18054
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18055
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18056
        disable main ;
18057
    end
18058
 
18059
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18060
 
18061
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18062 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18063
    master1_check_received_data = 0 ;
18064 15 mihad
 
18065 33 mihad
    ok_pci = 1 ;
18066
    // start a delayed read request
18067
    fork
18068
    begin
18069
        if ( test_mem )
18070
 
18071
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18072
                          pci_image_base, 32'h1234_5678,
18073
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18074
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18075
        else
18076
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18077
 
18078
        do_pause( 1 ) ;
18079
    end
18080
    begin:error_monitor1
18081 35 mihad
        error_monitor_done = 0 ;
18082 33 mihad
        @(error_event_int) ;
18083
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18084
        ok_pci = 0 ;
18085 35 mihad
        error_monitor_done = 1 ;
18086 33 mihad
    end
18087
    begin
18088
        if ( test_mem )
18089
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18090
        else
18091
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18092 15 mihad
 
18093 33 mihad
        if ( ok_wb !== 1 )
18094
        begin
18095
            test_fail("Bridge failed to process Target Memory read correctly") ;
18096
            disable main ;
18097
        end
18098
 
18099 35 mihad
        #1 ;
18100
        if ( !error_monitor_done )
18101 33 mihad
            disable error_monitor1 ;
18102
    end
18103
    join
18104
 
18105
    clocks_after_completion = 0 ;
18106
    // now do another - different transaction
18107
    fork
18108
    begin
18109
        if ( test_mem )
18110
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18111
                          pci_image_base + 4, 32'h1234_5678,
18112
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18113
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18114
        else
18115
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18116
 
18117
        while ( clocks_after_completion < 32'h0000_FFF0 )
18118
        begin
18119
            @(posedge pci_clock) ;
18120
            clocks_after_completion = clocks_after_completion + 1 ;
18121
        end
18122
 
18123
        do_pause('hFF) ;
18124
 
18125
        if ( test_mem )
18126
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18127
                          pci_image_base + 4, 32'h1234_5678,
18128
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18129
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18130
        else
18131
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18132
 
18133
        do_pause( 1 ) ;
18134
    end
18135
    begin:error_monitor2
18136 35 mihad
        error_monitor_done = 0 ;
18137 33 mihad
        @(error_event_int) ;
18138
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18139
        ok_pci = 0 ;
18140 35 mihad
        error_monitor_done = 1 ;
18141 33 mihad
    end
18142
    begin
18143
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18144
        repeat( 'hFF )
18145
            @(posedge pci_clock) ;
18146
 
18147
        if ( test_mem )
18148
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18149
        else
18150
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18151
 
18152
        if ( ok_wb !== 1 )
18153
        begin
18154
            test_fail("Bridge failed to process Target Memory read correctly") ;
18155
            disable main ;
18156
        end
18157
 
18158
        repeat(4)
18159
            @(posedge pci_clock) ;
18160
 
18161
        fork
18162
        begin
18163
            if ( test_mem )
18164
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18165
                              pci_image_base + 4, 32'h1234_5678,
18166
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18167
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18168
            else
18169
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18170
 
18171
            do_pause(1) ;
18172
        end
18173
        begin
18174
           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 ) ;
18175 35 mihad
           #1 ;
18176
           if ( !error_monitor_done )
18177 33 mihad
               disable error_monitor2 ;
18178
        end
18179
        join
18180
    end
18181
    join
18182
 
18183
    if ( ok && ok_pci && ok_wb )
18184
        test_ok ;
18185
 
18186
    if ( ok !== 1 )
18187
    begin
18188
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18189
        test_fail("write to PCI Address Mask register failed") ;
18190
        disable main ;
18191
    end
18192
 
18193
    // check statuses after this situation - none should be set
18194
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18195
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18196
    if ( ok !== 1 )
18197
    begin
18198
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18199
        test_fail("read from pci device status register failed") ;
18200
        disable main ;
18201
    end
18202
 
18203
    if ( temp_val1[31] )
18204
    begin
18205
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18206
        test_fail("detected parity error bit was set for no reason") ;
18207
    end
18208
 
18209
    if ( temp_val1[30] )
18210
    begin
18211
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18212
        test_fail("signaled system error bit was set for no reason") ;
18213
    end
18214
 
18215
    if ( temp_val1[29] )
18216
    begin
18217
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18218
        test_fail("received master abort bit was set for no reason") ;
18219
    end
18220
 
18221
    if ( temp_val1[28] )
18222
    begin
18223
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18224
        test_fail("received target abort bit was set for no reason") ;
18225
    end
18226
 
18227
    if ( temp_val1[27] )
18228
    begin
18229
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18230
        test_fail("signaled target abort bit was set for no reason") ;
18231
    end
18232
 
18233
    if ( temp_val1[24] )
18234
    begin
18235
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18236
        test_fail("Master Data parity error bit was set for no reason") ;
18237
    end
18238
 
18239
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18240
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18241
    if ( temp_val1[8] !== 0 )
18242
    begin
18243
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18244
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18245
    end
18246
    // test target retry counter expiration
18247
    // set wb slave to retry response
18248
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18249
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18250
    ok_pci = 1 ;
18251
 
18252
    fork
18253
    begin
18254
        if ( test_mem == 1 )
18255
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18256
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18257
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18258
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18259
        else
18260
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18261
 
18262
        do_pause(1) ;
18263
 
18264
        // do another write with same address and different data
18265
        if ( test_mem == 1 )
18266
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18267
                        pci_image_base, 32'h8765_4321, 4'h0,
18268
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18269
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18270
        else
18271
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18272
 
18273
        do_pause(1) ;
18274
    end
18275
    begin
18276
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18277
        begin
18278
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18279
            if ( ok_wb !== 1 )
18280
            begin
18281
                $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) ;
18282
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18283
                disable main ;
18284
            end
18285
        end
18286
 
18287
        // set WB slave to normal completion
18288
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18289
 
18290
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18291
        if ( ok_wb !== 1 )
18292
        begin
18293
            $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) ;
18294
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18295
            disable main ;
18296
        end
18297
 
18298 35 mihad
        #1 ;
18299
        if ( !error_monitor_done )
18300 33 mihad
            disable error_monitor3 ;
18301
    end
18302
    begin:error_monitor3
18303 35 mihad
        error_monitor_done = 0 ;
18304 33 mihad
        @(error_event_int) ;
18305
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18306
        ok_pci = 0 ;
18307 35 mihad
        error_monitor_done = 1 ;
18308 33 mihad
    end
18309
    join
18310
 
18311
    if ( ok_wb && ok_pci )
18312
    begin
18313
        test_ok ;
18314
    end
18315
 
18316
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18317
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18318
    if ( temp_val1[8] !== 1'b1 )
18319
    begin
18320
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18321
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18322
    end
18323
 
18324
    if ( temp_val1[9] !== 1 )
18325
    begin
18326
        $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) ;
18327
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18328
    end
18329
 
18330
    if ( temp_val1[10] !== 1 )
18331
    begin
18332
        $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) ;
18333
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18334
    end
18335
 
18336
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18337
    begin
18338
        $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) ;
18339
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18340
    end
18341
 
18342
    if ( temp_val1[31:28] !== 4'hA )
18343
    begin
18344
        $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) ;
18345
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18346
    end
18347
 
18348
    // clear error status register
18349
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18350
 
18351
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18352
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18353
    if ( temp_val1 !== pci_image_base )
18354
    begin
18355
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18356
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18357
    end
18358
 
18359
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18360
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18361
    if ( temp_val1 !== 32'hDEAD_BEAF )
18362
    begin
18363
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18364
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18365
    end
18366
 
18367
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18368
    ok_pci = 1 ;
18369
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18370
 
18371
    i = 0 ;
18372
    fork
18373
    begin
18374
        if ( test_mem )
18375
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18376
                          pci_image_base + 4, 32'h1234_5678,
18377
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18378
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18379
        else
18380
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18381
 
18382
        do_pause( 1 ) ;
18383
 
18384
    end
18385
    begin
18386
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18387
        begin
18388
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18389
            if ( ok_wb !== 1 )
18390
            begin
18391
                $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) ;
18392
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18393
                disable main ;
18394
            end
18395
        end
18396
 
18397
        // set WB slave to normal completion
18398
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18399
 
18400
        fork
18401
        begin
18402
            repeat(4)
18403
                @(posedge pci_clock) ;
18404
 
18405
            if ( test_mem )
18406
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18407
                              pci_image_base, 32'h8765_4321,
18408
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18409
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18410
            else
18411
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18412
 
18413
            do_pause(1) ;
18414
        end
18415
        begin
18416
 
18417
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18418
            if ( ok_wb !== 1 )
18419
            begin
18420
                $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) ;
18421
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18422
                disable main ;
18423
            end
18424
        end
18425
        join
18426
 
18427
        repeat( 4 )
18428
            @(posedge pci_clock) ;
18429
 
18430
        if ( test_mem )
18431
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18432
                          pci_image_base, 32'h8765_4321,
18433
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18434
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18435
        else
18436
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18437
 
18438
        do_pause(1) ;
18439
 
18440 35 mihad
        #1 ;
18441
        if ( !error_monitor_done )
18442 33 mihad
            disable error_monitor4 ;
18443
    end
18444
    begin:error_monitor4
18445 35 mihad
        error_monitor_done = 0 ;
18446 33 mihad
        @(error_event_int) ;
18447
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18448
        ok_pci = 0 ;
18449 35 mihad
        error_monitor_done = 1 ;
18450 33 mihad
    end
18451
    join
18452
 
18453
    if ( ok_wb && ok_pci )
18454
        test_ok ;
18455
 
18456
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18457
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18458
    if ( temp_val1[8] !== 1'b0 )
18459
    begin
18460
        $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) ;
18461
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18462
    end
18463
 
18464
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18465 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18466
    $fdisplay(pciu_mon_log_file_desc,
18467
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18468 33 mihad
    ok_pci = 1 ;
18469
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18470
 
18471
    fork
18472
    begin
18473
        if ( test_mem )
18474
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18475
                          pci_image_base + 4, 32'h1234_5678,
18476
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18477
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18478
        else
18479
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18480
 
18481
        do_pause( 1 ) ;
18482
 
18483
    end
18484
    begin
18485
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18486
        if ( ok_wb !== 1 )
18487
        begin
18488
            $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) ;
18489
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18490
            disable main ;
18491
        end
18492
 
18493
        repeat(4)
18494
            @(posedge pci_clock) ;
18495
 
18496
        fork
18497
        begin
18498
 
18499
            if ( test_mem )
18500
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18501
                              pci_image_base + 4, 32'h8765_4321,
18502
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18503
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18504
            else
18505
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18506
 
18507
            do_pause(1) ;
18508
 
18509
        end
18510
        begin
18511
 
18512
            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 ) ;
18513
            if ( ok !== 1 )
18514
            begin
18515
                $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) ;
18516
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18517
                disable main ;
18518
            end
18519
        end
18520
        join
18521
 
18522 35 mihad
        #1 ;
18523
        if ( !error_monitor_done )
18524 33 mihad
            disable error_monitor5 ;
18525
    end
18526
    begin:error_monitor5
18527 35 mihad
        error_monitor_done = 0 ;
18528 33 mihad
        @(error_event_int) ;
18529
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18530
        ok_pci = 0 ;
18531 35 mihad
        error_monitor_done = 1 ;
18532 33 mihad
    end
18533
    join
18534
 
18535
    if ( ok_wb && ok_pci )
18536
        test_ok ;
18537
 
18538
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18539
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18540
    if ( temp_val1[8] !== 1'b0 )
18541
    begin
18542
        $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) ;
18543
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18544
    end
18545
 
18546
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18547
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18548
    if ( temp_val1[25] !== 1'b1 )
18549
    begin
18550
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18551
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18552
    end
18553
 
18554
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18555
 
18556
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18557
    ok_pci = 1 ;
18558
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18559
 
18560
    fork
18561
    begin
18562
        if ( test_mem == 1 )
18563
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18564
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18565
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18566
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18567
        else
18568
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18569
 
18570
        do_pause(1) ;
18571
 
18572
        // do another write with same address and different data
18573
        if ( test_mem == 1 )
18574
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18575
                        pci_image_base, 32'h8765_6789, 4'h0,
18576
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18577
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18578
        else
18579
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18580
 
18581
        do_pause(1) ;
18582
    end
18583
    begin
18584
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18585
        if ( ok_wb !== 1 )
18586
        begin
18587
            $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) ;
18588
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18589
            disable main ;
18590
        end
18591
 
18592
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18593
 
18594
        if ( test_mem )
18595
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18596
        else
18597
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18598
 
18599
        if ( ok_wb !== 1 )
18600
        begin
18601
            $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) ;
18602
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18603
            disable main ;
18604
        end
18605
 
18606 35 mihad
        #1 ;
18607
        if ( !error_monitor_done )
18608 33 mihad
            disable error_monitor6 ;
18609
    end
18610
    begin:error_monitor6
18611 35 mihad
        error_monitor_done = 0 ;
18612 33 mihad
        @(error_event_int) ;
18613
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18614
        ok_pci = 0 ;
18615 35 mihad
        error_monitor_done = 1 ;
18616 33 mihad
    end
18617
    join
18618
 
18619
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18620
    $fdisplay(pciu_mon_log_file_desc,
18621
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18622
 
18623
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18624
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18625
    if ( temp_val1[8] !== 1'b1 )
18626
    begin
18627
        $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) ;
18628
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18629
    end
18630
 
18631
    if ( temp_val1[9] !== 0 )
18632
    begin
18633
        $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) ;
18634
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18635
    end
18636
 
18637
    if ( temp_val1[10] !== 1 )
18638
    begin
18639
        $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) ;
18640
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18641
    end
18642
 
18643
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18644
    begin
18645
        $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) ;
18646
        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") ;
18647
    end
18648
 
18649
    if ( temp_val1[31:28] !== 4'h0 )
18650
    begin
18651
        $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) ;
18652
        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") ;
18653
    end
18654
 
18655
    // clear error status register
18656
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18657
 
18658
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18659
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18660
    if ( temp_val1 !== pci_image_base )
18661
    begin
18662
        $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) ;
18663
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18664
    end
18665
 
18666
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18667
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18668
    if ( temp_val1 !== 32'hBEAF_DEAD )
18669
    begin
18670
        $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) ;
18671
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18672
    end
18673
 
18674
    // disable current image - write address mask register
18675 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18676 15 mihad
end
18677 57 mihad
endtask // target_completion_expiration
18678 15 mihad
 
18679 57 mihad
task master_completion_expiration ;
18680
    reg   [11:0] ctrl_offset ;
18681
    reg   [11:0] ba_offset ;
18682
    reg   [11:0] am_offset ;
18683
    reg `WRITE_STIM_TYPE write_data ;
18684
    reg `READ_STIM_TYPE  read_data ;
18685
    reg `READ_RETURN_TYPE read_status ;
18686
 
18687
    reg `WRITE_RETURN_TYPE write_status ;
18688
    reg `WB_TRANSFER_FLAGS write_flags ;
18689
    reg        ok   ;
18690
    reg [11:0] pci_ctrl_offset ;
18691
    reg [31:0] image_base ;
18692
    reg [31:0] target_address ;
18693
begin:main
18694
    pci_ctrl_offset = 12'h4 ;
18695
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18696
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18697
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18698
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18699
 
18700
    target_address  = `BEH_TAR1_MEM_START ;
18701
    image_base      = 0 ;
18702
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18703
 
18704
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18705
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18706
    write_flags                      = 0 ;
18707
    write_flags`INIT_WAITS           = tb_init_waits ;
18708
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18709
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18710
 
18711
    // enable master & target operation
18712
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18713
    if ( ok !== 1 )
18714
    begin
18715
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18716
        test_fail("write to PCI Device Control register didn't succeede");
18717
        disable main ;
18718
    end
18719
 
18720
    // prepare image control register
18721
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18722
    if ( ok !== 1 )
18723
    begin
18724
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18725
        test_fail("write to WB Image Control register didn't succeede");
18726
        disable main ;
18727
    end
18728
 
18729
    // prepare base address register
18730
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18731
    if ( ok !== 1 )
18732
    begin
18733
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18734
        test_fail("write to WB Base Address register didn't succeede");
18735
        disable main ;
18736
    end
18737
 
18738
    // write address mask register
18739
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18740
    if ( ok !== 1 )
18741
    begin
18742
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18743
        test_fail("write to WB Address Mask register didn't succeede");
18744
        disable main ;
18745
    end
18746
 
18747
    fork
18748
    begin
18749
        // do not handle retries
18750
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18751
 
18752
        // initiate a read request
18753
        read_data`READ_ADDRESS  = target_address ;
18754
        read_data`READ_SEL      = 4'hF ;
18755
        read_data`READ_TAG_STIM = 0 ;
18756
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18757
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18758
        begin
18759
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18760
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18761
            disable main ;
18762
        end
18763
 
18764
        // handle retries from now on
18765
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18766
 
18767
        write_data`WRITE_ADDRESS = target_address + 4 ;
18768
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18769
        write_data`WRITE_SEL     = 4'hF ;
18770
 
18771
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18772
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18773
        begin
18774
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18775
            test_fail("WB Slave state machine failed to post single memory write");
18776
            disable main ;
18777
        end
18778
 
18779
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 100
18780
        repeat('h1_0000 - 100)
18781
            @(posedge wb_clock) ;
18782
 
18783
        // now perform a read
18784
        read_data`READ_ADDRESS  = target_address + 4 ;
18785
        read_data`READ_SEL      = 4'hF ;
18786
        read_data`READ_TAG_STIM = 0 ;
18787
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18788
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18789
        begin
18790
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18791
            test_fail("PCI bridge didn't process the read as expected");
18792
            disable main ;
18793
        end
18794
 
18795
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18796
        begin
18797
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18798
            test_fail("PCI bridge returned unexpected Read Data");
18799
        end
18800
        else if (ok === 1'b1)
18801
            test_ok ;
18802
    end
18803
    begin:monitors
18804
        // monitor first read, which will expire
18805
        pci_transaction_progress_monitor
18806
        (
18807
            target_address, // expected address
18808
            `BC_MEM_READ,   // expected bus command
18809
            1,              // expected number of transfers
18810
            0,              // expected number of cycles
18811
            1,              // check number of transfers true/false
18812
            0,              // check number of cycles true/false
18813
            0,              // is this fast B2B true/false
18814
            ok              // return 1 if as expected, anything else on error
18815
        ) ;
18816
 
18817
        if ( ok !== 1 )
18818
        begin
18819
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18820
            #1 disable monitors ;
18821
        end
18822
 
18823
        // monitor normal single write
18824
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18825
        if ( ok !== 1 )
18826
        begin
18827
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18828
            #1 disable monitors ;
18829
        end
18830
 
18831
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18832
        repeat('h1_0000 - 50)
18833
            @(posedge wb_clock) ;
18834
 
18835
        // monitor normal single memory read
18836
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18837
        if ( ok !== 1 )
18838
        begin
18839
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18840
        end
18841
    end
18842
    join
18843
 
18844
    // disable the image
18845
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18846
    if ( ok !== 1 )
18847
    begin
18848
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18849
        test_fail("write to WB Address Mask register didn't succeede");
18850
    end
18851
end
18852
endtask // master_completion_expiration
18853
 
18854 15 mihad
task config_write ;
18855
    input [11:0] offset ;
18856
    input [31:0] data ;
18857
    input [3:0]  byte_enable ;
18858
    output       ok ;
18859
    `ifdef HOST
18860
    reg   `WRITE_STIM_TYPE   write_data ;
18861
    reg   `WB_TRANSFER_FLAGS write_flags ;
18862
    reg   `WRITE_RETURN_TYPE write_status ;
18863
    `else
18864
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18865
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18866
    `endif
18867
    reg in_use ;
18868
    reg [31:0] temp_var ;
18869
begin
18870
    if ( in_use === 1 )
18871
    begin
18872
        $display("config_read task re-entered! Time %t ", $time) ;
18873
        ok = 0 ;
18874
        #20 $stop ;
18875
    end
18876
    else
18877
    begin
18878
        ok = 1 ;
18879
        in_use = 1 ;
18880
    end
18881
    `ifdef HOST
18882
    write_flags                    = 0 ;
18883
    write_flags`INIT_WAITS         = tb_init_waits ;
18884
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18885
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18886
 
18887
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18888
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18889
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18890
    write_data`WRITE_SEL                         = byte_enable ;
18891
    write_data`WRITE_TAG_STIM                    = 0 ;
18892
    write_data`WRITE_DATA                        = data ;
18893
 
18894
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18895
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18896
    begin
18897
        $display("Write to configuration space failed! Time %t ", $time) ;
18898
        ok = 0 ;
18899
    end
18900
 
18901
    @(posedge wb_clock) ;
18902
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18903
    // here we just wait for two guest cycles for conf space bits to synchronize
18904
    repeat( 2 )
18905
        @(posedge pci_clock) ;
18906
 
18907
    `else // GUEST
18908
    byte_enables_l = ~byte_enable ;
18909
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18910
 
18911
    fork
18912
    begin
18913
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18914
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
18915
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
18916
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18917
              8'h0_0, `Test_One_Zero_Target_WS,
18918
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
18919
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18920
    do_pause( 1 ) ;
18921
    end
18922
    begin
18923
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
18924
        @(posedge pci_clock) ;
18925
    end
18926
    join
18927
 
18928
     repeat( 2 )
18929
         @(posedge wb_clock) ;
18930
 
18931
    `endif
18932
    in_use = 0 ;
18933
end
18934
endtask // config_write
18935
 
18936
task config_read ;
18937
    input [11:0] offset ;
18938
    input [3:0]  byte_enable ;
18939
    output [31:0] data ;
18940
 
18941
    reg `READ_STIM_TYPE    read_data ;
18942
    reg `WB_TRANSFER_FLAGS read_flags ;
18943
    reg `READ_RETURN_TYPE  read_status ;
18944
 
18945
    reg [31:0] pci_address ;
18946
    reg [3:0] byte_enables_l ;
18947
 
18948
    reg master_check_data_prev ;
18949
    reg in_use ;
18950
    reg [31:0] temp_var ;
18951
begin:main
18952
    if ( in_use === 1 )
18953
    begin
18954
        $display("config_read task re-entered! Time %t ", $time) ;
18955
        data = 32'hxxxx_xxxx ;
18956
        disable main ;
18957
    end
18958
 
18959
    in_use = 1 ;
18960
 
18961
`ifdef HOST
18962 26 mihad
    repeat(4)
18963
        @(posedge pci_clock) ;
18964
    repeat(4)
18965
        @(posedge wb_clock) ;
18966 15 mihad
    read_flags                    = 0 ;
18967
    read_flags`INIT_WAITS         = tb_init_waits ;
18968
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18969
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18970
 
18971
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18972
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18973
 
18974
    read_data`READ_ADDRESS  = temp_var + offset ;
18975
    read_data`READ_SEL      = byte_enable ;
18976
    read_data`READ_TAG_STIM = 0 ;
18977
 
18978
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
18979
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18980
    begin
18981
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
18982
        #20 $stop ;
18983
    end
18984
    data = read_status`READ_DATA ;
18985
`else
18986
  `ifdef GUEST
18987 26 mihad
    repeat(4)
18988
        @(posedge wb_clock) ;
18989
    repeat(4)
18990
        @(posedge pci_clock) ;
18991 15 mihad
    master_check_data_prev = master2_check_received_data ;
18992
    master2_check_received_data = 0 ;
18993
 
18994
    byte_enables_l = ~byte_enable ;
18995
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18996
 
18997
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18998
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
18999
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19000
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19001
             8'h4_0, `Test_One_Zero_Target_WS,
19002
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19003
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19004
    do_pause( 1 ) ;
19005
 
19006
    @(master2_received_data_valid) ;
19007
    data = master2_received_data ;
19008
 
19009
    master2_check_received_data = master_check_data_prev ;
19010
  `endif
19011
`endif
19012
    in_use = 0 ;
19013
end
19014
endtask //config_read
19015
 
19016
task test_fail ;
19017
    input [7999:0] failure_reason ;
19018
    reg   [8007:0] display_failure ;
19019
    reg   [799:0] display_test ;
19020
begin
19021
    tests_failed = tests_failed + 1 ;
19022
 
19023
    display_failure = {failure_reason, "!"} ;
19024
    while ( display_failure[7999:7992] == 0 )
19025
        display_failure = display_failure << 8 ;
19026
 
19027
    display_test = test_name ;
19028
    while ( display_test[799:792] == 0 )
19029
       display_test = display_test << 8 ;
19030
 
19031
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19032
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
19033
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
19034
    $fdisplay( tb_log_file, " *FAILED* because") ;
19035
    $fdisplay( tb_log_file, " %s", display_failure ) ;
19036
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19037
    $fdisplay( tb_log_file, " " ) ;
19038
 
19039
    `ifdef STOP_ON_FAILURE
19040
    #20 $stop ;
19041
    `endif
19042
end
19043
endtask // test_fail
19044
 
19045
task test_ok ;
19046
    reg [799:0] display_test ;
19047
begin
19048
   tests_successfull = tests_successfull + 1 ;
19049
 
19050
   display_test = test_name ;
19051
   while ( display_test[799:792] == 0 )
19052
       display_test = display_test << 8 ;
19053
 
19054
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19055
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
19056
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
19057
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
19058
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19059
   $fdisplay( tb_log_file, " " ) ;
19060
end
19061
endtask // test_ok
19062
 
19063
task test_summary;
19064
begin
19065
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19066
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
19067
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
19068
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
19069
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19070
    $fclose(tb_log_file) ;
19071
end
19072
endtask
19073
 
19074
endmodule

powered by: WebSVN 2.1.0

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