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

Subversion Repositories pci

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

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 64 mihad
// Revision 1.10  2002/10/11 10:08:57  mihad
43
// Added additional testcase and changed rst name in BIST to trst
44
//
45 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
46
// Added BIST signals for RAMs.
47
//
48 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
49
// Added completion expiration test for WB Slave unit. Changed expiration signalling
50
//
51 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
52
// Oops, never before noticed that OC header is missing
53 52 mihad
//
54 57 mihad
//
55 52 mihad
 
56 15 mihad
`include "pci_constants.v"
57
`include "bus_commands.v"
58
`include "pci_testbench_defines.v"
59
`include "timescale.v"
60
 
61 51 mihad
`ifdef HOST
62
    `ifdef NO_CNF_IMAGE
63
    `else
64
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
65
    `endif
66
`else
67
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
68
`endif
69
 
70 15 mihad
module SYSTEM ;
71
 
72
`include "pci_blue_constants.vh"
73
`include "pci_blue_options.vh"
74
 
75
integer tests_successfull ;
76
integer tests_failed ;
77
integer tb_log_file ;
78
reg [799:0] test_name ;
79
 
80
reg pci_clock ;
81
reg wb_clock ;
82
reg reset ;
83
 
84
wire [4:0] arb_grant_out ;
85
 
86
wire [31:0] AD ;
87
wire [3:0]  CBE ;
88
pullup(INTA) ;
89
pullup(MAS0_REQ) ;
90
pullup(MAS1_REQ) ;
91
pullup(MAS2_REQ) ;
92
pullup(MAS3_REQ) ;
93
 
94
wire MAS0_GNT = ~arb_grant_out[0];
95
wire MAS1_GNT = ~arb_grant_out[1] ;
96
wire MAS2_GNT = ~arb_grant_out[2] ;
97
wire MAS3_GNT = ~arb_grant_out[3] ;
98
 
99
pullup(FRAME) ;
100
pullup(IRDY) ;
101 45 mihad
 
102
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
103
 
104 15 mihad
pullup(DEVSEL) ;
105
pullup(TRDY) ;
106
pullup(STOP) ;
107
wire   PAR ;
108
pullup(PERR) ;
109
pullup(SERR) ;
110
wire [3:0] MAS1_IDSEL ;
111
 
112
pullup lockpu ( LOCK ) ;
113
 
114
wire        RST_O ;
115
wire        INT_O ;
116
reg         INT_I ;
117
wire [31:0] ADR_I ;
118
wire [31:0] SDAT_I ;
119
wire [31:0] SDAT_O ;
120
wire [3:0]  SEL_I ;
121
wire        CYC_I ;
122
wire        STB_I ;
123
wire        WE_I ;
124
wire        CAB_I ;
125
wire        ACK_O ;
126
wire        RTY_O ;
127
wire        ERR_O ;
128
 
129
wire [31:0] ADR_O ;
130
wire [31:0] MDAT_I ;
131
wire [31:0] MDAT_O ;
132
wire [3:0]  SEL_O ;
133
wire        CYC_O ;
134
wire        STB_O ;
135
wire        WE_O ;
136
wire        CAB_O ;
137
wire        ACK_I ;
138
wire        RTY_I ;
139
wire        ERR_I ;
140
 
141 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
142
 
143
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
144
 
145 15 mihad
wire        reset_wb ; // reset to Wb devices
146
 
147 62 mihad
`ifdef PCI_BIST
148
wire SO ;
149
reg  SI ;
150 63 mihad
wire trst = reset_wb ;
151 62 mihad
reg  shift_DR ;
152
reg  capture_DR ;
153
reg  extest ;
154
reg  tck ;
155
`endif
156
 
157 15 mihad
`ifdef GUEST
158
    wire    RST = ~reset ;
159
    assign  reset_wb = RST_O ;
160
`else
161
    pullup(RST) ;
162
    assign  reset_wb = reset ;
163
`endif
164
 
165
`define PCI_BRIDGE_INSTANCE bridge32_top
166
 
167
TOP `PCI_BRIDGE_INSTANCE
168
(
169
    .CLK    ( pci_clock),
170
    .AD     ( AD ),
171
    .CBE    ( CBE ),
172
    .RST    ( RST ),
173
    .INTA   ( INTA ),
174
    .REQ    ( MAS0_REQ ),
175
    .GNT    ( MAS0_GNT ),
176
    .FRAME  ( FRAME ),
177
    .IRDY   ( IRDY ),
178
    .IDSEL  ( TAR0_IDSEL),
179
    .DEVSEL ( DEVSEL ),
180
    .TRDY   ( TRDY ),
181
    .STOP   ( STOP ),
182
    .PAR    ( PAR ),
183
    .PERR   ( PERR ),
184
    .SERR   ( SERR ),
185
 
186
    .CLK_I  ( wb_clock ),
187
    .RST_I  ( reset ),
188
    .RST_O  ( RST_O ),
189
    .INT_I  ( INT_I ),
190
    .INT_O  ( INT_O ),
191
 
192
    // WISHBONE slave interface
193
    .ADR_I  ( ADR_I ),
194
    .SDAT_I ( SDAT_I ),
195
    .SDAT_O ( SDAT_O ),
196
    .SEL_I  ( SEL_I ),
197
    .CYC_I  ( CYC_I ),
198
    .STB_I  ( STB_I ),
199
    .WE_I   ( WE_I ),
200
    .CAB_I  ( CAB_I),
201
    .ACK_O  ( ACK_O ),
202
    .RTY_O  ( RTY_O ),
203
    .ERR_O  ( ERR_O ),
204
 
205
    // WISHBONE master interface
206
    .ADR_O  ( ADR_O ),
207
    .MDAT_I ( MDAT_I ),
208
    .MDAT_O ( MDAT_O ),
209
    .SEL_O  ( SEL_O ),
210
    .CYC_O  ( CYC_O ),
211
    .STB_O  ( STB_O ),
212
    .WE_O   ( WE_O ),
213
    .CAB_O  ( CAB_O ),
214
    .ACK_I  ( ACK_I ),
215
    .RTY_I  ( RTY_I ),
216
    .ERR_I  ( ERR_I )
217 62 mihad
 
218
`ifdef PCI_BIST
219
    ,
220 63 mihad
    .trst       (trst),
221 62 mihad
    .SO         (SO),
222
    .SI         (SI),
223
    .shift_DR   (shift_DR),
224
    .capture_DR (capture_DR),
225
    .extest     (extest),
226
    .tck        (tck)
227
`endif
228 15 mihad
) ;
229
 
230
WB_MASTER_BEHAVIORAL wishbone_master
231
(
232
    .CLK_I(wb_clock),
233
    .RST_I(reset_wb),
234
    .TAG_I(4'b0000),
235
    .TAG_O(),
236
    .ACK_I(ACK_O),
237
    .ADR_O(ADR_I),
238
    .CYC_O(CYC_I),
239
    .DAT_I(SDAT_O),
240
    .DAT_O(SDAT_I),
241
    .ERR_I(ERR_O),
242
    .RTY_I(RTY_O),
243
    .SEL_O(SEL_I),
244
    .STB_O(STB_I),
245
    .WE_O (WE_I),
246
    .CAB_O(CAB_I)
247
);
248
 
249
WB_SLAVE_BEHAVIORAL wishbone_slave
250
(
251
    .CLK_I              (wb_clock),
252
    .RST_I              (reset_wb),
253
    .ACK_O              (ACK_I),
254
    .ADR_I              (ADR_O),
255
    .CYC_I              (CYC_O),
256
    .DAT_O              (MDAT_I),
257
    .DAT_I              (MDAT_O),
258
    .ERR_O              (ERR_I),
259
    .RTY_O              (RTY_I),
260
    .SEL_I              (SEL_O),
261
    .STB_I              (STB_O),
262
    .WE_I               (WE_O),
263
    .CAB_I              (CAB_O)
264
);
265
 
266
integer wbu_mon_log_file_desc ;
267
integer pciu_mon_log_file_desc ;
268
WB_BUS_MON wbu_wb_mon(
269
                    .CLK_I(wb_clock),
270
                    .RST_I(reset_wb),
271
                    .ACK_I(ACK_O),
272
                    .ADDR_O(ADR_I),
273
                    .CYC_O(CYC_I),
274
                    .DAT_I(SDAT_O),
275
                    .DAT_O(SDAT_I),
276
                    .ERR_I(ERR_O),
277
                    .RTY_I(RTY_O),
278
                    .SEL_O(SEL_I),
279
                    .STB_O(STB_I),
280
                    .WE_O (WE_I),
281
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
282
                    .TAG_O(),
283
                    .CAB_O(CAB_I),
284
                    .log_file_desc ( wbu_mon_log_file_desc )
285
                  ) ;
286
 
287
WB_BUS_MON pciu_wb_mon(
288
                    .CLK_I(wb_clock),
289
                    .RST_I(reset_wb),
290
                    .ACK_I(ACK_I),
291
                    .ADDR_O(ADR_O),
292
                    .CYC_O(CYC_O),
293
                    .DAT_I(MDAT_I),
294
                    .DAT_O(MDAT_O),
295
                    .ERR_I(ERR_I),
296
                    .RTY_I(RTY_I),
297
                    .SEL_O(SEL_O),
298
                    .STB_O(STB_O),
299
                    .WE_O (WE_O),
300
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
301
                    .TAG_O(),
302
                    .CAB_O(CAB_O),
303
                    .log_file_desc( pciu_mon_log_file_desc )
304
                  ) ;
305
 
306
// some aditional signals are needed here because of the arbiter
307
reg [3:0] pci_ext_req_prev ;
308
always@(posedge pci_clock)
309
begin
310
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
311
end
312
reg pci_frame_prev ;
313
always@(posedge pci_clock)
314
begin
315
    pci_frame_prev <= FRAME ;
316
end
317
reg pci_irdy_prev ;
318
always@(posedge pci_clock)
319
begin
320
    pci_irdy_prev <= IRDY ;
321
end
322
 
323
pci_blue_arbiter pci_arbiter
324
(
325
  .pci_int_req_direct(1'b0),
326
  .pci_ext_req_prev(pci_ext_req_prev),
327
  .pci_int_gnt_direct_out(arb_grant_out[4]),
328
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
329
  .pci_frame_prev(~pci_frame_prev),
330
  .pci_irdy_prev(~pci_irdy_prev),
331
  .pci_irdy_now(~IRDY),
332
  .arbitration_enable(1'b1),
333
  .pci_clk(pci_clock),
334
  .pci_reset_comb(~RST)
335
);
336
 
337
reg [31:0] target_message ;
338
 
339
// define output enable signals for monitor inputs
340
// real output enable signals
341
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
342
`ifdef ACTIVE_LOW_OE
343
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
344
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
345
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
346
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
347
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
348
                        !devsel_t_s_oe,
349
                        !ad_oe,
350
                        !cbe_oe,
351
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
352
                        ;
353
`else
354
`ifdef ACTIVE_HIGH_OE
355
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
356
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
357
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
358
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
359
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
360
                        devsel_t_s_oe,
361
                        ad_oe,
362
                        cbe_oe,
363
                        `PCI_BRIDGE_INSTANCE.PERR_en}
364
                        ;
365
`endif
366
`endif
367
/*wire [5:0] oe_sigs_0 = {1'b0,
368
                        1'b0,
369
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
370
                        pci_target32.ad_enable,
371
                        1'b0,
372
                        pci_target32.err_enable | pci_target32.r_err_enable
373
                       } ;
374
*/
375
 
376
wire [5:0] oe_sigs_2 ;
377
wire [5:0] oe_sigs_1 ;
378
 
379
// signals which are used by test modules to know what to do
380
triand  test_accepted_l_int, error_event_int;
381
pullup  (test_accepted_l_int), (error_event_int);
382
 
383
wire    pci_reset_comb  = ~RST;
384
wire    pci_ext_clk     = pci_clock;
385
 
386
integer pci_mon_log_file_desc ;
387
pci_bus_monitor monitor32
388
(
389
    .pci_ext_ad                 (AD),
390
    .pci_ext_cbe_l              (CBE),
391
    .pci_ext_par                (PAR),
392
    .pci_ext_frame_l            (FRAME),
393
    .pci_ext_irdy_l             (IRDY),
394
    .pci_ext_devsel_l           (DEVSEL),
395
    .pci_ext_trdy_l             (TRDY),
396
    .pci_ext_stop_l             (STOP),
397
    .pci_ext_perr_l             (PERR),
398
    .pci_ext_serr_l             (SERR),
399
    .pci_real_req_l             (MAS0_REQ),
400
    .pci_real_gnt_l             (MAS0_GNT),
401
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
402
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
403
    .test_error_event           (error_event_int),
404
    .test_observe_r_oe_sigs     (r_oe_sigs),
405
    .test_observe_0_oe_sigs     (6'h00),
406
    .test_observe_1_oe_sigs     (oe_sigs_1),
407
    .test_observe_2_oe_sigs     (oe_sigs_2),
408
    .test_observe_3_oe_sigs     (6'h00),
409
    .pci_ext_reset_l            (RST),
410
    .pci_ext_clk                (pci_clock),
411
    .log_file_desc              (pci_mon_log_file_desc)
412
) ;
413
 
414
reg [2:0]  test_master_number ;
415
reg [31:0] test_address ;
416
reg [3:0]  test_command ;
417
reg [31:0] test_data ;
418
reg [3:0]  test_byte_enables_l ;
419
reg [9:0]  test_size ;
420
reg        test_make_addr_par_error ;
421
reg        test_make_data_par_error ;
422
reg [3:0]  test_master_initial_wait_states ;
423
reg [3:0]  test_master_subsequent_wait_states ;
424
reg [3:0]  test_target_initial_wait_states ;
425
reg [3:0]  test_target_subsequent_wait_states ;
426
reg [1:0]  test_target_devsel_speed ;
427
reg        test_fast_back_to_back ;
428
reg [2:0]  test_target_termination ;
429
reg        test_expect_master_abort ;
430
reg        test_start ;
431
reg [25:0] test_target_response ;
432
 
433
wire [31:0] master2_received_data ;
434
wire        master2_received_data_valid ;
435
reg         master2_check_received_data ;
436
pci_behaviorial_device pci_behaviorial_device2
437
(
438
    .pci_ext_ad(AD),
439
    .pci_ext_cbe_l(CBE),
440
    .pci_ext_par(PAR),
441
    .pci_ext_frame_l(FRAME),
442
    .pci_ext_irdy_l(IRDY),
443
    .pci_ext_devsel_l(DEVSEL),
444
    .pci_ext_trdy_l(TRDY),
445
    .pci_ext_stop_l(STOP),
446
    .pci_ext_perr_l(PERR),
447
    .pci_ext_serr_l(SERR),
448
    .pci_ext_idsel(TAR2_IDSEL),
449
    .pci_ext_inta_l(INTA),
450
    .pci_ext_req_l(MAS2_REQ),
451
    .pci_ext_gnt_l(MAS2_GNT),
452
    .pci_ext_reset_l(RST),
453
    .pci_ext_clk(pci_clock),
454
 
455
// Signals used by the test bench instead of using "." notation
456
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
457
    .test_master_number                 (test_master_number[2:0]),
458
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
459
    .test_command                       (test_command[3:0]),
460
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
461
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
462
    .test_size                          (test_size),
463
    .test_make_addr_par_error           (test_make_addr_par_error),
464
    .test_make_data_par_error           (test_make_data_par_error),
465
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
466
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
467
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
468
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
469
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
470
    .test_fast_back_to_back             (test_fast_back_to_back),
471
    .test_target_termination            (test_target_termination[2:0]),
472
    .test_expect_master_abort           (test_expect_master_abort),
473
    .test_start                         (test_start),
474
    .test_accepted_l                    (test_accepted_l_int),
475
    .test_error_event                   (error_event_int),
476
    .test_device_id                     (`Test_Master_2),
477
    .test_target_response               (test_target_response),
478
 
479
    .master_received_data               (master2_received_data),
480
    .master_received_data_valid         (master2_received_data_valid),
481
    .master_check_received_data         (master2_check_received_data)
482
);
483
 
484
wire [31:0] master1_received_data ;
485
wire        master1_received_data_valid ;
486
reg         master1_check_received_data ;
487
pci_behaviorial_device pci_behaviorial_device1
488
(
489
    .pci_ext_ad(AD),
490
    .pci_ext_cbe_l(CBE),
491
    .pci_ext_par(PAR),
492
    .pci_ext_frame_l(FRAME),
493
    .pci_ext_irdy_l(IRDY),
494
    .pci_ext_devsel_l(DEVSEL),
495
    .pci_ext_trdy_l(TRDY),
496
    .pci_ext_stop_l(STOP),
497
    .pci_ext_perr_l(PERR),
498
    .pci_ext_serr_l(SERR),
499
    .pci_ext_idsel(TAR1_IDSEL),
500
    .pci_ext_inta_l(INTA),
501
    .pci_ext_req_l(MAS1_REQ),
502
    .pci_ext_gnt_l(MAS1_GNT),
503
    .pci_ext_reset_l(RST),
504
    .pci_ext_clk(pci_clock),
505
 
506
// Signals used by the test bench instead of using "." notation
507
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
508
    .test_master_number                 (test_master_number[2:0]),
509
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
510
    .test_command                       (test_command[3:0]),
511
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
512
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
513
    .test_size                          (test_size),
514
    .test_make_addr_par_error           (test_make_addr_par_error),
515
    .test_make_data_par_error           (test_make_data_par_error),
516
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
517
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
518
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
519
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
520
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
521
    .test_fast_back_to_back             (test_fast_back_to_back),
522
    .test_target_termination            (test_target_termination[2:0]),
523
    .test_expect_master_abort           (test_expect_master_abort),
524
    .test_start                         (test_start),
525
    .test_accepted_l                    (test_accepted_l_int),
526
    .test_error_event                   (error_event_int),
527
    .test_device_id                     (`Test_Master_1),
528
    .test_target_response               (test_target_response),
529
 
530
    .master_received_data               (master1_received_data),
531
    .master_received_data_valid         (master1_received_data_valid),
532
    .master_check_received_data         (master1_check_received_data)
533
);
534
 
535
pci_unsupported_commands_master ipci_unsupported_commands_master
536
(
537
    .CLK    ( pci_clock),
538
    .AD     ( AD ),
539
    .CBE    ( CBE ),
540
    .RST    ( RST ),
541
    .REQ    ( MAS3_REQ ),
542
    .GNT    ( MAS3_GNT ),
543
    .FRAME  ( FRAME ),
544
    .IRDY   ( IRDY ),
545
    .DEVSEL ( DEVSEL ),
546
    .TRDY   ( TRDY ),
547
    .STOP   ( STOP ),
548
    .PAR    ( PAR )
549
) ;
550
 
551 45 mihad
`ifdef HOST
552
 
553
reg     [1:0]   conf_cyc_type1_target_response ;
554
reg     [31:0]  conf_cyc_type1_target_data ;
555
reg     [7:0]   conf_cyc_type1_target_bus_num ;
556
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
557
 
558
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
559
(
560
    .CLK              ( pci_clock),
561
    .AD               ( AD ),
562
    .CBE              ( CBE ),
563
    .RST              ( RST ),
564
    .FRAME            ( FRAME ),
565
    .IRDY             ( IRDY ),
566
    .DEVSEL           ( DEVSEL ),
567
    .TRDY             ( TRDY ),
568
    .STOP             ( STOP ),
569
    .PAR              ( PAR ),
570
 
571
    .response         ( conf_cyc_type1_target_response ),
572
    .data_out         ( conf_cyc_type1_target_data ),
573
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
574
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
575
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
576
    .bus_number       ( conf_cyc_type1_target_bus_num )
577
);
578
`endif
579
 
580 15 mihad
// pci clock generator
581 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
582
    always@(posedge wb_clock)
583
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
584
 
585
    always@(negedge wb_clock)
586
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
587 15 mihad
`else
588 63 mihad
    always
589
    `ifdef PCI33
590
        #15 pci_clock = ~pci_clock ;
591
    `else
592
    `ifdef PCI66
593
        #7.5 pci_clock = ~pci_clock ;
594
    `endif
595
    `endif
596 15 mihad
`endif
597
 
598
// WISHBONE clock generation
599 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
600
always@(posedge pci_clock)
601
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
602 15 mihad
 
603 63 mihad
always@(negedge pci_clock)
604
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
605
 
606
`else
607
    always
608
        #(((1/`WB_FREQ)/2)) wb_clock = !wb_clock ;
609
`endif
610
 
611 15 mihad
// Make test name visible when the Master starts working on it
612
reg     [79:0] present_test_name;
613
reg     [79:0] next_test_name;
614
wire    test_accepted = ~test_accepted_l_int;
615
always @(posedge test_accepted)
616
begin
617
    present_test_name <= next_test_name;
618
end
619
 
620
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
621
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
622
 
623
// basic configuration parameters for both behavioral devices
624
parameter [2:0] Master_ID_A                           = `Test_Master_1;
625
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
626
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
627
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
628
 
629
parameter [2:0] Master_ID_B                           = `Test_Master_2;
630
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
631
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
632
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
633
 
634
// basic configuration parameters for REAL device
635
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
636
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
637
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
638
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
639
 
640
// reg  [2:0]   ack_err_rty_termination ;
641
// reg          wait_cycles ;
642
// reg  [7:0]   num_of_retries ;
643
 
644
//reg [19:0] pci_config_base ;
645
reg [7:0] system_burst_size ;
646
reg [7:0] bridge_latency ;
647
integer   target_mem_image ;
648
integer   target_io_image ;
649
 
650
initial
651
begin
652 62 mihad
 
653
`ifdef PCI_BIST
654
    SI          = 0 ;
655
    shift_DR    = 0 ;
656
    capture_DR  = 0 ;
657
    extest      = 0 ;
658
    tck         = 0 ;
659
`endif
660 15 mihad
    next_test_name[79:0] <= "Nowhere___";
661
    reset = 1'b1 ;
662
    pci_clock = 1'b0 ;
663
    wb_clock  = 1'b1 ;
664
    target_message = 32'h0000_0000 ;
665
//  num_of_retries = 8'h01 ;
666
//  ack_err_rty_termination = 3'b100 ;
667
//  wait_cycles = 1'b0 ;
668
 
669
    // system paameters
670
    system_burst_size = 16 ;
671
    bridge_latency    = 8 ;
672
 
673
    // set initial values for controling the behavioral PCI master
674
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
675
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
676
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
677
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
678
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
679
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
680
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
681
 
682
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
683
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
684
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
685
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
686
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
687
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
688
 
689
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
690
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
691
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
692
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
693
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
694
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
695
 
696
    test_master_number = `Test_Master_2 ;
697
    test_address = 32'h0000_0000 ;
698
    test_command = `BC_RESERVED0 ;
699
    test_data = 32'h0000_0000 ;
700
    test_byte_enables_l   = 4'hF ;
701
    test_size = 0 ;
702
    test_make_addr_par_error = 0 ;
703
    test_make_data_par_error = 0;
704
    test_master_initial_wait_states = 0 ;
705
    test_master_subsequent_wait_states = 0 ;
706
    test_target_initial_wait_states = 0 ;
707
    test_target_subsequent_wait_states = 0;
708
    test_target_devsel_speed = `Test_Devsel_Fast ;
709
    test_fast_back_to_back = 0 ;
710
    test_target_termination = `Test_Target_Normal_Completion ;
711
    test_expect_master_abort = 0 ;
712
    test_start = 0 ;
713
    test_target_response = 0 ;
714
 
715
    master1_check_received_data = 0 ;
716
    master2_check_received_data = 0 ;
717
 
718 45 mihad
    `ifdef HOST
719
        conf_cyc_type1_target_response = 0 ;
720
        conf_cyc_type1_target_data = 0 ;
721
        conf_cyc_type1_target_bus_num = 255 ;
722
    `endif
723 15 mihad
 
724
    // fill memory and IO data with random values
725
    fill_memory ;
726
 
727
    INT_I = 0 ;
728
 
729
    // extract from constants which target image can be used as IO and which as memory
730
    `ifdef HOST
731
        target_mem_image = 1 ;
732
        target_io_image  = 1 ;
733
    `else
734
        target_mem_image = -1 ;
735
        target_io_image     = -1 ;
736
        if ( `PCI_BA1_MEM_IO === 0 )
737
            target_mem_image = 1 ;
738
        else
739
            target_io_image = 1 ;
740
 
741
        if ( target_mem_image === -1 )
742
        begin
743
            `ifdef PCI_IMAGE2
744
                if ( `PCI_BA2_MEM_IO === 0 )
745
                    target_mem_image = 2 ;
746
                else if ( target_io_image === -1 )
747
                    target_io_image = 2 ;
748
            `endif
749
        end
750
 
751
        if ( target_mem_image === -1 )
752
        begin
753
            `ifdef PCI_IMAGE3
754
                if ( `PCI_BA3_MEM_IO === 0 )
755
                    target_mem_image = 3 ;
756
                else if ( target_io_image === -1 )
757
                    target_io_image = 3 ;
758
            `endif
759
        end
760
 
761
        if ( target_mem_image === -1 )
762
        begin
763
            `ifdef PCI_IMAGE4
764
                if ( `PCI_BA4_MEM_IO === 0 )
765
                    target_mem_image = 4 ;
766
                else if ( target_io_image === -1 )
767
                    target_io_image = 4 ;
768
            `endif
769
        end
770
 
771
        if ( target_mem_image === -1 )
772
        begin
773
            `ifdef PCI_IMAGE5
774
                if ( `PCI_BA5_MEM_IO === 0 )
775
                    target_mem_image = 5 ;
776
                else if ( target_io_image === -1 )
777
                    target_io_image = 5 ;
778
            `endif
779
        end
780
    `endif
781
 
782
    tests_successfull = 0 ;
783
    tests_failed = 0 ;
784
 
785
    tb_log_file = $fopen("../log/pci_tb.log") ;
786
 
787
    if ( tb_log_file < 2 )
788
    begin
789
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
790
        $finish ;
791
    end
792
 
793
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
794
    $fdisplay( tb_log_file,"" ) ;
795
 
796
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
797
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
798
 
799
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
800
    begin
801
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
802
        $finish ;
803
    end
804
 
805
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
806
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
807
 
808
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
809
    if ( pci_mon_log_file_desc < 2 )
810
    begin
811
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
812
        $finish ;
813
    end
814
 
815
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
816
 
817
    run_tests ;
818
end
819
 
820
task fill_memory ;
821
    integer temp_index ;
822
begin
823
    // fill write memories with random data
824
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
825
    begin
826
        wmem_data[temp_index[9:0]] = $random ;
827 26 mihad
        # 1;
828 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
829 26 mihad
        # 1;
830 15 mihad
    end
831
    // fill WB slave behavioral MEMORY
832
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
833
    begin
834
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
835
        # 1;
836
    end
837
end
838
endtask // fill_memory
839
 
840
reg [2:0] tb_init_waits ;
841
reg [2:0] tb_subseq_waits ;
842
reg [2:0] tb_target_decode_speed ;
843
 
844
task run_tests ;
845
begin
846
    // first - reset logic
847
    do_reset ;
848 62 mihad
 
849
    // if BIST is implemented, give it a go
850
`ifdef PCI_BIST
851
    run_bist_test ;
852
`endif
853 45 mihad
    test_initial_conf_values ;
854
 
855 15 mihad
    next_test_name[79:0] <= "Initing...";
856
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
857
 
858
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
859
    begin
860
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
861
        begin
862
 
863
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
864
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
865
 
866
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
867
            begin
868
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
869
 
870
                `ifdef HOST
871
                    configure_bridge_target ;
872
                    find_pci_devices ;
873 45 mihad
                    test_configuration_cycle_target_abort ;
874
                    test_configuration_cycle_type1_generation ;
875 15 mihad
                `endif
876
 
877
                @(posedge pci_clock) ;
878
                configure_target(1) ;
879
                @(posedge pci_clock) ;
880
                configure_target(2) ;
881
 
882
                `ifdef GUEST
883
                    configure_bridge_target ;
884
                `endif
885
 
886
               next_test_name[79:0] <= "WB_SLAVE..";
887
 
888
                $display("Testing WISHBONE slave images' features!") ;
889
                test_wb_image(1) ;
890
 
891
                `ifdef WB_IMAGE2
892
                    test_wb_image(2) ;
893
                `else
894
                    $display(" WB IMAGE 2 not implemented! ") ;
895
                `endif
896
 
897
                `ifdef WB_IMAGE3
898
                    test_wb_image(3) ;
899
                `else
900
                    $display(" WB IMAGE 3 not implemented! ") ;
901
                `endif
902
 
903
                `ifdef WB_IMAGE4
904
                    test_wb_image(4) ;
905
                `else
906
                    $display(" WB IMAGE 4 not implemented! ") ;
907
                `endif
908
 
909
                `ifdef WB_IMAGE5
910
                    test_wb_image(5) ;
911
                `else
912
                    $display(" WB IMAGE 5 not implemented! ") ;
913
                `endif
914
 
915
                wb_slave_errors ;
916
                wb_to_pci_error_handling ;
917
 
918
                parity_checking ;
919
 
920
                wb_to_pci_transactions ;
921
 
922
                `ifdef HOST
923
                iack_cycle ;
924
                `endif
925
 
926
            end
927 57 mihad
 
928 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
929
        `else
930 57 mihad
            master_completion_expiration ;
931 63 mihad
        `endif
932 57 mihad
 
933 15 mihad
            $display(" ") ;
934
            $display("WB slave images' tests finished!") ;
935
 
936
            $display("########################################################################") ;
937
            $display("########################################################################") ;
938
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
939
            $display("########################################################################") ;
940
            $display("########################################################################") ;
941
 
942
            $display("Testing PCI target images' features!") ;
943
            configure_bridge_target_base_addresses ;
944
 
945 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
946
                test_conf_cycle_type1_reference ;
947
            `endif
948
 
949 15 mihad
            `ifdef HOST
950
             `ifdef NO_CNF_IMAGE
951
              `ifdef PCI_IMAGE0
952
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
953
            test_pci_image(0) ;
954
              `else
955
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
956
              `endif
957
             `else
958
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
959
             `endif
960
            `endif
961
 
962
            $display("PCI image 1 is ALWAYS implemented!") ;
963
            test_pci_image(1) ;
964
 
965
            `ifdef PCI_IMAGE2
966
            $display("PCI image 2 is implemented!") ;
967
            test_pci_image(2) ;
968
            `else
969
            $display("PCI image 2 is NOT implemented!") ;
970
            `endif
971
 
972
            `ifdef PCI_IMAGE3
973
            $display("PCI image 3 is implemented!") ;
974
            test_pci_image(3) ;
975
            `else
976
            $display("PCI image 3 is NOT implemented!") ;
977
            `endif
978
 
979
            `ifdef PCI_IMAGE4
980
            $display("PCI image 4 is implemented!") ;
981
            test_pci_image(4) ;
982
            `else
983
            $display("PCI image 4 is NOT implemented!") ;
984
            `endif
985
 
986
            `ifdef PCI_IMAGE5
987
            $display("PCI image 5 is implemented!") ;
988
            test_pci_image(5) ;
989
            `else
990
            $display("PCI image 5 is NOT implemented!") ;
991
            `endif
992
 
993
            test_wb_error_rd ;
994
 
995
            target_fast_back_to_back ;
996
            target_disconnects ;
997
 
998
            if ( target_io_image !== -1 )
999
                test_target_abort( target_io_image ) ;
1000
            $display(" ") ;
1001
            $display("PCI target images' tests finished!") ;
1002
 
1003
            transaction_ordering ;
1004 33 mihad
 
1005 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1006
        `else
1007 33 mihad
            target_completion_expiration ;
1008 63 mihad
        `endif
1009
 
1010 15 mihad
            $display(" ") ;
1011
            $display("PCI transaction ordering tests finished!") ;
1012
        end
1013
    end
1014
 
1015 63 mihad
    `ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
1016
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1017
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1018
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1019
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1020
 
1021
        `ifdef HOST
1022
            configure_bridge_target ;
1023
        `endif
1024
 
1025
        @(posedge pci_clock) ;
1026
        configure_target(1) ;
1027
        @(posedge pci_clock) ;
1028
        configure_target(2) ;
1029
 
1030
        `ifdef GUEST
1031
            configure_bridge_target ;
1032
        `endif
1033
 
1034
        target_special_corner_case_test ;
1035
    `endif
1036
 
1037 15 mihad
    test_summary ;
1038
 
1039
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1040
    $stop ;
1041
end
1042
endtask // run_tests
1043
 
1044
task do_reset;
1045
begin
1046
    next_test_name[79:0] <= "Reset.....";
1047
 
1048
    reset = 1'b1 ;
1049
    #100 ;
1050
    `ifdef HOST
1051
        @(posedge wb_clock) ;
1052
    `else
1053
    `ifdef GUEST
1054
        @(posedge pci_clock) ;
1055
    `endif
1056
    `endif
1057
 
1058
    reset <= 1'b0 ;
1059
 
1060 45 mihad
    `ifdef HOST
1061
        @(posedge wb_clock) ;
1062
    `else
1063
    `ifdef GUEST
1064
        @(posedge pci_clock) ;
1065
    `endif
1066
    `endif
1067
 
1068 15 mihad
end
1069
endtask
1070
 
1071
/*############################################################################
1072
WB SLAVE UNIT tasks
1073
===================
1074
############################################################################*/
1075
 
1076
task configure_target ;
1077 45 mihad
    input [1:0]  beh_dev_num ;
1078 15 mihad
    reg   [31:0] base_address1 ;
1079
    reg   [31:0] base_address2 ;
1080
    reg   [2:0]  Master_ID;
1081
    reg   [31:0] Target_Config_Addr;
1082 45 mihad
    reg   [4:0]  device_num ;
1083 15 mihad
begin
1084 45 mihad
    if (beh_dev_num === 1)
1085 15 mihad
    begin
1086
        base_address1       = `BEH_TAR1_MEM_START ;
1087
        base_address2       = `BEH_TAR1_IO_START  ;
1088
        Master_ID           = `Test_Master_2 ;
1089
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1090 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1091 15 mihad
    end
1092
    else
1093 45 mihad
    if (beh_dev_num === 2)
1094 15 mihad
    begin
1095
        base_address1       = `BEH_TAR2_MEM_START ;
1096
        base_address2       = `BEH_TAR2_IO_START  ;
1097
        Master_ID           = `Test_Master_1 ;
1098
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1099 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1100 15 mihad
    end
1101
 
1102
    // write target's base addresses
1103
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1104
    // type 0 cycle, byte enables, base address
1105
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1106
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1107
 
1108
    // enable target's response and master
1109
    // enable parity errors, disable system error
1110
 
1111
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1112
 
1113
end
1114
endtask //configure_target
1115
 
1116
task test_wb_image ;
1117
    input [2:0]  image_num ;
1118
    reg   [11:0] ctrl_offset ;
1119
    reg   [11:0] ba_offset ;
1120
    reg   [11:0] am_offset ;
1121
    reg   [11:0] ta_offset ;
1122
    reg   [11:0] err_cs_offset ;
1123
    reg `WRITE_STIM_TYPE write_data ;
1124
    reg `READ_STIM_TYPE  read_data ;
1125
    reg `READ_RETURN_TYPE read_status ;
1126
 
1127
    reg `WRITE_RETURN_TYPE write_status ;
1128
    reg `WB_TRANSFER_FLAGS write_flags ;
1129
    reg [31:0] temp_val ;
1130
    reg        ok   ;
1131
    reg [11:0] pci_ctrl_offset ;
1132
    reg [31:0] image_base ;
1133
    reg [31:0] target_address ;
1134
    reg [31:0] translation_address ;
1135
    integer    i ;
1136
    integer    j ;
1137
begin:main
1138
    pci_ctrl_offset = 12'h4 ;
1139
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1140
    // image 0 can only be configuration image - start with 1
1141
    if (image_num === 1)
1142
    begin
1143
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1144
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1145
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1146
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1147
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1148
    end
1149
    else if (image_num === 2)
1150
    begin
1151
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1152
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1153
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1154
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1155
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1156
    end
1157
    else if (image_num === 3)
1158
    begin
1159
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1160
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1161
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1162
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1163
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1164
    end
1165
    else if (image_num === 4)
1166
    begin
1167
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1168
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1169
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1170
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1171
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1172
    end
1173
    else if (image_num === 5)
1174
    begin
1175
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1176
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1177
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1178
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1179
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1180
    end
1181
    else
1182
    begin
1183
        test_name   = "WB IMAGES' FEATURES TEST" ;
1184
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1185
        disable main ;
1186
    end
1187
 
1188
    target_address  = `BEH_TAR1_MEM_START ;
1189
    image_base      = 0 ;
1190
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1191
 
1192
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1193
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1194
    write_flags                      = 0 ;
1195
    write_flags`INIT_WAITS           = tb_init_waits ;
1196
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1197
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1198
 
1199
    test_name = "WB IMAGE CONFIGURATION" ;
1200
    // enable master & target operation
1201
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1202
    if ( ok !== 1 )
1203
    begin
1204
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1205
        test_fail("write to PCI Device Control register didn't succeede");
1206
        disable main ;
1207
    end
1208
 
1209
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1210
    if ( ok !== 1 )
1211
    begin
1212
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1213
        test_fail("write to WB Error Control and Status register didn't succeede");
1214
        disable main ;
1215
    end
1216
 
1217
    // prepare image control register
1218
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1219
    if ( ok !== 1 )
1220
    begin
1221
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1222
        test_fail("write to WB Image Control register didn't succeede");
1223
        disable main ;
1224
    end
1225
 
1226
    // prepare base address register
1227
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1228
    if ( ok !== 1 )
1229
    begin
1230
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1231
        test_fail("write to WB Base Address register didn't succeede");
1232
        disable main ;
1233
    end
1234
 
1235
    // write address mask register
1236
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1237
    if ( ok !== 1 )
1238
    begin
1239
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1240
        test_fail("write to WB Address Mask register didn't succeede");
1241
        disable main ;
1242
    end
1243
 
1244
    fork
1245
    begin
1246
        write_data`WRITE_ADDRESS = target_address ;
1247
        write_data`WRITE_DATA    = wmem_data[0] ;
1248
        write_data`WRITE_SEL     = 4'hF ;
1249
 
1250
        // handle retries from now on
1251
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1252
 
1253
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1254
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1255
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1256
        begin
1257
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1258
            test_fail("WB Slave state machine failed to post single memory write");
1259
            disable main ;
1260
        end
1261
 
1262
        // read written data back
1263
        read_data`READ_ADDRESS  = target_address ;
1264
        read_data`READ_SEL      = 4'hF ;
1265
        read_data`READ_TAG_STIM = 0 ;
1266
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1267
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1268
        begin
1269
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1270
            test_fail("PCI bridge didn't process the read as expected");
1271
            disable main ;
1272
        end
1273
 
1274
        if (read_status`READ_DATA !== wmem_data[0])
1275
        begin
1276
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1277
            test_fail("PCI bridge returned unexpected Read Data");
1278
        end
1279
        else
1280
            test_ok ;
1281
    end
1282
    begin
1283
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1284
        if ( ok !== 1 )
1285
        begin
1286
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1287
        end
1288
        else
1289
            test_ok ;
1290
 
1291
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1292
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1293
        if ( ok !== 1 )
1294
        begin
1295
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1296
        end
1297
    end
1298
    join
1299
 
1300
    // if address translation is implemented - try it out
1301
    translation_address = image_base ;
1302
    `ifdef ADDR_TRAN_IMPL
1303
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1304
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1305
    if ( ok !== 1 )
1306
    begin
1307
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1308
        test_fail("write to WB Image Translation Address Register failed") ;
1309
        disable main ;
1310
    end
1311
 
1312
    target_address  = `BEH_TAR2_MEM_START ;
1313
    image_base      = 0 ;
1314
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1315
 
1316
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1317
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1318
 
1319
    write_flags                      = 0 ;
1320
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1321
 
1322
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1323
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1324
    if ( ok !== 1 )
1325
    begin
1326
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1327
        test_fail("write to WB Image Base Address Register failed") ;
1328
        disable main ;
1329
    end
1330
 
1331
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1332
    // enable address translation
1333
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1334
    if ( ok !== 1 )
1335
    begin
1336
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1337
        test_fail("write to WB Image Control Register failed") ;
1338
        disable main ;
1339
    end
1340
 
1341
    `endif
1342
 
1343
    fork
1344
    begin
1345
        write_data`WRITE_ADDRESS = target_address + 4 ;
1346
        write_data`WRITE_DATA    = wmem_data[1] ;
1347
        write_data`WRITE_SEL     = 4'hF ;
1348
 
1349
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1350
 
1351
        `ifdef ADDR_TRAN_IMPL
1352
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1353
        `else
1354
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1355
        `endif
1356
 
1357
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1358
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1359
        begin
1360
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1361
            test_fail("WB Slave state machine failed to post single memory write") ;
1362
            disable main ;
1363
        end
1364
 
1365
        // read written data back
1366
        read_data`READ_ADDRESS  = target_address + 4 ;
1367
        read_data`READ_SEL      = 4'hF ;
1368
        read_data`READ_TAG_STIM = 0 ;
1369
 
1370
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1371
 
1372
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1373
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1374
        begin
1375
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1376
            test_fail("PCI bridge failed to process single delayed memory read") ;
1377
            disable main ;
1378
        end
1379
 
1380
        if (read_status`READ_DATA !== wmem_data[1])
1381
        begin
1382
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1383
            test_fail("PCI bridge returned unexpected Read Data");
1384
        end
1385
        else
1386
            test_ok ;
1387
    end
1388
    begin
1389
        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 ) ;
1390
        if ( ok !== 1 )
1391
        begin
1392
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1393
        end
1394
        else
1395
            test_ok ;
1396
 
1397
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1398
        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 ) ;
1399
        if ( ok !== 1 )
1400
        begin
1401
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1402
        end
1403
    end
1404
    join
1405
 
1406
    // 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
1407
    // prepare write data
1408
    for ( i = 0 ; i < 6 ; i = i + 1 )
1409
    begin
1410
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1411
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1412
        write_data`WRITE_SEL     = 4'hF ;
1413
        wishbone_master.blk_write_data[i] = write_data ;
1414
    end
1415
 
1416
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1417
    write_flags`WB_TRANSFER_CAB    = 1 ;
1418
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1419
 
1420
    fork
1421
    begin
1422
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1423
        wishbone_master.wb_block_write(write_flags, write_status) ;
1424
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1425
        begin
1426
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1427
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1428
            disable main ;
1429
        end
1430
    end
1431
    begin
1432
        pci_transaction_progress_monitor( wb_to_pci_addr_convert( target_address + 8, translation_address, 1'b1 ), `BC_MEM_WRITE, 6, 0, 1'b1, 0, 0, ok ) ;
1433
        if ( ok !== 1 )
1434
        begin
1435
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1436
        end
1437
        else
1438
            test_ok ;
1439
    end
1440
    join
1441
 
1442
    // set burst size and latency timer
1443
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1444
 
1445
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1446
    write_flags`WB_TRANSFER_CAB    = 1 ;
1447
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1448
 
1449
    // prepare read data
1450
    for ( i = 0 ; i < 4 ; i = i + 1 )
1451
    begin
1452
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1453
        read_data`READ_SEL     = 4'hF ;
1454
        wishbone_master.blk_read_data_in[i] = read_data ;
1455
    end
1456
 
1457
    fork
1458
    begin
1459
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1460
        wishbone_master.wb_block_read(write_flags, read_status) ;
1461
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1462
        begin
1463
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1464
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1465
            disable main ;
1466
        end
1467
 
1468
        // check data read from target
1469
        for ( i = 0 ; i < 4 ; i = i + 1 )
1470
        begin
1471
            read_status = wishbone_master.blk_read_data_out[i] ;
1472
            if (read_status`READ_DATA !== wmem_data[2 + i])
1473
            begin
1474
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1475
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1476
            end
1477
        end
1478
    end
1479
    begin
1480
        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 ) ;
1481
        if ( ok !== 1 )
1482
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1483
        else
1484
            test_ok ;
1485
 
1486
        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 ) ;
1487
        if ( ok !== 1 )
1488
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1489
        else
1490
            test_ok ;
1491
 
1492
        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 ) ;
1493
        if ( ok !== 1 )
1494
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1495
        else
1496
            test_ok ;
1497
 
1498
        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 ) ;
1499
        if ( ok !== 1 )
1500
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1501
        else
1502
            test_ok ;
1503
 
1504
    end
1505
    join
1506
 
1507
    // now repeat this same burst read with various image features enabled or disabled
1508
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1509
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1510
    if (ok !== 1)
1511
    begin
1512
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1513
        test_fail("write to WB Image control register failed") ;
1514
        disable main ;
1515
    end
1516
 
1517
    fork
1518
    begin
1519
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1520
        wishbone_master.wb_block_read(write_flags, read_status) ;
1521
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1522
        begin
1523
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1524
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1525
            disable main ;
1526
        end
1527
 
1528
        // check data read from target
1529
        for ( i = 0 ; i < 4 ; i = i + 1 )
1530
        begin
1531
            read_status = wishbone_master.blk_read_data_out[i] ;
1532
            if (read_status`READ_DATA !== wmem_data[2 + i])
1533
            begin
1534
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1535
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1536
            end
1537
            else
1538
                test_ok ;
1539
        end
1540
    end
1541
    begin
1542
        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 ) ;
1543
        if ( ok !== 1 )
1544
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1545
    end
1546
    join
1547
 
1548
    read_data`READ_ADDRESS  = target_address ;
1549
    read_data`READ_SEL      = 4'hF ;
1550
    read_data`READ_TAG_STIM = 0 ;
1551
 
1552
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1553
    fork
1554
    begin
1555
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1556
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1557
        begin
1558
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1559
            test_fail("delayed single memory read wasn't processed as expected") ;
1560
            disable main ;
1561
        end
1562
 
1563
        if (read_status`READ_DATA !== wmem_data[0])
1564
        begin
1565
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1566
            test_fail("delayed single memory read data value returned was not as expected") ;
1567
        end
1568
        else
1569
            test_ok ;
1570
    end
1571
    begin
1572
        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 ) ;
1573
        if ( ok !== 1 )
1574
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1575
    end
1576
    join
1577
 
1578
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1579
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1580
    if (ok !== 1)
1581
    begin
1582
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1583
        test_fail("write to WB Image control register failed") ;
1584
        disable main ;
1585
    end
1586
 
1587
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1588
    fork
1589
    begin
1590
        wishbone_master.wb_block_read(write_flags, read_status) ;
1591
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1592
        begin
1593
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1594
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1595
            disable main ;
1596
        end
1597
 
1598
        // check data read from target
1599
        for ( i = 0 ; i < 4 ; i = i + 1 )
1600
        begin
1601
            read_status = wishbone_master.blk_read_data_out[i] ;
1602
            if (read_status`READ_DATA !== wmem_data[2 + i])
1603
            begin
1604
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1605
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1606
            end
1607
            else
1608
                test_ok ;
1609
        end
1610
    end
1611
    begin
1612
        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 ) ;
1613
        if ( ok !== 1 )
1614
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1615
    end
1616
    join
1617
 
1618
    read_data`READ_ADDRESS  = target_address + 4 ;
1619
    read_data`READ_SEL      = 4'hF ;
1620
    read_data`READ_TAG_STIM = 0 ;
1621
 
1622
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1623
    fork
1624
    begin
1625
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1626
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1627
        begin
1628
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1629
            test_fail("delayed single memory read wasn't processed as expected") ;
1630
            disable main ;
1631
        end
1632
 
1633
        if (read_status`READ_DATA !== wmem_data[1])
1634
        begin
1635
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1636
            test_fail("delayed single memory read data value returned was not as expected") ;
1637
        end
1638
        else
1639
            test_ok ;
1640
    end
1641
    begin
1642
        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 ) ;
1643
        if ( ok !== 1 )
1644
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1645
    end
1646
    join
1647
 
1648
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1649
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1650
    if (ok !== 1)
1651
    begin
1652
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1653
        test_fail("write to WB Image control register failed") ;
1654
        disable main ;
1655
    end
1656
 
1657
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1658
    fork
1659
    begin
1660
        wishbone_master.wb_block_read(write_flags, read_status) ;
1661
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1662
        begin
1663
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1664
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1665
            disable main ;
1666
        end
1667
 
1668
        // check data read from target
1669
        for ( i = 0 ; i < 4 ; i = i + 1 )
1670
        begin
1671
            read_status = wishbone_master.blk_read_data_out[i] ;
1672
            if (read_status`READ_DATA !== wmem_data[2 + i])
1673
            begin
1674
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1675
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1676
            end
1677
            else
1678
                test_ok ;
1679
        end
1680
    end
1681
    begin
1682
        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 ) ;
1683
        if ( ok !== 1 )
1684
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1685
    end
1686
    join
1687
 
1688
    read_data`READ_ADDRESS  = target_address + 8 ;
1689
    read_data`READ_SEL      = 4'hF ;
1690
    read_data`READ_TAG_STIM = 0 ;
1691
 
1692
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1693
    fork
1694
    begin
1695
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1696
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1697
        begin
1698
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1699
            test_fail("delayed single memory read wasn't processed as expected") ;
1700
            disable main ;
1701
        end
1702
 
1703
        if (read_status`READ_DATA !== wmem_data[2])
1704
        begin
1705
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1706
            test_fail("delayed single memory read data value returned was not as expected") ;
1707
        end
1708
        else
1709
            test_ok ;
1710
    end
1711
    begin
1712
        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 ) ;
1713
        if ( ok !== 1 )
1714
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1715
    end
1716
    join
1717
 
1718
    // map image to IO space
1719
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1720
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1721
    if ( ok !== 1 )
1722
    begin
1723
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1724
        test_fail("write to WB Image Base Address register failed") ;
1725
        disable main ;
1726
    end
1727
 
1728
    write_data`WRITE_ADDRESS = target_address ;
1729
    write_data`WRITE_DATA    = wmem_data[11] ;
1730
    write_data`WRITE_SEL     = 4'hF ;
1731
 
1732
    // handle retries from now on
1733
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1734
 
1735
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1736
    fork
1737
    begin
1738
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1739
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1740
        begin
1741
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1742
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1743
            disable main ;
1744
        end
1745
    end
1746
    begin
1747
        // currently IO commands not supported in behavioral models - master abort
1748
        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 ) ;
1749
        if ( ok !== 1 )
1750
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1751
        else
1752
            test_ok ;
1753
    end
1754
    join
1755
 
1756
    read_data`READ_ADDRESS  = target_address ;
1757
    read_data`READ_SEL      = 4'hF ;
1758
    read_data`READ_TAG_STIM = 0 ;
1759
 
1760
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1761
 
1762
    // currently io commands are not supported by behavioral target - transfer should not be completed
1763
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1764
    fork
1765
    begin
1766
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1767
        if (read_status`CYC_ERR !== 1)
1768
        begin
1769
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1770
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1771
            disable main ;
1772
        end
1773
        else
1774
            test_ok ;
1775
    end
1776
    begin
1777
        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 ) ;
1778
        if ( ok !== 1 )
1779
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1780
    end
1781
    join
1782
 
1783
    // test byte addressing
1784
    read_data`READ_ADDRESS = target_address + 2 ;
1785
    read_data`READ_SEL     = 4'b1100 ;
1786
 
1787
    fork
1788
    begin
1789
        // currently io commands are not supported by behavioral target - transfer should not be completed
1790
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1791
        if (read_status`CYC_ERR !== 1)
1792
        begin
1793
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1794
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1795
            disable main ;
1796
        end
1797
        else test_ok ;
1798
    end
1799
    begin
1800
        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 ) ;
1801
        if ( ok !== 1 )
1802
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1803
    end
1804
    join
1805
 
1806
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1807
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1808
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1809
    if ( ok !== 1 )
1810
    begin
1811
        test_fail("WB Base address register could not be written") ;
1812
        disable main ;
1813
    end
1814
 
1815
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1816
    if ( ok !== 1 )
1817
    begin
1818
        test_fail("WB Address Mask register could not be written") ;
1819
        disable main ;
1820
    end
1821
 
1822
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1823
    if ( ok !== 1 )
1824
    begin
1825
        test_fail("WB Image Control register could not be written") ;
1826
        disable main ;
1827
    end
1828
 
1829
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1830
    write_data`WRITE_DATA    = wmem_data[11] ;
1831
    write_data`WRITE_SEL     = 4'b1000 ;
1832
 
1833
    // handle retries from now on
1834
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1835
 
1836
    fork
1837
    begin
1838
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1839
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1840
        begin
1841
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1842
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1843
            disable main ;
1844
        end
1845
    end
1846
    begin
1847
        // currently IO commands not supported in behavioral models - master abort
1848
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1849
        if ( ok !== 1 )
1850
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1851
        else
1852
            test_ok ;
1853
    end
1854
    join
1855
 
1856
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1857
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1858
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1859
 
1860
    fork
1861
    begin
1862
        // currently io commands are not supported by behavioral target - transfer should not be completed
1863
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1864
        if (read_status`CYC_ERR !== 1)
1865
        begin
1866
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1867
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1868
            disable main ;
1869
        end
1870
        else test_ok ;
1871
    end
1872
    begin
1873
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1874
        if ( ok !== 1 )
1875
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1876
    end
1877
    join
1878
 
1879
    test_name = "DISABLING WB IMAGE" ;
1880
 
1881
    // disable current image
1882
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1883
    if ( ok !== 1 )
1884
    begin
1885
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1886
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1887
        disable main ;
1888
    end
1889
 
1890
    // clear master abort status bit
1891
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1892
    if ( ok !== 1 )
1893
    begin
1894
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1895
        test_fail("write to PCI Device Status register not accepted as expected") ;
1896
        disable main ;
1897
    end
1898
 
1899
end //main
1900
endtask //test_wb_image
1901
 
1902
task wb_slave_errors ;
1903
    reg   [11:0] ctrl_offset ;
1904
    reg   [11:0] ba_offset ;
1905
    reg   [11:0] am_offset ;
1906
    reg   [11:0] ta_offset ;
1907
    reg `WRITE_STIM_TYPE write_data ;
1908
    reg `READ_STIM_TYPE  read_data ;
1909
    reg `READ_RETURN_TYPE read_status ;
1910
 
1911
    reg `WRITE_RETURN_TYPE write_status ;
1912
    reg `WB_TRANSFER_FLAGS write_flags ;
1913
    reg [31:0] temp_val1 ;
1914
    reg [31:0] temp_val2 ;
1915
    reg        ok   ;
1916
    reg [11:0] pci_ctrl_offset ;
1917
    reg [31:0] image_base ;
1918
    reg [31:0] target_address ;
1919
    integer    i ;
1920
    reg skip ;
1921
fork
1922
begin:main
1923
 
1924
    `ifdef GUEST
1925
        skip = 1 ;
1926
    `else
1927
        skip = 0 ;
1928
    `endif
1929
 
1930
    pci_ctrl_offset = 12'h4 ;
1931
 
1932
    // image 1 is used for error testing, since it is always implemented
1933
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1934
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1935
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1936
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1937
 
1938
    target_address  = `BEH_TAR1_MEM_START ;
1939
    image_base      = 0 ;
1940
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1941
 
1942
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1943
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1944
    write_flags                    = 0 ;
1945
    write_flags`INIT_WAITS         = tb_init_waits ;
1946
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1947
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1948
 
1949
    // enable master & target operation
1950
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1951
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1952
    if ( ok !== 1 )
1953
    begin
1954
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1955
        test_fail("PCI Device Control register couldn't be written") ;
1956
        disable no_transaction ;
1957
        disable main ;
1958
    end
1959
 
1960
    // prepare image control register
1961
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1962
    if ( ok !== 1 )
1963
    begin
1964
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1965
        test_fail("WB Image Control register couldn't be written") ;
1966
        disable no_transaction ;
1967
        disable main ;
1968
    end
1969
 
1970
    // prepare base address register
1971
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1972
    if ( ok !== 1 )
1973
    begin
1974
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1975
        test_fail("WB Base Address register couldn't be written") ;
1976
        disable no_transaction ;
1977
        disable main ;
1978
    end
1979
 
1980
    // write address mask register
1981
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1982
    if ( ok !== 1 )
1983
    begin
1984
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1985
        test_fail("WB Address Mask register couldn't be written") ;
1986
        disable no_transaction ;
1987
        disable main ;
1988
    end
1989
 
1990
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1991
 
1992
    skip = 0 ;
1993
 
1994
    // memory mapped image - access is erroneous when address is not alligned
1995
    write_data`WRITE_ADDRESS = target_address + 1 ;
1996
    write_data`WRITE_DATA    = wmem_data[0] ;
1997
    write_data`WRITE_SEL     = 4'hF ;
1998
 
1999
    // handle retries from now on
2000
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2001
 
2002
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2003
 
2004
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2005
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2006
    begin
2007
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2008
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2009
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2010
        disable no_transaction ;
2011
        disable main ;
2012
    end
2013
 
2014
    write_data`WRITE_ADDRESS = target_address + 2 ;
2015
 
2016
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2017
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2018
    begin
2019
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2020
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2021
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2022
        disable no_transaction ;
2023
        disable main ;
2024
 
2025
    end
2026
 
2027
    write_data`WRITE_ADDRESS = target_address + 3 ;
2028
 
2029
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2030
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2031
    begin
2032
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2033
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2034
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2035
        disable no_transaction ;
2036
        disable main ;
2037
    end
2038
 
2039
    test_ok ;
2040
 
2041
    // perform same tests for read accesses
2042
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2043
 
2044
    read_data`READ_ADDRESS  = target_address + 2 ;
2045
    read_data`READ_SEL      = 4'hF ;
2046
    read_data`READ_TAG_STIM = 0 ;
2047
 
2048
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2049
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2050
    begin
2051
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2052
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2053
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2054
        disable no_transaction ;
2055
        disable main ;
2056
    end
2057
 
2058
    test_ok ;
2059
 
2060
    // prepare write data
2061
    for ( i = 0 ; i < 6 ; i = i + 1 )
2062
    begin
2063
        write_data`WRITE_DATA    = wmem_data[i] ;
2064
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2065
        write_data`WRITE_SEL     = 4'hF ;
2066
        wishbone_master.blk_write_data[i] = write_data ;
2067
    end
2068
 
2069
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2070
    write_flags`WB_TRANSFER_CAB    = 1 ;
2071
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2072
 
2073
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2074
    wishbone_master.wb_block_write(write_flags, write_status) ;
2075
 
2076
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2077
    begin
2078
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2079
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2080
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2081
        disable no_transaction ;
2082
        disable main ;
2083
    end
2084
 
2085
    // prepare read data
2086
    for ( i = 0 ; i < 6 ; i = i + 1 )
2087
    begin
2088
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2089
        read_data`READ_SEL     = 4'hF ;
2090
        wishbone_master.blk_read_data_in[i] = read_data ;
2091
    end
2092
 
2093
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2094
    wishbone_master.wb_block_read(write_flags, read_status) ;
2095
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2096
    begin
2097
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2098
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2099
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2100
        disable no_transaction ;
2101
        disable main ;
2102
    end
2103
 
2104
    test_ok ;
2105
 
2106
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2107
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2108
 
2109
    // map image to IO space
2110
    `ifdef GUEST
2111
        skip = 1 ;
2112
    `endif
2113
 
2114
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2115
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2116
    if ( ok !== 1 )
2117
    begin
2118
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2119
        test_fail("WB Image Base Address register couldn't be written") ;
2120
        disable no_transaction ;
2121
        disable main ;
2122
    end
2123
 
2124
    skip = 0 ;
2125
 
2126
    write_data`WRITE_ADDRESS = target_address ;
2127
    write_data`WRITE_DATA    = wmem_data[0] ;
2128
    write_data`WRITE_SEL     = 4'b1010 ;
2129
 
2130
    // don't handle retries
2131
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2132
 
2133
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2134
 
2135
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2136
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2137
    begin
2138
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2139
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2140
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2141
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2142
        disable no_transaction ;
2143
        disable main ;
2144
    end
2145
 
2146
    write_data`WRITE_ADDRESS = target_address + 1 ;
2147
    write_data`WRITE_SEL     = 4'b0011 ;
2148
 
2149
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2150
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2151
    begin
2152
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2153
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2154
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2155
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2156
        disable no_transaction ;
2157
        disable main ;
2158
    end
2159
 
2160
    write_data`WRITE_SEL     = 4'b1100 ;
2161
 
2162
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2163
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2164
    begin
2165
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2166
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2167
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2168
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2169
        disable no_transaction ;
2170
        disable main ;
2171
    end
2172
 
2173
    write_data`WRITE_ADDRESS = target_address + 2 ;
2174
    write_data`WRITE_SEL     = 4'b0101 ;
2175
 
2176
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2177
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2178
    begin
2179
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2180
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2181
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2182
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2183
        disable no_transaction ;
2184
        disable main ;
2185
    end
2186
 
2187
    write_data`WRITE_SEL     = 4'b1000 ;
2188
 
2189
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2190
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2191
    begin
2192
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2193
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2194
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2195
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2196
        disable no_transaction ;
2197
        disable main ;
2198
    end
2199
 
2200
    write_data`WRITE_ADDRESS = target_address + 3 ;
2201
    write_data`WRITE_SEL     = 4'b1010 ;
2202
 
2203
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2204
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2205
    begin
2206
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2207
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2208
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2209
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2210
        disable no_transaction ;
2211
        disable main ;
2212
    end
2213
 
2214
    write_data`WRITE_SEL     = 4'b0110 ;
2215
 
2216
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2217
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2218
    begin
2219
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2220
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2221
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2222
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2223
        disable no_transaction ;
2224
        disable main ;
2225
    end
2226
 
2227
    test_ok ;
2228
 
2229
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2230
 
2231
    read_data`READ_ADDRESS  = target_address + 3 ;
2232
    read_data`READ_SEL      = 4'hF ;
2233
    read_data`READ_TAG_STIM = 0 ;
2234
 
2235
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2236
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2237
    begin
2238
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2239
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2240
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2241
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2242
        disable no_transaction ;
2243
        disable main ;
2244
    end
2245
 
2246
    test_ok ;
2247
 
2248
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2249
    // prepare write data
2250
    for ( i = 0 ; i < 6 ; i = i + 1 )
2251
    begin
2252
        write_data`WRITE_DATA    = wmem_data[i] ;
2253
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2254
        write_data`WRITE_SEL     = 4'hF ;
2255
        wishbone_master.blk_write_data[i] = write_data ;
2256
    end
2257
 
2258
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2259
    write_flags`WB_TRANSFER_CAB    = 1 ;
2260
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2261
 
2262
    wishbone_master.wb_block_write(write_flags, write_status) ;
2263
 
2264
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2265
    begin
2266
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2267
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2268
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2269
        disable no_transaction ;
2270
        disable main ;
2271
    end
2272
 
2273
    test_ok ;
2274
 
2275
    test_name = "CAB I/O READ TO WB SLAVE" ;
2276
    // prepare read data
2277
    for ( i = 0 ; i < 6 ; i = i + 1 )
2278
    begin
2279
        read_data`READ_ADDRESS = target_address + 4*i ;
2280
        read_data`READ_SEL     = 4'hF ;
2281
        wishbone_master.blk_read_data_in[i] = read_data ;
2282
    end
2283
 
2284
    wishbone_master.wb_block_read(write_flags, read_status) ;
2285
 
2286
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2287
    begin
2288
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2289
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2290
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2291
        disable no_transaction ;
2292
        disable main ;
2293
    end
2294
 
2295
    test_ok ;
2296
 
2297
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2298
 
2299
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2300
 
2301
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2302
    write_data`WRITE_ADDRESS = target_address + 1 ;
2303
    write_data`WRITE_DATA    = wmem_data[0] ;
2304
    write_data`WRITE_SEL     = 4'hF ;
2305
 
2306
    // don't handle retries
2307
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2308
 
2309
    `ifdef HOST
2310
        `define DO_W_CONF_TEST
2311
        `define DO_R_CONF_TEST
2312
    `else
2313
        `ifdef WB_CNF_IMAGE
2314
             `define DO_R_CONF_TEST
2315
        `endif
2316
    `endif
2317
 
2318
    `ifdef DO_W_CONF_TEST
2319
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2320
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2321
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2322
    begin
2323
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2324
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2325
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2326
        disable no_transaction ;
2327
        disable main ;
2328
    end
2329
 
2330
    write_data`WRITE_ADDRESS = target_address + 2 ;
2331
 
2332
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2333
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2334
    begin
2335
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2336
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2337
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2338
        disable no_transaction ;
2339
        disable main ;
2340
    end
2341
 
2342
    write_data`WRITE_ADDRESS = target_address + 3 ;
2343
 
2344
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2345
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2346
    begin
2347
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2348
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2349
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2350
        disable no_transaction ;
2351
        disable main ;
2352
    end
2353
 
2354
    test_ok ;
2355
    `endif
2356
 
2357
    `ifdef DO_R_CONF_TEST
2358
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2359
    read_data`READ_ADDRESS  = target_address + 3 ;
2360
    read_data`READ_SEL      = 4'hF ;
2361
    read_data`READ_TAG_STIM = 0 ;
2362
 
2363
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2364
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2365
    begin
2366
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2367
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2368
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2369
        disable no_transaction ;
2370
        disable main ;
2371
    end
2372
 
2373
    test_ok ;
2374
    `endif
2375
 
2376
    `ifdef DO_W_CONF_TEST
2377
    // prepare write data
2378
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2379
    for ( i = 0 ; i < 6 ; i = i + 1 )
2380
    begin
2381
        write_data`WRITE_DATA    = wmem_data[i] ;
2382
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2383
        write_data`WRITE_SEL     = 4'hF ;
2384
        wishbone_master.blk_write_data[i] = write_data ;
2385
    end
2386
 
2387
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2388
    write_flags`WB_TRANSFER_CAB    = 1 ;
2389
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2390
 
2391
    wishbone_master.wb_block_write(write_flags, write_status) ;
2392
 
2393
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2394
    begin
2395
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2396
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2397
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2398
        disable no_transaction ;
2399
        disable main ;
2400
    end
2401
    test_ok ;
2402
    `endif
2403
 
2404
    `ifdef DO_R_CONF_TEST
2405
    // prepare read data
2406
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2407
    for ( i = 0 ; i < 6 ; i = i + 1 )
2408
    begin
2409
        read_data`READ_ADDRESS = target_address + 4*i ;
2410
        read_data`READ_SEL     = 4'hF ;
2411
        wishbone_master.blk_read_data_in[i] = read_data ;
2412
    end
2413
 
2414
    wishbone_master.wb_block_read(write_flags, read_status) ;
2415
 
2416
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2417
    begin
2418
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2419
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2420
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2421
        disable no_transaction ;
2422
        disable main ;
2423
    end
2424
    test_ok ;
2425
    `endif
2426
 
2427
    `ifdef GUEST
2428
        skip = 1 ;
2429
    `endif
2430
 
2431
    // disable image
2432
    test_name = "DISABLE IMAGE" ;
2433
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2434
    if ( ok !== 1 )
2435
    begin
2436
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2437
        test_fail("WB Address Mask register couldn't be written") ;
2438
        disable no_transaction ;
2439
        disable main ;
2440
    end
2441
 
2442
    skip = 0 ;
2443
 
2444
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2445
 
2446
    disable no_transaction ;
2447
end
2448
begin:no_transaction
2449
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2450
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2451
    forever
2452
    begin
2453
        @(posedge pci_clock) ;
2454
        if ( skip !== 1 )
2455
        begin
2456
            if ( FRAME !== 1 )
2457
            begin
2458
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2459
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2460
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2461
            end
2462
        end
2463
    end
2464
end
2465
join
2466
endtask //wb_slave_errors
2467
 
2468
task wb_to_pci_error_handling ;
2469
    reg   [11:0] ctrl_offset ;
2470
    reg   [11:0] ba_offset ;
2471
    reg   [11:0] am_offset ;
2472
    reg   [11:0] ta_offset ;
2473
    reg   [11:0] err_cs_offset ;
2474
    reg `WRITE_STIM_TYPE write_data ;
2475
    reg `READ_STIM_TYPE  read_data ;
2476
    reg `READ_RETURN_TYPE read_status ;
2477
 
2478
    reg `WRITE_RETURN_TYPE write_status ;
2479
    reg `WB_TRANSFER_FLAGS write_flags ;
2480
    reg [31:0] temp_val1 ;
2481
    reg [31:0] temp_val2 ;
2482
    reg        ok   ;
2483
    reg [11:0] pci_ctrl_offset ;
2484
    reg [31:0] image_base ;
2485
    reg [31:0] target_address ;
2486
    integer    num_of_trans ;
2487
    integer    current ;
2488
    integer    i ;
2489
begin:main
2490
 
2491
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2492
 
2493
    pci_ctrl_offset = 12'h4 ;
2494
 
2495
    // disable error interrupts and disable error reporting
2496
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2497
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2498
    if ( ok !== 1 )
2499
    begin
2500
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2501
        test_fail("PCI Device Control register couldn't be written") ;
2502
        disable main ;
2503
    end
2504
 
2505
    // image 1 is used for error testing, since it is always implemented
2506
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2507
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2508
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2509
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2510
 
2511
    // set master abort testing address to address that goes out of target's range
2512
    target_address  = `BEH_TAR1_MEM_START ;
2513
    image_base      = 0 ;
2514
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2515
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2516
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2517
 
2518
    write_flags                    = 0 ;
2519
    write_flags`INIT_WAITS         = tb_init_waits ;
2520
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2521
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2522
 
2523
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2524
 
2525
    // enable master & target operation
2526
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2527
    if ( ok !== 1 )
2528
    begin
2529
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2530
        test_fail("PCI Device Control register couldn't be written") ;
2531
        disable main ;
2532
    end
2533
 
2534
    // prepare image control register
2535
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2536
    if ( ok !== 1 )
2537
    begin
2538
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2539
        test_fail("WB Image Control register couldn't be written") ;
2540
        disable main ;
2541
    end
2542
 
2543
    // prepare base address register
2544
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2545
    if ( ok !== 1 )
2546
    begin
2547
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2548
        test_fail("WB Image Base Address register couldn't be written") ;
2549
        disable main ;
2550
    end
2551
 
2552
    // write address mask register
2553
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2554
    if ( ok !== 1 )
2555
    begin
2556
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2557
        test_fail("WB Image Address Mask register couldn't be written") ;
2558
        disable main ;
2559
    end
2560
 
2561
    // disable error reporting
2562
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2563
    if ( ~ok )
2564
    begin
2565
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2566
        test_fail("WB Error Control and Status register couldn't be written") ;
2567
        disable main ;
2568
    end
2569
 
2570
    // perform two writes - one to error address and one to OK address
2571
    // prepare write buffer
2572
 
2573
    write_data`WRITE_ADDRESS = target_address ;
2574
    write_data`WRITE_DATA    = wmem_data[100] ;
2575
    write_data`WRITE_SEL     = 4'hF ;
2576
 
2577
    wishbone_master.blk_write_data[0] = write_data ;
2578
 
2579
    write_flags`WB_TRANSFER_SIZE = 2 ;
2580
 
2581
    // don't handle retries
2582
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2583
    write_flags`WB_TRANSFER_CAB    = 0 ;
2584
 
2585
    $display("Introducing master abort error on single WB to PCI write!") ;
2586
 
2587
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2588
    // first disable target 1
2589
 
2590 45 mihad
    configuration_cycle_write(0,                        // bus number
2591
                              `TAR1_IDSEL_INDEX - 11,   // device number
2592
                              0,                        // function number
2593
                              1,                        // register number
2594
                              0,                        // type of configuration cycle
2595
                              4'b0001,                  // byte enables
2596
                              32'h0000_0000             // data
2597 15 mihad
                             ) ;
2598
 
2599
    fork
2600
    begin
2601
        // start no response monitor in parallel with writes
2602
        musnt_respond(ok) ;
2603
        if ( ok !== 1 )
2604
        begin
2605
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2606
            $display("Testbench is configured wrong!") ;
2607
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2608
        end
2609
        else
2610
            test_ok ;
2611
    end
2612
    begin
2613
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2614
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2615
       begin
2616
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2617
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2618
           test_fail("WB Slave state machine failed to post single memory write");
2619
           disable main ;
2620
       end
2621
    end
2622
    join
2623
 
2624
    /*// read data from second write
2625
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2626
    read_data`READ_ADDRESS = target_address ;
2627
    read_data`READ_SEL     = 4'hF ;
2628
    read_data`READ_TAG_STIM = 0 ;
2629
 
2630
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2631
 
2632
    if ( read_status`READ_DATA !== wmem_data[101] )
2633
    begin
2634
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2635
    end
2636
    */
2637
 
2638
    // read error status register - no errors should be reported since reporting was disabled
2639
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2640
 
2641
    @(posedge pci_clock) ;
2642
    // wait for two WB clocks for synchronization to be finished
2643
    repeat (2)
2644
        @(posedge wb_clock) ;
2645
 
2646
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2647
    if ( temp_val1[8] !== 0 )
2648
    begin
2649
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2650
        $display("Error reporting was disabled, but error was reported anyway!") ;
2651
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2652
        disable main ;
2653
    end
2654
    test_ok ;
2655
 
2656
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2657
    // check for interrupts - there should be no interrupt requests active
2658
    `ifdef HOST
2659
        repeat(4)
2660
            @(posedge wb_clock) ;
2661
 
2662
        if ( INT_O !== 0 )
2663
        begin
2664
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2665
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2666
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2667
        end
2668
        else
2669
            test_ok ;
2670
    `else
2671
    `ifdef GUEST
2672
        repeat( 4 )
2673
            @(posedge pci_clock) ;
2674
 
2675
        if ( INTA !== 1 )
2676
        begin
2677
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2678
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2679
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2680
        end
2681
        else
2682
            test_ok ;
2683
    `endif
2684
    `endif
2685
 
2686
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2687
    // check PCI status register
2688
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2689
    if ( temp_val1[29] !== 1 )
2690
    begin
2691
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2692
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2693
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2694
    end
2695
    else
2696
        test_ok ;
2697
 
2698
    // clear
2699
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2700
 
2701
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2702
 
2703
    $display("Introducing master abort error to CAB write!") ;
2704
    // now enable error reporting mechanism
2705
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2706
    // enable error interrupts
2707
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2708
 
2709
    // configure flags for CAB transfer
2710
    write_flags`WB_TRANSFER_CAB = 1 ;
2711
    write_flags`WB_TRANSFER_SIZE = 3 ;
2712
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2713
 
2714
    // prepare data for erroneous write
2715
    for ( i = 0 ; i < 3 ; i = i + 1 )
2716
    begin
2717
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2718
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2719
        write_data`WRITE_SEL     = 4'hF ;
2720
        wishbone_master.blk_write_data[i] = write_data ;
2721
    end
2722
 
2723
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2724
    fork
2725
    begin
2726
        wishbone_master.wb_block_write(write_flags, write_status) ;
2727
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2728
        begin
2729
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2730
            $display("Complete burst write through WB slave didn't succeed!") ;
2731
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2732
            disable main ;
2733
        end
2734
    end
2735
    begin
2736
        musnt_respond(ok) ;
2737
        if ( ok !== 1 )
2738
        begin
2739
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2740
            $display("Testbench is configured wrong!") ;
2741
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2742
        end
2743
        else
2744
            test_ok ;
2745
    end
2746
    join
2747
 
2748
    // check error status address, data, byte enables and bus command
2749
    // error status bit is signalled on PCI clock and synchronized to WB clock
2750
    // wait one PCI clock cycle
2751
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2752
    ok = 1 ;
2753
    @(posedge pci_clock) ;
2754
 
2755
    // wait for two WB clocks for synchronization to be finished
2756
    repeat (2)
2757
        @(posedge wb_clock) ;
2758
 
2759
    // read registers
2760
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2761
    if ( temp_val1[8] !== 1 )
2762
    begin
2763
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2764
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2765
        ok = 0 ;
2766
    end
2767
 
2768
    if ( temp_val1[9] !== 1 )
2769
    begin
2770
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2771
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2772
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2773
        ok = 0 ;
2774
    end
2775
 
2776
    if ( temp_val1[31:28] !== 0 )
2777
    begin
2778
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2779
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2780
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2781
        ok = 0 ;
2782
    end
2783
 
2784
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2785
    begin
2786
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2787
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2788
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2789
        ok = 0 ;
2790
    end
2791
 
2792
    // read error address register
2793
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2794
    if ( temp_val1 !== target_address )
2795
    begin
2796
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2797
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2798
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2799
        ok = 0 ;
2800
    end
2801
 
2802
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2803
    if ( temp_val1 !== wmem_data[110] )
2804
    begin
2805
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2806
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2807
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2808
        ok = 0 ;
2809
    end
2810
 
2811
    // check PCI status register
2812
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2813
    if ( temp_val1[29] !== 1 )
2814
    begin
2815
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2816
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2817
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2818
        ok = 0 ;
2819
    end
2820
 
2821
    if ( temp_val1[28] !== 0 )
2822
    begin
2823
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2824
        $display("Received Target Abort bit was set for no reason!") ;
2825
        test_fail("Received Target Abort bit was set for no reason") ;
2826
        ok = 0 ;
2827
    end
2828
 
2829
    if ( ok )
2830
        test_ok ;
2831
 
2832
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2833
 
2834
    // clear error status bit
2835
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2836
 
2837
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2838
 
2839
    ok = 1 ;
2840
 
2841
    `ifdef HOST
2842
        repeat(4)
2843
        @(posedge wb_clock) ;
2844
        if ( INT_O !== 1 )
2845
        begin
2846
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2847
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2848
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2849
            ok = 0 ;
2850
        end
2851
    `else
2852
    `ifdef GUEST
2853
        repeat(4)
2854
        @(posedge pci_clock) ;
2855
        if ( INTA !== 0 )
2856
        begin
2857
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2858
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2859
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2860
            ok = 0 ;
2861
        end
2862
    `endif
2863
    `endif
2864
 
2865
    // read interrupt status register
2866
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2867
    if ( temp_val1 !== 32'h0000_0002 )
2868
    begin
2869
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2870
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2871
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2872
        test_fail("Interrupt Status register returned wrong value") ;
2873
        ok = 0 ;
2874
    end
2875
 
2876
    if ( ok )
2877
        test_ok ;
2878
    // clear interrupt status bits
2879
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2880
 
2881
    ok = 1 ;
2882
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2883
    // wait for two clock cycles before checking interrupt request deassertion
2884
    `ifdef HOST
2885
        repeat (4)
2886
            @(posedge wb_clock) ;
2887
 
2888
        if ( INT_O !== 0 )
2889
        begin
2890
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2891
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2892
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2893
            ok = 0 ;
2894
        end
2895
    `else
2896
    `ifdef GUEST
2897
        repeat (4)
2898
            @(posedge pci_clock) ;
2899
 
2900
        if ( INTA !== 1 )
2901
        begin
2902
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2903
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2904
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2905
            ok = 0 ;
2906
        end
2907
    `endif
2908
    `endif
2909
 
2910
    if ( ok )
2911
        test_ok ;
2912
 
2913
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2914
    ok = 1 ;
2915
    // enable target
2916 45 mihad
    configuration_cycle_write(0,                        // bus number
2917
                              `TAR1_IDSEL_INDEX - 11,   // device number
2918
                              0,                        // function number
2919
                              1,                        // register number
2920
                              0,                        // type of configuration cycle
2921
                              4'b0001,                  // byte enables
2922
                              32'h0000_0007             // data
2923 15 mihad
                             ) ;
2924
    // prepare data for ok write
2925
    for ( i = 0 ; i < 3 ; i = i + 1 )
2926
    begin
2927
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2928
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2929
        write_data`WRITE_SEL     = 4'hF ;
2930
        wishbone_master.blk_write_data[i] = write_data ;
2931
    end
2932
 
2933
    wishbone_master.wb_block_write(write_flags, write_status) ;
2934
 
2935
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2936
    begin
2937
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2938
        $display("Complete burst write through WB slave didn't succeed!") ;
2939
        test_fail("WB Slave state machine failed to post CAB write") ;
2940
        disable main ;
2941
    end
2942
 
2943
    // do a read
2944
    for ( i = 0 ; i < 3 ; i = i + 1 )
2945
    begin
2946
        read_data`READ_ADDRESS = target_address + 4*i ;
2947
        read_data`READ_SEL     = 4'hF ;
2948
        wishbone_master.blk_read_data_in[i] = read_data ;
2949
    end
2950
 
2951
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2952
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2953
    write_flags`WB_TRANSFER_CAB    = 1 ;
2954
 
2955
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2956
 
2957
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2958
    begin
2959
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2960
        $display("Complete burst read through WB slave didn't succeed!") ;
2961
        test_fail("Delayed CAB write was not processed as expected") ;
2962
        disable main ;
2963
    end
2964
 
2965
    for ( i = 0 ; i < 3 ; i = i + 1 )
2966
    begin
2967
        read_status = wishbone_master.blk_read_data_out[i] ;
2968
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2969
        begin
2970
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2971
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2972
        end
2973
    end
2974
 
2975
    $display("Introducing master abort error to single read!") ;
2976
    // disable target
2977 45 mihad
    configuration_cycle_write(0,                        // bus number
2978
                              `TAR1_IDSEL_INDEX - 11,   // device number
2979
                              0,                        // function number
2980
                              1,                        // register number
2981
                              0,                        // type of configuration cycle
2982
                              4'b0001,                  // byte enables
2983
                              32'h0000_0000             // data
2984 15 mihad
                             ) ;
2985
    // set read data
2986
    read_data`READ_ADDRESS = target_address ;
2987
    read_data`READ_SEL     = 4'hF ;
2988
 
2989
    // enable automatic retry handling
2990
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2991
    write_flags`WB_TRANSFER_CAB    = 0 ;
2992
 
2993
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2994
    fork
2995
    begin
2996
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2997
    end
2998
    begin
2999
        musnt_respond(ok) ;
3000
        if ( ok !== 1 )
3001
        begin
3002
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3003
            $display("Testbench is configured wrong!") ;
3004
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3005
        end
3006
    end
3007
    join
3008
 
3009
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3010
    begin
3011
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3012
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3013
        $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) ;
3014
        test_fail("read didn't finish on WB bus as expected") ;
3015
        disable main ;
3016
    end
3017
 
3018
    test_ok ;
3019
 
3020
 
3021
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3022
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3023
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3024
    if ( temp_val1[8] !== 0 )
3025
    begin
3026
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3027
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3028
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3029
    end
3030
    else
3031
        test_ok ;
3032
 
3033
    // now check normal read operation
3034 45 mihad
    configuration_cycle_write(0,                        // bus number
3035
                              `TAR1_IDSEL_INDEX - 11,   // device number
3036
                              0,                        // function number
3037
                              1,                        // register number
3038
                              0,                        // type of configuration cycle
3039
                              4'b0001,                  // byte enables
3040
                              32'h0000_0007             // data
3041 15 mihad
                             ) ;
3042
 
3043 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3044 15 mihad
    read_data`READ_ADDRESS = target_address ;
3045
    read_data`READ_SEL     = 4'hF ;
3046
 
3047
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3048
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3049
    begin
3050
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3051
        $display("WB slave failed to process single read!") ;
3052
        $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) ;
3053
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3054
        disable main ;
3055
    end
3056
 
3057
    if ( read_status`READ_DATA !== wmem_data[113] )
3058
    begin
3059
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3060
        test_fail("when read finished on WB bus, wrong data was provided") ;
3061
    end
3062
    else
3063
        test_ok ;
3064
 
3065
    // check PCI status register
3066 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3067 15 mihad
    ok = 1 ;
3068
 
3069
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3070
    if ( temp_val1[29] !== 1 )
3071
    begin
3072
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3073
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3074
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3075
        ok = 0 ;
3076
    end
3077
 
3078
    if ( temp_val1[28] !== 0 )
3079
    begin
3080
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3081
        $display("Received Target Abort bit was set for no reason!") ;
3082
        test_fail("Received Target Abort bit was set for no reason") ;
3083
        ok = 0 ;
3084
    end
3085
    if ( ok )
3086
        test_ok ;
3087
 
3088
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3089
 
3090
    $display("Introducing master abort error to CAB read!") ;
3091
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3092
 
3093 45 mihad
    configuration_cycle_write(0,                        // bus number
3094
                              `TAR1_IDSEL_INDEX - 11,   // device number
3095
                              0,                        // function number
3096
                              1,                        // register number
3097
                              0,                        // type of configuration cycle
3098
                              4'b0001,                  // byte enables
3099
                              32'h0000_0000             // data
3100 15 mihad
                             ) ;
3101
 
3102
    for ( i = 0 ; i < 3 ; i = i + 1 )
3103
    begin
3104
        read_data`READ_ADDRESS = target_address + 4*i ;
3105
        read_data`READ_SEL     = 4'hF ;
3106
        wishbone_master.blk_read_data_in[i] = read_data ;
3107
    end
3108
 
3109
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3110
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3111
    write_flags`WB_TRANSFER_CAB    = 1 ;
3112
 
3113
    fork
3114
    begin
3115
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3116
    end
3117
    begin
3118
        musnt_respond(ok) ;
3119
        if ( ok !== 1 )
3120
        begin
3121
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3122
            $display("Testbench is configured wrong!") ;
3123
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3124
        end
3125
    end
3126
    join
3127
 
3128
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3129
    begin
3130
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3131
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3132
        $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) ;
3133
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3134
        disable main ;
3135
    end
3136
    else
3137
        test_ok ;
3138
 
3139
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3140
    ok = 1 ;
3141
    // check PCI status register
3142
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3143
    if ( temp_val1[29] !== 1 )
3144
    begin
3145
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3146
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3147
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3148
        ok = 0 ;
3149
    end
3150
 
3151
    if ( temp_val1[28] !== 0 )
3152
    begin
3153
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3154
        $display("Received Target Abort bit was set for no reason!") ;
3155
        test_fail("Received Target Abort bit was set for no reason") ;
3156
        ok = 0 ;
3157
    end
3158
 
3159
    if ( ok )
3160
        test_ok ;
3161
 
3162
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3163
 
3164
    $display("Introducing target abort termination to single write!") ;
3165
 
3166
    // disable error reporting and interrupts
3167
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3168
 
3169 45 mihad
    configuration_cycle_write(0,                        // bus number
3170
                              `TAR1_IDSEL_INDEX - 11,   // device number
3171
                              0,                        // function number
3172
                              1,                        // register number
3173
                              0,                        // type of configuration cycle
3174
                              4'b0001,                  // byte enables
3175
                              32'h0000_0007             // data
3176 15 mihad
                             ) ;
3177
 
3178
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3179
    if ( ok !== 1 )
3180
    begin
3181
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3182
        test_fail("WB Error Control and Status register couldn't be written to") ;
3183
        disable main ;
3184
    end
3185
 
3186
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3187
    if ( ok !== 1 )
3188
    begin
3189
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3190
        test_fail("Interrupt Control register couldn't be written to") ;
3191
        disable main ;
3192
    end
3193
 
3194
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3195
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3196
 
3197
    write_data`WRITE_ADDRESS = target_address ;
3198
    write_data`WRITE_DATA    = wmem_data[0] ;
3199
    write_data`WRITE_SEL     = 4'hF ;
3200
 
3201
    wishbone_master.blk_write_data[0] = write_data ;
3202
 
3203
    write_data`WRITE_ADDRESS = target_address + 4;
3204
    write_data`WRITE_DATA    = wmem_data[1] ;
3205
    write_data`WRITE_SEL     = 4'hF ;
3206
 
3207
    wishbone_master.blk_write_data[1] = write_data ;
3208
 
3209
    write_flags`WB_TRANSFER_SIZE = 2 ;
3210
 
3211
    // don't handle retries
3212
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3213
    write_flags`WB_TRANSFER_CAB    = 0 ;
3214
 
3215
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3216
    fork
3217
    begin
3218
        wishbone_master.wb_block_write(write_flags, write_status) ;
3219
 
3220
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3221
        begin
3222
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3223
            $display("Image writes were not accepted as expected!") ;
3224
            $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) ;
3225
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3226
            disable main ;
3227
        end
3228
 
3229
        // read data back to see, if it was written OK
3230
        read_data`READ_ADDRESS         = target_address + 4;
3231
        read_data`READ_SEL             = 4'hF ;
3232
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3233
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3234
    end
3235
    begin
3236
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3237
        if ( ok !== 1 )
3238
        begin
3239
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3240
        end
3241
        else
3242
            test_ok ;
3243
 
3244
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3245
 
3246
        // when first transaction finishes - enable normal target response!
3247
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3248
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3249
 
3250
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3251
        if ( ok !== 1 )
3252
        begin
3253
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3254
        end
3255
        else
3256
            test_ok ;
3257
 
3258
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3259
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3260
        if ( ok !== 1 )
3261
        begin
3262
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3263
        end
3264
    end
3265
    join
3266
 
3267
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3268
    begin
3269
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3270
        $display("Bridge failed to process single read after target abort terminated write!") ;
3271
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3272
        disable main ;
3273
    end
3274
 
3275
    if ( read_status`READ_DATA !== wmem_data[1] )
3276
    begin
3277
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3278
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3279
    end
3280
    else
3281
        test_ok ;
3282
 
3283
    // check interrupt and error statuses!
3284
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3285
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3286
    if ( temp_val1[8] !== 0 )
3287
    begin
3288
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3289
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3290
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3291
    end
3292
    else
3293
        test_ok ;
3294
 
3295
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3296
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3297
    if ( temp_val1[1] !== 0 )
3298
    begin
3299
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3300
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3301
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3302
    end
3303
    else
3304
        test_ok ;
3305
 
3306
    // check PCI status register
3307
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3308
    ok = 1 ;
3309
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3310
    if ( temp_val1[29] !== 0 )
3311
    begin
3312
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3313
        $display("Received Master Abort bit was set with no reason!") ;
3314
        test_fail("Received Master Abort bit was set with no reason") ;
3315
        ok = 0 ;
3316
    end
3317
 
3318
    if ( temp_val1[28] !== 1 )
3319
    begin
3320
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3321
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3322
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3323
        ok = 0 ;
3324
    end
3325
 
3326
    if ( ok )
3327
        test_ok ;
3328
 
3329
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3330
 
3331
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3332
 
3333
    $display("Introducing target abort termination to CAB write!") ;
3334
    // enable error reporting mechanism
3335
 
3336
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3337
    if ( ok !== 1 )
3338
    begin
3339
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3340
        test_fail("WB Error Control and Status register could not be written to") ;
3341
        disable main ;
3342
    end
3343
 
3344
    for ( i = 0 ; i < 3 ; i = i + 1 )
3345
    begin
3346
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3347
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3348
        write_data`WRITE_SEL     = 4'b1010 ;
3349
        wishbone_master.blk_write_data[i] = write_data ;
3350
    end
3351
 
3352
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3353
    write_flags`WB_TRANSFER_CAB    = 1 ;
3354
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3355
 
3356
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3357
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3358
 
3359
    fork
3360
    begin
3361
        wishbone_master.wb_block_write(write_flags, write_status) ;
3362
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3363
        begin
3364
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3365
            $display("Bridge failed to process complete CAB write!") ;
3366
            test_fail("bridge failed to post CAB Memory Write") ;
3367
            disable main ;
3368
        end
3369
    end
3370
    begin
3371
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3372
        if ( ok !== 1 )
3373
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3374
        else
3375
            test_ok ;
3376
    end
3377
    join
3378
 
3379
    // check statuses and data from error
3380
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3381
    ok = 1 ;
3382
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3383
    if ( temp_val1[8] !== 1 )
3384
    begin
3385
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3386
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3387
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3388
        ok = 0 ;
3389
    end
3390
 
3391
    if ( temp_val1[9] !== 0 )
3392
    begin
3393
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3394
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3395
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3396
        ok = 0 ;
3397
    end
3398
 
3399
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3400
    begin
3401
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3402
        $display("Value in W_ERR_CS register was wrong!") ;
3403
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3404
        test_fail("BE Field didn't provided expected value") ;
3405
        ok = 0 ;
3406
    end
3407
 
3408
    if ( ok )
3409
        test_ok ;
3410
 
3411
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3412
    ok = 1 ;
3413
    // check erroneous address and data
3414
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3415
    if ( temp_val1 !== (target_address + 8) )
3416
    begin
3417
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3418
        $display("Value in W_ERR_ADDR register was wrong!") ;
3419
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3420
        test_fail("Value in WB Erroneous Address register was wrong") ;
3421
        ok = 0 ;
3422
    end
3423
 
3424
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3425
    if ( temp_val1 !== wmem_data[120] )
3426
    begin
3427
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3428
        $display("Value in W_ERR_DATA register was wrong!") ;
3429
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3430
        test_fail("Value in WB Erroneous Data register was wrong") ;
3431
        ok = 0 ;
3432
    end
3433
 
3434
    if ( ok )
3435
        test_ok ;
3436
 
3437
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3438
    ok = 1 ;
3439
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3440
    if ( temp_val1[29] !== 0 )
3441
    begin
3442
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3443
        $display("Received Master Abort bit was set with no reason!") ;
3444
        test_fail("Received Master Abort bit was set for no reason") ;
3445
        ok = 0 ;
3446
    end
3447
 
3448
    if ( temp_val1[28] !== 1 )
3449
    begin
3450
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3451
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3452
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3453
        ok = 0 ;
3454
    end
3455
 
3456
    if ( ok )
3457
        test_ok ;
3458
 
3459
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3460
 
3461
    // clear error status bit and enable error interrupts
3462
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3463
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3464
 
3465
    // check if error bit was cleared
3466
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3467
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3468
    if ( temp_val1[8] !== 0 )
3469
    begin
3470
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3471
        $display("Error bit was not cleared even though one was written to its location!") ;
3472
        test_fail("Error bit was not cleared even though one was written to its location") ;
3473
    end
3474
 
3475
    // repeat same write with different target configuration
3476
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3477
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3478
 
3479
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3480
    fork
3481
    begin
3482
        write_flags`WB_TRANSFER_SIZE = 2 ;
3483
        wishbone_master.wb_block_write(write_flags, write_status) ;
3484
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3485
        begin
3486
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3487
            $display("Bridge failed to process complete CAB write!") ;
3488
            test_fail("bridge failed to post CAB Memory Write") ;
3489
            disable main ;
3490
        end
3491
 
3492
        write_flags`WB_TRANSFER_SIZE = 3 ;
3493
        wishbone_master.wb_block_write(write_flags, write_status) ;
3494
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3495
        begin
3496
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3497
            $display("Bridge failed to process complete CAB write!") ;
3498
            test_fail("bridge failed to post CAB Memory Write") ;
3499
            disable main ;
3500
        end
3501
    end
3502
    begin
3503
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3504
        if ( ok !== 1 )
3505
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3506
        else
3507
        begin
3508
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3509
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3510
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3511
            if ( ok !== 1 )
3512
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3513
            else
3514
                test_ok ;
3515
        end
3516
    end
3517
    join
3518
 
3519
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3520
    ok = 1 ;
3521
    // check statuses and data from error
3522
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3523
    if ( temp_val1[8] !== 1 )
3524
    begin
3525
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3526
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3527
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3528
        ok = 0 ;
3529
    end
3530
 
3531
    if ( temp_val1[9] !== 0 )
3532
    begin
3533
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3534
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3535
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3536
        ok = 0 ;
3537
    end
3538
 
3539
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3540
    begin
3541
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3542
        $display("Value in W_ERR_CS register was wrong!") ;
3543
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3544
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3545
        ok = 0 ;
3546
    end
3547
 
3548
    if ( ok )
3549
        test_ok ;
3550
 
3551
    // check erroneous address and data
3552
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3553
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3554
    ok = 1 ;
3555
    if ( temp_val1 !== (target_address + 8 + 4) )
3556
    begin
3557
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3558
        $display("Value in W_ERR_ADDR register was wrong!") ;
3559
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3560
        test_fail("Value in WB Erroneous Address register was wrong") ;
3561
        ok = 0 ;
3562
 
3563
    end
3564
 
3565
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3566
    if ( temp_val1 !== wmem_data[121] )
3567
    begin
3568
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3569
        $display("Value in W_ERR_DATA register was wrong!") ;
3570
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3571
        test_fail("Value in WB Erroneous Data register was wrong") ;
3572
        ok = 0 ;
3573
    end
3574
 
3575
    if ( ok )
3576
        test_ok ;
3577
 
3578
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3579
    `ifdef HOST
3580
        repeat(4)
3581
            @(posedge wb_clock) ;
3582
        if ( INT_O !== 1 )
3583
        begin
3584
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3585
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3586
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3587
        end
3588
        else
3589
            test_ok ;
3590
    `else
3591
    `ifdef GUEST
3592
        repeat(4)
3593
            @(posedge pci_clock) ;
3594
        if ( INTA !== 0 )
3595
        begin
3596
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3597
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3598
            test_fail("interrupt request was not presented on PCI bus") ;
3599
        end
3600
        else
3601
            test_ok ;
3602
    `endif
3603
    `endif
3604
 
3605
    // read interrupt status register
3606
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3607
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3608
    if ( temp_val1[1] !== 1 )
3609
    begin
3610
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3611
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3612
        test_fail("Expected Interrupt status bit wasn't set") ;
3613
    end
3614
 
3615
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3616
 
3617
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3618
    ok = 1 ;
3619
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3620
    if ( temp_val1[29] !== 0 )
3621
    begin
3622
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3623
        $display("Received Master Abort bit was set with no reason!") ;
3624
        test_fail("Received Master Abort bit was set with no reason") ;
3625
        ok = 0 ;
3626
    end
3627
 
3628
    if ( temp_val1[28] !== 1 )
3629
    begin
3630
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3631
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3632
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3633
        ok = 0 ;
3634
    end
3635
 
3636
    if ( ok )
3637
        test_ok ;
3638
 
3639
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3640
 
3641
    // clear interrupts and errors
3642
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3643
    repeat( 3 )
3644
        @(posedge pci_clock) ;
3645
 
3646
    repeat( 2 )
3647
        @(posedge wb_clock) ;
3648
 
3649
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3650
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3651
    if ( temp_val1[1] !== 0 )
3652
    begin
3653
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3654
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3655
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3656
    end
3657
    else
3658
        test_ok ;
3659
 
3660
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3661
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3662
    if ( temp_val1[8] !== 0 )
3663
    begin
3664
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3665
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3666
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3667
    end
3668
 
3669
 
3670
    $display("Introducing Target Abort error to single read!") ;
3671
    // set read data
3672
    read_data`READ_ADDRESS = target_address + 8 ;
3673
    read_data`READ_SEL     = 4'hF ;
3674
 
3675
    // enable automatic retry handling
3676
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3677
    write_flags`WB_TRANSFER_CAB    = 0 ;
3678
 
3679
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3680
 
3681
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3682
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3683
 
3684
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3685
 
3686
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3687
    begin
3688
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3689
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3690
        $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) ;
3691
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3692
        disable main ;
3693
    end
3694
    else
3695
        test_ok ;
3696
 
3697
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3698
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3699
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3700
    if ( temp_val1[8] !== 0 )
3701
    begin
3702
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3703
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3704
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3705
    end
3706
    else
3707
        test_ok ;
3708
 
3709
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3710
    ok = 1 ;
3711
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3712
    if ( temp_val1[29] !== 0 )
3713
    begin
3714
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3715
        $display("Received Master Abort bit was set with no reason!") ;
3716
        test_fail("Received Master Abort bit was set with no reason") ;
3717
        ok = 0 ;
3718
    end
3719
 
3720
    if ( temp_val1[28] !== 1 )
3721
    begin
3722
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3723
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3724
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3725
        ok = 0 ;
3726
    end
3727
 
3728
    if ( ok )
3729
        test_ok ;
3730
 
3731
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3732
 
3733
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3734
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3735
    if ( temp_val1[1] !== 0 )
3736
    begin
3737
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3738
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3739
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3740
    end
3741
    else
3742
        test_ok ;
3743
 
3744
    $display("Introducing Target Abort error to CAB read!") ;
3745
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3746
 
3747
    for ( i = 0 ; i < 4 ; i = i + 1 )
3748
    begin
3749
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3750
        read_data`READ_SEL     = 4'b1010 ;
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   = 2 ;
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]      = 2 ;
3760
 
3761
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3762
 
3763
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (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 second phase should return one data and terminate WISHBONE cycle with error on second 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 second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3769
        disable main ;
3770
    end
3771
 
3772
    read_status = wishbone_master.blk_read_data_out[0] ;
3773
    temp_val1 = read_status`READ_DATA ;
3774
    temp_val2 = wmem_data[120] ;
3775
 
3776
    // last write to this address was with only two byte enables - check only those
3777
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3778
    begin
3779
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3780
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3781
    end
3782
    else
3783
        test_ok ;
3784
 
3785
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3786
    ok = 1 ;
3787
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3788
    if ( temp_val1[29] !== 0 )
3789
    begin
3790
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3791
        $display("Received Master Abort bit was set with no reason!") ;
3792
        test_fail("Received Master Abort bit was set with no reason") ;
3793
        ok = 0 ;
3794
    end
3795
 
3796
    if ( temp_val1[28] !== 1 )
3797
    begin
3798
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3799
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3800
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3801
        ok = 0 ;
3802
    end
3803
 
3804
    if ( ok )
3805
       test_ok ;
3806
 
3807
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3808
 
3809
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3810
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3811
 
3812
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3813
    for ( i = 0 ; i < 3 ; i = i + 1 )
3814
    begin
3815
        read_data`READ_ADDRESS = target_address + 4*i ;
3816
        read_data`READ_SEL     = 4'b1111 ;
3817
        wishbone_master.blk_read_data_in[i] = read_data ;
3818
    end
3819
 
3820
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3821
 
3822
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3823
 
3824
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3825
    begin
3826
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3827
        $display("Complete burst read through WB slave didn't succeed!") ;
3828
        test_fail("bridge didn't process Burst Read in an expected way") ;
3829
        disable main ;
3830
    end
3831
    else
3832
        test_ok ;
3833
 
3834
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3835
 
3836
    for ( i = 0 ; i < 3 ; i = i + 1 )
3837
    begin
3838
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3839
        read_data`READ_SEL     = 4'b1111 ;
3840
        wishbone_master.blk_read_data_in[i] = read_data ;
3841
    end
3842
 
3843
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3844
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3845
    write_flags`WB_TRANSFER_CAB    = 1 ;
3846
 
3847
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3848
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3849
 
3850
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3851
 
3852
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3853
    begin
3854
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3855
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3856
        $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) ;
3857
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3858
        disable main ;
3859
    end
3860
 
3861
    for ( i = 0 ; i < 3 ; i = i + 1 )
3862
    begin
3863
        ok = 1 ;
3864
        read_status = wishbone_master.blk_read_data_out[i] ;
3865
        temp_val1 = read_status`READ_DATA ;
3866
        temp_val2 = wmem_data[120 + i] ;
3867
 
3868
        // last write to this address was with only two byte enables - check only those
3869
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3870
        begin
3871
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3872
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3873
            ok = 0 ;
3874
        end
3875
    end
3876
 
3877
    if ( ok )
3878
        test_ok ;
3879
 
3880
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3881
    ok = 1 ;
3882
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3883
    if ( temp_val1[29] !== 0 )
3884
    begin
3885
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3886
        $display("Received Master Abort bit was set with no reason!") ;
3887
        test_fail("Received Master Abort bit was set with no reason") ;
3888
        ok = 0 ;
3889
    end
3890
 
3891
    if ( temp_val1[28] !== 1 )
3892
    begin
3893
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3894
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3895
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3896
        ok = 0 ;
3897
    end
3898
 
3899
    if ( ok )
3900
       test_ok ;
3901
 
3902
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3903
 
3904
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3905
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3906
 
3907
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3908
    for ( i = 0 ; i < 3 ; i = i + 1 )
3909
    begin
3910
        read_data`READ_ADDRESS = target_address + 4*i ;
3911
        read_data`READ_SEL     = 4'b1111 ;
3912
        wishbone_master.blk_read_data_in[i] = read_data ;
3913
    end
3914
 
3915
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3916
 
3917
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3918
 
3919
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3920
    begin
3921
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3922
        $display("Complete burst read through WB slave didn't succeed!") ;
3923
        test_fail("bridge didn't process Burst Read in an expected way") ;
3924
        disable main ;
3925
    end
3926
    else
3927
        test_ok ;
3928
 
3929
    // test error on IO write
3930
    // change base address
3931
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3932
    write_data`WRITE_SEL     = 4'b0101 ;
3933
    write_data`WRITE_ADDRESS = target_address ;
3934
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3935
 
3936
    write_flags`WB_TRANSFER_CAB    = 0 ;
3937
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3938
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3939
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3940
    fork
3941
    begin
3942
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3943
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3944
        begin
3945
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3946
            $display("WB slave failed to accept IO write!") ;
3947
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3948
            disable main ;
3949
        end
3950
    end
3951
    begin
3952
        musnt_respond(ok) ;
3953
        if ( ok !== 1 )
3954
        begin
3955
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3956
            $display("Testbench is configured wrong!") ;
3957
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3958
        end
3959
        else
3960
            test_ok ;
3961
    end
3962
    join
3963
 
3964
    // check statuses and everything else
3965
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3966
    ok = 1 ;
3967
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3968
    if ( temp_val1[8] !== 1 )
3969
    begin
3970
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3971
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3972
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3973
        ok = 0 ;
3974
    end
3975
 
3976
    if ( temp_val1[9] !== 1 )
3977
    begin
3978
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3979
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3980
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3981
        ok = 0 ;
3982
    end
3983
 
3984
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3985
    begin
3986
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3987
        $display("Value in W_ERR_CS register was wrong!") ;
3988
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3989
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3990
        ok = 0 ;
3991
    end
3992
 
3993
    if ( ok )
3994
        test_ok ;
3995
 
3996
    // check erroneous address and data
3997
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3998
    ok = 1 ;
3999
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4000
    if ( temp_val1 !== target_address )
4001
    begin
4002
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4003
        $display("Value in W_ERR_ADDR register was wrong!") ;
4004
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4005
        test_fail("WB Erroneous Address register didn't provide right value") ;
4006
        ok = 0 ;
4007
    end
4008
 
4009
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4010
    if ( temp_val1 !== 32'hAAAA_AAAA )
4011
    begin
4012
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4013
        $display("Value in W_ERR_DATA register was wrong!") ;
4014
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
4015
        test_fail("WB Erroneous Data register didn't provide right value") ;
4016
        ok = 0 ;
4017
    end
4018
 
4019
    if ( ok )
4020
        test_ok ;
4021
 
4022
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4023
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4024
    if ( temp_val1[1] !== 1 )
4025
    begin
4026
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4027
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4028
        test_fail("expected interrupt status bit was not set") ;
4029
    end
4030
    else
4031
        test_ok ;
4032
 
4033
    // clear interrupts and errors
4034
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4035
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4036
 
4037
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4038
    ok = 1 ;
4039
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4040
    if ( temp_val1[29] !== 1 )
4041
    begin
4042
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4043
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4044
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4045
        ok = 0 ;
4046
    end
4047
 
4048
    if ( temp_val1[28] !== 0 )
4049
    begin
4050
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4051
        $display("Received Target Abort bit was set for no reason!") ;
4052
        test_fail("Received Target Abort bit was set for no reason") ;
4053
        ok = 0 ;
4054
    end
4055
 
4056
    if ( ok )
4057
        test_ok ;
4058
 
4059
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4060
 
4061
    // disable image
4062
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4063
    if ( ok !== 1 )
4064
    begin
4065
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4066
        test_fail("WB Image Address Mask register couldn't be written") ;
4067
        disable main ;
4068
    end
4069
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4070
 
4071
end
4072
endtask
4073
 
4074
task parity_checking ;
4075
    reg   [11:0] ctrl_offset ;
4076
    reg   [11:0] ba_offset ;
4077
    reg   [11:0] am_offset ;
4078
    reg   [11:0] ta_offset ;
4079
    reg `WRITE_STIM_TYPE write_data ;
4080
    reg `READ_STIM_TYPE  read_data ;
4081
    reg `READ_RETURN_TYPE read_status ;
4082
 
4083
    reg `WRITE_RETURN_TYPE write_status ;
4084
    reg `WB_TRANSFER_FLAGS write_flags ;
4085
    reg [31:0] temp_val1 ;
4086
    reg [31:0] temp_val2 ;
4087
    reg        ok   ;
4088
    reg [11:0] pci_ctrl_offset ;
4089
    reg [31:0] image_base ;
4090
    reg [31:0] target_address ;
4091
    reg [11:0] icr_offset ;
4092
    reg [11:0] isr_offset ;
4093
    reg [11:0] p_ba_offset ;
4094
    reg [11:0] p_am_offset ;
4095
    reg [11:0] p_ctrl_offset ;
4096
    integer    i ;
4097
    reg        perr_asserted ;
4098
begin:main
4099
    $display("******************************* Testing Parity Checker functions ********************************") ;
4100
    $display("Testing Parity Errors during Master Transactions!") ;
4101
    $display("Introducing Parity Erros to Master Writes!") ;
4102
    $fdisplay(pci_mon_log_file_desc,
4103
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4104
 
4105
    // image 1 is used for error testing, since it is always implemented
4106
    pci_ctrl_offset = 12'h004 ;
4107
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4108
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4109
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4110
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4111
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4112
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4113
 
4114
    // image 1 for PCI target
4115
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4116
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4117
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4118
 
4119
    target_address  = `BEH_TAR1_MEM_START ;
4120
    image_base      = 0 ;
4121
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4122
 
4123
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4124
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4125
    write_flags                    = 0 ;
4126
    write_flags`INIT_WAITS         = tb_init_waits ;
4127
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4128
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4129
 
4130
    // enable master & target operation and disable parity functions
4131
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4132
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4133
    if ( ok !== 1 )
4134
    begin
4135
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4136
        test_fail("PCI Device Control register could not be written to") ;
4137
        disable main ;
4138
    end
4139
 
4140
    // prepare image control register
4141
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4142
    if ( ok !== 1 )
4143
    begin
4144
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4145
        test_fail("WB Image Control register could not be written to") ;
4146
        disable main ;
4147
    end
4148
 
4149
    // prepare base address register
4150
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4151
    if ( ok !== 1 )
4152
    begin
4153
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4154
        test_fail("WB Image Base Address register could not be written to") ;
4155
        disable main ;
4156
    end
4157
 
4158
    // write address mask register
4159
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4160
    if ( ok !== 1 )
4161
    begin
4162
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4163
        test_fail("WB Image Address Mask register could not be written to") ;
4164
        disable main ;
4165
    end
4166
 
4167
    // disable parity interrupts
4168
    config_write( icr_offset, 0, 4'hF, ok ) ;
4169
    if ( ok !== 1 )
4170
    begin
4171
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4172
        test_fail("Interrupt Control register could not be written to") ;
4173
        disable main ;
4174
    end
4175
 
4176
    write_data`WRITE_ADDRESS = target_address ;
4177
    write_data`WRITE_DATA    = wmem_data[0] ;
4178
    write_data`WRITE_SEL     = 4'b1111 ;
4179
 
4180
    // enable target's 1 response to parity errors
4181 45 mihad
    configuration_cycle_write(0,                        // bus number
4182
                              `TAR1_IDSEL_INDEX - 11,   // device number
4183
                              0,                        // function number
4184
                              1,                        // register number
4185
                              0,                        // type of configuration cycle
4186
                              4'b0001,                  // byte enables
4187
                              32'h0000_0047             // data
4188 15 mihad
                             ) ;
4189
 
4190
    // disable target's 2 response to parity errors
4191 45 mihad
    configuration_cycle_write(0,                        // bus number
4192
                              `TAR2_IDSEL_INDEX - 11,   // device number
4193
                              0,                        // function number
4194
                              1,                        // register number
4195
                              0,                        // type of configuration cycle
4196
                              4'b0001,                  // byte enables
4197
                              32'h0000_0007             // data
4198 15 mihad
                             ) ;
4199
 
4200
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4201
 
4202
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4203
    fork
4204
    begin
4205
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4206
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4207
        begin
4208
            $display("Parity checker testing failed! Time %t ", $time) ;
4209
            $display("Bridge failed to process single memory write!") ;
4210
            test_fail("bridge failed to post single WB memory write") ;
4211
            disable main ;
4212
        end
4213
    end
4214
    begin:wait_perr1
4215
        perr_asserted = 0 ;
4216
        @(posedge pci_clock) ;
4217
 
4218 35 mihad
        while ( PERR !== 0 )
4219 15 mihad
            @(posedge pci_clock) ;
4220
 
4221 35 mihad
        perr_asserted = 1 ;
4222 15 mihad
 
4223
    end
4224
    begin
4225
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4226
 
4227
        if ( ok !== 1 )
4228
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4229
 
4230 35 mihad
        repeat(2)
4231 15 mihad
            @(posedge pci_clock) ;
4232
 
4233 35 mihad
        #1 ;
4234
        if ( !perr_asserted )
4235
            disable wait_perr1 ;
4236 15 mihad
    end
4237
    join
4238
 
4239
    if ( perr_asserted && ok )
4240
    begin
4241
        test_ok ;
4242
    end
4243
    else
4244
    if ( ~perr_asserted )
4245
    begin
4246
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4247
        disable main ;
4248
    end
4249
 
4250
    // check all the statuses - if HOST is defined, wait for them to be synced
4251
    `ifdef HOST
4252
    repeat(4)
4253
        @(posedge wb_clock) ;
4254
    `endif
4255
 
4256
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4257
    ok = 1 ;
4258
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4259 45 mihad
    if ( temp_val1[31] !== 0 )
4260 15 mihad
    begin
4261
        $display("Parity checker testing failed! Time %t ", $time) ;
4262 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4263
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4264 15 mihad
        ok = 0 ;
4265
    end
4266
 
4267
    if ( temp_val1[30] !== 0 )
4268
    begin
4269
        $display("Parity checker testing failed! Time %t ", $time) ;
4270
        $display("Signalled System Error bit was set for no reason!") ;
4271
        test_fail("Signalled System Error bit was set for no reason") ;
4272
        ok = 0 ;
4273
    end
4274
 
4275
    if ( temp_val1[24] !== 0 )
4276
    begin
4277
        $display("Parity checker testing failed! Time %t ", $time) ;
4278
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4279
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4280
        ok = 0 ;
4281
    end
4282
 
4283
    if ( ok )
4284
        test_ok ;
4285
 
4286
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4287
    // clear parity bits and enable parity response
4288
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4289
    if ( ok !== 1 )
4290
    begin
4291
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4292
        test_fail("write to PCI Status Register failed") ;
4293
        disable main ;
4294
    end
4295
 
4296
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4297
    fork
4298
    begin
4299
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4300
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4301
        begin
4302
            $display("Parity checker testing failed! Time %t ", $time) ;
4303
            $display("Bridge failed to process single memory write!") ;
4304
            test_fail("bridge failed to post single memory write") ;
4305
            disable main ;
4306
        end
4307
    end
4308
    begin:wait_perr2
4309
        perr_asserted = 0 ;
4310
        @(posedge pci_clock) ;
4311
 
4312 35 mihad
        while ( PERR !== 0 )
4313 15 mihad
            @(posedge pci_clock) ;
4314
 
4315 35 mihad
        perr_asserted = 1 ;
4316 15 mihad
 
4317
    end
4318
    begin
4319
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4320
 
4321
        if ( ok !== 1 )
4322
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4323
 
4324 35 mihad
        repeat(2)
4325 15 mihad
            @(posedge pci_clock) ;
4326
 
4327 35 mihad
        #1 ;
4328
        if (!perr_asserted)
4329
            disable wait_perr2 ;
4330 15 mihad
    end
4331
    join
4332
 
4333
    if ( perr_asserted && ok )
4334
    begin
4335
        test_ok ;
4336
    end
4337
    else
4338
    if ( ~perr_asserted )
4339
    begin
4340
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4341
        disable main ;
4342
    end
4343
 
4344
    // check all the statuses - if HOST is defined, wait for them to be synced
4345
    `ifdef HOST
4346
    repeat(4)
4347
        @(posedge wb_clock) ;
4348
    `endif
4349
 
4350
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4351
    ok = 1 ;
4352
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4353 45 mihad
    if ( temp_val1[31] !== 0 )
4354 15 mihad
    begin
4355
        $display("Parity checker testing failed! Time %t ", $time) ;
4356 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4357
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4358 15 mihad
        ok = 0 ;
4359
    end
4360
 
4361
    if ( temp_val1[30] !== 0 )
4362
    begin
4363
        $display("Parity checker testing failed! Time %t ", $time) ;
4364
        $display("Signalled System Error bit was set for no reason!") ;
4365
        test_fail("Signalled System Error bit was set for no reason") ;
4366
        ok = 0 ;
4367
    end
4368
 
4369
    if ( temp_val1[24] !== 1 )
4370
    begin
4371
        $display("Parity checker testing failed! Time %t ", $time) ;
4372 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!") ;
4373
        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") ;
4374 15 mihad
        ok = 0 ;
4375
    end
4376
 
4377
    if ( ok )
4378
        test_ok ;
4379
 
4380
    // clear status bits and disable parity error response
4381
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4382
 
4383
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4384
 
4385
    // disable perr generation and perform a write - no bits should be set
4386
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4387
    fork
4388
    begin
4389
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4390
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4391
        begin
4392
            $display("Parity checker testing failed! Time %t ", $time) ;
4393
            $display("Bridge failed to process single memory write!") ;
4394
            test_fail("bridge failed to post single memory write") ;
4395
            disable main ;
4396
        end
4397
    end
4398
    begin
4399
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4400
 
4401
        if ( ok !== 1 )
4402
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4403
        else
4404
            test_ok ;
4405
 
4406
        repeat(3)
4407
            @(posedge pci_clock) ;
4408
    end
4409
    join
4410
 
4411
    `ifdef HOST
4412
    repeat(4)
4413
        @(posedge wb_clock) ;
4414
    `endif
4415
 
4416
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4417
    ok = 1 ;
4418
 
4419
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4420
    if ( temp_val1[31] !== 0 )
4421
    begin
4422
        $display("Parity checker testing failed! Time %t ", $time) ;
4423
        $display("Detected Parity Error bit was set for no reason!") ;
4424
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4425
        ok = 0 ;
4426
    end
4427
 
4428
    if ( temp_val1[30] !== 0 )
4429
    begin
4430
        $display("Parity checker testing failed! Time %t ", $time) ;
4431
        $display("Signalled System Error bit was set for no reason!") ;
4432
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4433
        ok = 0 ;
4434
    end
4435
 
4436
    if ( temp_val1[24] !== 0 )
4437
    begin
4438
        $display("Parity checker testing failed! Time %t ", $time) ;
4439
        $display("Master Data Parity Error bit was set for no reason!") ;
4440
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4441
        ok = 0 ;
4442
    end
4443
 
4444
    if ( ok )
4445
        test_ok ;
4446
 
4447
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4448
 
4449
    read_data = 0 ;
4450
    read_data`READ_ADDRESS  = target_address ;
4451
    read_data`READ_SEL      = 4'hF ;
4452
    read_data`READ_TAG_STIM = 0 ;
4453
 
4454
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4455
 
4456
    // enable parity and system error interrupts
4457
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4458
 
4459
    // enable parity error response
4460
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4461
 
4462
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4463
 
4464
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4465
    fork
4466
    begin
4467
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4468
    end
4469
    begin:wait_perr4
4470
        perr_asserted = 0 ;
4471
        @(posedge pci_clock) ;
4472 35 mihad
        while ( PERR !== 0 )
4473 15 mihad
            @(posedge pci_clock) ;
4474
 
4475 35 mihad
        perr_asserted = 1 ;
4476 15 mihad
 
4477
    end
4478
    begin
4479
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4480
 
4481
        if ( ok !== 1 )
4482
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4483
 
4484
        repeat(2)
4485
            @(posedge pci_clock) ;
4486
 
4487 35 mihad
        #1 ;
4488
        if ( !perr_asserted )
4489
            disable wait_perr4 ;
4490 15 mihad
    end
4491
    join
4492
 
4493
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4494
    begin
4495
        $display("Parity checker testing failed! Time %t ", $time) ;
4496
        $display("Bridge failed to process single memory read!") ;
4497
        test_fail("bridge didn't process single memory read correctly") ;
4498
        ok = 0 ;
4499
    end
4500
 
4501
    if ( perr_asserted && ok )
4502
    begin
4503
        test_ok ;
4504
    end
4505
    else
4506
    if ( ~perr_asserted )
4507
    begin
4508
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4509
        disable main ;
4510
    end
4511
 
4512
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4513
    // interrupt should also be present
4514
    `ifdef HOST
4515
        repeat(4)
4516 26 mihad
            @(posedge pci_clock) ;
4517
        repeat(4)
4518 15 mihad
            @(posedge wb_clock) ;
4519
 
4520
        if ( INT_O !== 1 )
4521
        begin
4522
            $display("Parity checker testing failed! Time %t ", $time) ;
4523
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4524
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4525
        end
4526
        else
4527
            test_ok ;
4528
    `else
4529
    `ifdef GUEST
4530 26 mihad
        repeat(4)
4531
            @(posedge wb_clock) ;
4532
        repeat(4)
4533 15 mihad
            @(posedge pci_clock) ;
4534
 
4535
        if ( INTA !== 1 )
4536
        begin
4537
            $display("Parity checker testing failed! Time %t ", $time) ;
4538
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4539
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4540
        end
4541
        else
4542
            test_ok ;
4543
    `endif
4544
    `endif
4545
 
4546
    // check statuses!
4547
 
4548
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4549
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4550
    ok = 1 ;
4551
 
4552
    if ( temp_val1[31] !== 1 )
4553
    begin
4554
        $display("Parity checker testing failed! Time %t ", $time) ;
4555 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4556
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4557 15 mihad
        ok = 0 ;
4558
    end
4559
 
4560
    if ( temp_val1[30] !== 0 )
4561
    begin
4562
        $display("Parity checker testing failed! Time %t ", $time) ;
4563
        $display("Signalled System Error bit was set for no reason!") ;
4564
        test_fail("Signalled System Error bit was set for no reason") ;
4565
        ok = 0 ;
4566
    end
4567
 
4568
    if ( temp_val1[24] !== 1 )
4569
    begin
4570
        $display("Parity checker testing failed! Time %t ", $time) ;
4571 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4572
        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") ;
4573 15 mihad
        ok = 0 ;
4574
    end
4575
 
4576
    if ( ok )
4577
        test_ok ;
4578
 
4579
    // clear statuses and disable parity error response
4580
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4581
 
4582
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4583
    ok = 1 ;
4584
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4585
 
4586
    if ( temp_val1[4] !== 0 )
4587
    begin
4588
        $display("Parity checker testing failed! Time %t ", $time) ;
4589
        $display("System error interrupt status bit set for no reason!") ;
4590
        test_fail("System error interrupt status bit set for no reason") ;
4591
        ok = 0 ;
4592
    end
4593
 
4594
    `ifdef HOST
4595
    if ( temp_val1[3] !== 1 )
4596
    begin
4597
        $display("Parity checker testing failed! Time %t ", $time) ;
4598
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4599
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4600
        ok = 0 ;
4601
    end
4602
    `else
4603
    if ( temp_val1[3] !== 0 )
4604
    begin
4605
        $display("Parity checker testing failed! Time %t ", $time) ;
4606
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4607
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4608
        ok = 0 ;
4609
    end
4610
    `endif
4611
 
4612
    if ( ok )
4613
        test_ok ;
4614
 
4615
    // clear int statuses
4616
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4617
 
4618
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4619
 
4620
    `ifdef HOST
4621
        repeat(4)
4622 26 mihad
            @(posedge pci_clock) ;
4623
        repeat(4)
4624 15 mihad
            @(posedge wb_clock) ;
4625
 
4626
        if ( INT_O !== 0 )
4627
        begin
4628
            $display("Parity checker testing failed! Time %t ", $time) ;
4629
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4630
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4631
        end
4632
        else
4633
            test_ok ;
4634
    `else
4635
    `ifdef GUEST
4636 26 mihad
        repeat(4)
4637
            @(posedge wb_clock) ;
4638
        repeat(4)
4639 15 mihad
            @(posedge pci_clock) ;
4640
 
4641
        if ( INTA !== 1 )
4642
        begin
4643
            $display("Parity checker testing failed! Time %t ", $time) ;
4644
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4645
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4646
        end
4647
        else
4648
            test_ok ;
4649
    `endif
4650
    `endif
4651
 
4652
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4653
 
4654
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4655
    fork
4656
    begin
4657
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4658
    end
4659
    begin:wait_perr5
4660
        perr_asserted = 0 ;
4661
        @(posedge pci_clock) ;
4662
        while ( PERR === 1 )
4663
            @(posedge pci_clock) ;
4664
 
4665
        perr_asserted = 1 ;
4666
        $display("Parity checker testing failed! Time %t ", $time) ;
4667 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4668
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4669 15 mihad
    end
4670
    begin
4671
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4672
        if ( ok !== 1 )
4673
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4674
 
4675
        // perr can be asserted on idle or next PCI address phase
4676
        repeat(2)
4677
            @(posedge pci_clock) ;
4678
 
4679 35 mihad
        #1 ;
4680
        if ( !perr_asserted )
4681
            disable wait_perr5 ;
4682 15 mihad
    end
4683
    join
4684
 
4685
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4686
    begin
4687
        $display("Parity checker testing failed! Time %t ", $time) ;
4688
        $display("Bridge failed to process single memory read!") ;
4689
        test_fail("bridge failed to process single memory read correctly") ;
4690
        ok = 0 ;
4691
    end
4692
 
4693
    if ( ok && !perr_asserted)
4694
        test_ok ;
4695
 
4696
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4697
 
4698
    // interrupts should not be present
4699
    `ifdef HOST
4700
        repeat( 4 )
4701 26 mihad
            @(posedge pci_clock) ;
4702
        repeat( 4 )
4703 15 mihad
            @(posedge wb_clock) ;
4704
        if ( INT_O !== 0 )
4705
        begin
4706
            $display("Parity checker testing failed! Time %t ", $time) ;
4707
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4708
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4709
        end
4710
        else
4711
            test_ok ;
4712
    `else
4713
    `ifdef GUEST
4714
        repeat( 4 )
4715 26 mihad
            @(posedge wb_clock) ;
4716
        repeat( 4 )
4717 15 mihad
            @(posedge pci_clock) ;
4718
        if ( INTA !== 1 )
4719
        begin
4720
            $display("Parity checker testing failed! Time %t ", $time) ;
4721
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4722
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4723
        end
4724
        else
4725
            test_ok ;
4726
    `endif
4727
    `endif
4728
 
4729
    // check statuses!
4730
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4731
    ok = 1 ;
4732
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4733
    if ( temp_val1[31] !== 1 )
4734
    begin
4735
        $display("Parity checker testing failed! Time %t ", $time) ;
4736 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4737 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4738
        ok = 0 ;
4739
    end
4740
 
4741
    if ( temp_val1[30] !== 0 )
4742
    begin
4743
        $display("Parity checker testing failed! Time %t ", $time) ;
4744
        $display("Signalled System Error bit was set for no reason!") ;
4745
        test_fail("Signalled System Error bit was set for no reason") ;
4746
        ok = 0 ;
4747
    end
4748
 
4749
    if ( temp_val1[24] !== 0 )
4750
    begin
4751
        $display("Parity checker testing failed! Time %t ", $time) ;
4752 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4753 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4754
        ok = 0 ;
4755
    end
4756
 
4757
    if ( ok )
4758
        test_ok ;
4759
 
4760
    // clear statuses
4761
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4762
 
4763
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4764
    ok = 1 ;
4765
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4766
 
4767
    if ( temp_val1[4] !== 0 )
4768
    begin
4769
        $display("Parity checker testing failed! Time %t ", $time) ;
4770
        $display("System error interrupt status bit set for no reason!") ;
4771
        test_fail("System error interrupt status bit set for no reason") ;
4772
        ok = 0 ;
4773
    end
4774
 
4775
    if ( temp_val1[3] !== 0 )
4776
    begin
4777
        $display("Parity checker testing failed! Time %t ", $time) ;
4778
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4779
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4780
        ok = 0 ;
4781
    end
4782
 
4783
    if ( ok )
4784
        test_ok ;
4785
 
4786
    // enable all responses to parity errors!
4787
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4788
 
4789
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4790
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4791
 
4792
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4793
 
4794
    // repeat a read
4795
    fork
4796
    begin
4797
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4798
    end
4799
    begin:wait_perr6
4800
        perr_asserted = 0 ;
4801
        @(posedge pci_clock) ;
4802
        while ( PERR === 1 )
4803
            @(posedge pci_clock) ;
4804
 
4805
        perr_asserted = 1 ;
4806
        $display("Parity checker testing failed! Time %t ", $time) ;
4807
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4808
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4809
    end
4810
    begin
4811
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4812
        if ( ok !== 1 )
4813
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4814
 
4815
        repeat(2)
4816
            @(posedge pci_clock) ;
4817
 
4818 35 mihad
        #1 ;
4819
        if ( !perr_asserted )
4820
            disable wait_perr6 ;
4821 15 mihad
    end
4822
    join
4823
 
4824
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4825
    begin
4826
        $display("Parity checker testing failed! Time %t ", $time) ;
4827
        $display("Bridge failed to process single memory read!") ;
4828
        test_fail("bridge didn't process single memory read as expected") ;
4829
        ok = 0 ;
4830
    end
4831
 
4832
    if ( ok && !perr_asserted)
4833
        test_ok ;
4834
 
4835
    // check statuses!
4836
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4837
    ok = 1 ;
4838
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4839
    if ( temp_val1[31] !== 0 )
4840
    begin
4841
        $display("Parity checker testing failed! Time %t ", $time) ;
4842
        $display("Detected Parity Error bit was set for no reason!") ;
4843
        test_fail("Detected Parity Error bit was set for no reason") ;
4844
        ok = 0 ;
4845
    end
4846
 
4847
    if ( temp_val1[30] !== 0 )
4848
    begin
4849
        $display("Parity checker testing failed! Time %t ", $time) ;
4850
        $display("Signalled System Error bit was set for no reason!") ;
4851
        test_fail("Signalled System Error bit was set for no reason") ;
4852
        ok = 0 ;
4853
    end
4854
 
4855
    if ( temp_val1[24] !== 0 )
4856
    begin
4857
        $display("Parity checker testing failed! Time %t ", $time) ;
4858
        $display("Master Data Parity Error bit was set for no reason!") ;
4859
        test_fail("Master Data Parity Error bit was set for no reason") ;
4860
        ok = 0 ;
4861
    end
4862
 
4863
    if ( ok )
4864
        test_ok ;
4865
 
4866
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4867
    ok = 1 ;
4868
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4869
 
4870
    if ( temp_val1[4] !== 0 )
4871
    begin
4872
        $display("Parity checker testing failed! Time %t ", $time) ;
4873
        $display("System error interrupt status bit set for no reason!") ;
4874
        test_fail("System error interrupt status bit set for no reason") ;
4875
        ok = 0 ;
4876
    end
4877
 
4878
    if ( temp_val1[3] !== 0 )
4879
    begin
4880
        $display("Parity checker testing failed! Time %t ", $time) ;
4881
        $display("Parity error interrupt status bit set for no reason!") ;
4882
        test_fail("Parity error interrupt status bit set for no reason") ;
4883
        ok = 0 ;
4884
    end
4885
 
4886
    if ( ok )
4887
        test_ok ;
4888
 
4889
    $display("Presenting address parity error on PCI bus!") ;
4890
    // enable parity errors - this should not affect system errors
4891
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4892
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4893
 
4894
    // perform PCI write
4895
    // check transaction progress
4896
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4897
    fork
4898
    begin
4899
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4900
               target_address, 32'h1234_5678,
4901
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4902
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4903
        do_pause( 1 ) ;
4904
    end
4905
    begin:wait_serr7
4906
        perr_asserted = 0 ;
4907
        @(posedge pci_clock) ;
4908
        while( SERR === 1 )
4909
            @(posedge pci_clock) ;
4910
 
4911
        perr_asserted = 1 ;
4912
        $display("Parity checker testing failed! Time %t ", $time) ;
4913
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4914
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4915
    end
4916
    begin
4917
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4918
        if ( ok !== 1 )
4919
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4920
 
4921 35 mihad
        if ( !perr_asserted )
4922
            disable wait_serr7 ;
4923 15 mihad
    end
4924
    join
4925
 
4926
    if ( ok && !perr_asserted)
4927
        test_ok ;
4928
 
4929
    // check statuses!
4930
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4931
    ok = 1 ;
4932
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4933
    if ( temp_val1[31] !== 1 )
4934
    begin
4935
        $display("Parity checker testing failed! Time %t ", $time) ;
4936
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4937
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4938
        ok = 0 ;
4939
    end
4940
 
4941
    if ( temp_val1[30] !== 0 )
4942
    begin
4943
        $display("Parity checker testing failed! Time %t ", $time) ;
4944
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4945
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4946
        ok = 0 ;
4947
    end
4948
 
4949
    if ( temp_val1[24] !== 0 )
4950
    begin
4951
        $display("Parity checker testing failed! Time %t ", $time) ;
4952
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4953
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4954
        ok = 0 ;
4955
    end
4956
 
4957
    if ( ok )
4958
        test_ok ;
4959
 
4960
    // clear statuses
4961
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4962
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4963
    fork
4964
    begin
4965
        ipci_unsupported_commands_master.master_reference
4966
        (
4967
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4968
            32'h5555_5555,      // second part of address in dual address cycle
4969
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4970
            `BC_MEM_WRITE,      // normal command
4971
            4'h0,               // byte enables
4972
            32'h1234_5678,      // data
4973
            1'b1,               // make address parity error on first phase of dual address
4974
            1'b0,               // make address parity error on second phase of dual address
4975
            ok                  // result of operation
4976
        ) ;
4977 35 mihad
        if ( !perr_asserted )
4978
            disable wait_serr8 ;
4979 15 mihad
    end
4980
    begin:wait_serr8
4981
        perr_asserted = 0 ;
4982
        @(posedge pci_clock) ;
4983
        while( SERR === 1 )
4984
            @(posedge pci_clock) ;
4985
 
4986
        perr_asserted = 1 ;
4987
        $display("Parity checker testing failed! Time %t ", $time) ;
4988
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4989
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4990
    end
4991
    join
4992
 
4993
    if ( ok && !perr_asserted)
4994
        test_ok ;
4995
 
4996
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4997
    fork
4998
    begin
4999
        ipci_unsupported_commands_master.master_reference
5000
        (
5001
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5002
            32'h5555_5555,      // second part of address in dual address cycle
5003
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5004
            `BC_MEM_WRITE,      // normal command
5005
            4'h0,               // byte enables
5006
            32'h1234_5678,      // data
5007
            1'b0,               // make address parity error on first phase of dual address
5008
            1'b1,               // make address parity error on second phase of dual address
5009
            ok                  // result of operation
5010
        ) ;
5011 35 mihad
        if ( !perr_asserted )
5012
            disable wait_serr9 ;
5013 15 mihad
    end
5014
    begin:wait_serr9
5015
        perr_asserted = 0 ;
5016
        @(posedge pci_clock) ;
5017
        while( SERR === 1 )
5018
            @(posedge pci_clock) ;
5019
 
5020
        perr_asserted = 1 ;
5021
        $display("Parity checker testing failed! Time %t ", $time) ;
5022
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5023
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5024
    end
5025
    join
5026
 
5027
    if ( ok && !perr_asserted)
5028
        test_ok ;
5029
 
5030
    // check statuses!
5031
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5032
    ok = 1 ;
5033
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5034
    if ( temp_val1[31] !== 1 )
5035
    begin
5036
        $display("Parity checker testing failed! Time %t ", $time) ;
5037
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5038
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5039
        ok = 0 ;
5040
    end
5041
 
5042
    if ( temp_val1[30] !== 0 )
5043
    begin
5044
        $display("Parity checker testing failed! Time %t ", $time) ;
5045
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5046
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5047
        ok = 0 ;
5048
    end
5049
 
5050
    if ( temp_val1[24] !== 0 )
5051
    begin
5052
        $display("Parity checker testing failed! Time %t ", $time) ;
5053
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5054
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5055
        ok = 0 ;
5056
    end
5057
 
5058
    if ( ok )
5059
        test_ok ;
5060
 
5061
    // clear statuses
5062
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5063
 
5064
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5065
    fork
5066
    begin
5067
        ipci_unsupported_commands_master.master_reference
5068
        (
5069
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5070
            32'h5555_5555,      // second part of address in dual address cycle
5071
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5072
            `BC_MEM_WRITE,      // normal command
5073
            4'h0,               // byte enables
5074
            32'h1234_5678,      // data
5075
            1'b1,               // make address parity error on first phase of dual address
5076
            1'b1,               // make address parity error on second phase of dual address
5077
            ok                  // result of operation
5078
        ) ;
5079 35 mihad
        if ( !perr_asserted )
5080
            disable wait_serr10 ;
5081 15 mihad
    end
5082
    begin:wait_serr10
5083
        perr_asserted = 0 ;
5084
        @(posedge pci_clock) ;
5085
        while( SERR === 1 )
5086
            @(posedge pci_clock) ;
5087
 
5088
        perr_asserted = 1 ;
5089
        $display("Parity checker testing failed! Time %t ", $time) ;
5090
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5091
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5092
    end
5093
    join
5094
 
5095
    if ( ok && !perr_asserted)
5096
        test_ok ;
5097
 
5098
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5099
 
5100
    `ifdef HOST
5101
        repeat(4)
5102 26 mihad
            @(posedge pci_clock) ;
5103
        repeat(4)
5104 15 mihad
            @(posedge wb_clock) ;
5105
        if ( INT_O !== 0 )
5106
        begin
5107
            $display("Parity checker testing failed! Time %t ", $time) ;
5108
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5109
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5110
        end
5111
        else
5112
            test_ok ;
5113
    `else
5114
    `ifdef GUEST
5115 26 mihad
        repeat(4)
5116
            @(posedge wb_clock) ;
5117
        repeat(4)
5118 15 mihad
            @(posedge pci_clock) ;
5119
 
5120
        if ( INTA !== 1 )
5121
        begin
5122
            $display("Parity checker testing failed! Time %t ", $time) ;
5123
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5124
            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") ;
5125
        end
5126
        else
5127
            test_ok ;
5128
    `endif
5129
    `endif
5130
 
5131
    // check statuses!
5132
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5133
    ok = 1 ;
5134
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5135
    if ( temp_val1[31] !== 1 )
5136
    begin
5137
        $display("Parity checker testing failed! Time %t ", $time) ;
5138
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5139
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5140
        ok = 0 ;
5141
    end
5142
 
5143
    if ( temp_val1[30] !== 0 )
5144
    begin
5145
        $display("Parity checker testing failed! Time %t ", $time) ;
5146
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5147
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5148
        ok = 0 ;
5149
    end
5150
 
5151
    if ( temp_val1[24] !== 0 )
5152
    begin
5153
        $display("Parity checker testing failed! Time %t ", $time) ;
5154
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5155
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5156
        ok = 0 ;
5157
    end
5158
 
5159
    if ( ok )
5160
        test_ok ;
5161
 
5162
    // clear statuses
5163
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5164
 
5165
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5166
    ok = 1 ;
5167
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5168
 
5169
    if ( temp_val1[4] !== 0 )
5170
    begin
5171
        $display("Parity checker testing failed! Time %t ", $time) ;
5172
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5173
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5174
        ok = 0 ;
5175
    end
5176
 
5177
    if ( temp_val1[3] !== 0 )
5178
    begin
5179
        $display("Parity checker testing failed! Time %t ", $time) ;
5180
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5181
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5182
        ok = 0 ;
5183
    end
5184
 
5185
    if ( ok )
5186
        test_ok ;
5187
 
5188
    // now enable system error signaling and test response
5189
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5190
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5191
 
5192
    fork
5193
    begin
5194
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5195
               target_address, 32'h1234_5678,
5196
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5197
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5198
        do_pause( 1 ) ;
5199
    end
5200
    begin:wait_serr11
5201
        perr_asserted = 0 ;
5202
        @(posedge pci_clock) ;
5203 35 mihad
        while( SERR !== 0 )
5204 15 mihad
            @(posedge pci_clock) ;
5205
 
5206 35 mihad
        perr_asserted = 1 ;
5207 15 mihad
    end
5208
    begin
5209
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5210
        if ( ok !== 1 )
5211
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5212
 
5213
        @(posedge pci_clock) ;
5214 35 mihad
        #1 ;
5215
        if ( !perr_asserted )
5216
            disable wait_serr11 ;
5217 15 mihad
    end
5218
    join
5219
 
5220
    if ( ok && perr_asserted)
5221
        test_ok ;
5222
    else
5223
    if ( !perr_asserted )
5224
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5225
 
5226
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5227
 
5228
    `ifdef HOST
5229
        repeat(4)
5230 26 mihad
            @(posedge pci_clock) ;
5231
        repeat(4)
5232 15 mihad
            @(posedge wb_clock) ;
5233
        if ( INT_O !== 1 )
5234
        begin
5235
            $display("Parity checker testing failed! Time %t ", $time) ;
5236
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5237
            test_fail("Interrupt Request was not triggered as expected") ;
5238
        end
5239
        else
5240
            test_ok ;
5241
    `else
5242
    `ifdef GUEST
5243 26 mihad
        repeat(4)
5244
            @(posedge wb_clock) ;
5245
        repeat(4)
5246 15 mihad
            @(posedge pci_clock) ;
5247
 
5248
        if ( INTA !== 1 )
5249
        begin
5250
            $display("Parity checker testing failed! Time %t ", $time) ;
5251
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5252
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5253
        end
5254
        else
5255
            test_ok ;
5256
    `endif
5257
    `endif
5258
 
5259
    // check statuses!
5260
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5261
    ok = 1 ;
5262
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5263
    if ( temp_val1[31] !== 1 )
5264
    begin
5265
        $display("Parity checker testing failed! Time %t ", $time) ;
5266
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5267
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5268
        ok = 0 ;
5269
    end
5270
 
5271
    if ( temp_val1[30] !== 1 )
5272
    begin
5273
        $display("Parity checker testing failed! Time %t ", $time) ;
5274
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5275
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5276
        ok = 0 ;
5277
    end
5278
 
5279
    if ( temp_val1[24] !== 0 )
5280
    begin
5281
        $display("Parity checker testing failed! Time %t ", $time) ;
5282
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5283
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5284
        ok = 0 ;
5285
    end
5286
 
5287
    if ( ok )
5288
        test_ok ;
5289
 
5290
    // clear statuses
5291
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5292
 
5293
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5294
 
5295
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5296
    ok = 1 ;
5297
 
5298
    `ifdef HOST
5299
    if ( temp_val1[4] !== 1 )
5300
    begin
5301
        $display("Parity checker testing failed! Time %t ", $time) ;
5302
        $display("System error interrupt status bit not set when expected!") ;
5303
        test_fail("System error interrupt status bit not set when expected") ;
5304
        ok = 0 ;
5305
    end
5306
    `else
5307
    if ( temp_val1[4] !== 0 )
5308
    begin
5309
        $display("Parity checker testing failed! Time %t ", $time) ;
5310
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5311
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5312
        ok = 0 ;
5313
    end
5314
    `endif
5315
 
5316
    if ( temp_val1[3] !== 0 )
5317
    begin
5318
        $display("Parity checker testing failed! Time %t ", $time) ;
5319
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5320
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5321
        ok = 0 ;
5322
    end
5323
 
5324
    if ( ok )
5325
        test_ok ;
5326
 
5327
    // clear statuses
5328
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5329
 
5330
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5331
    fork
5332
    begin
5333
        ipci_unsupported_commands_master.master_reference
5334
        (
5335
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5336
            32'h5555_5555,      // second part of address in dual address cycle
5337
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5338
            `BC_MEM_WRITE,      // normal command
5339
            4'h0,               // byte enables
5340
            32'h1234_5678,      // data
5341
            1'b1,               // make address parity error on first phase of dual address
5342
            1'b0,               // make address parity error on second phase of dual address
5343
            ok                  // result of operation
5344
        ) ;
5345 35 mihad
        if ( !perr_asserted )
5346
            disable wait_serr14 ;
5347 15 mihad
    end
5348
    begin:wait_serr14
5349
        perr_asserted = 0 ;
5350
        @(posedge pci_clock) ;
5351 35 mihad
        while( SERR !== 0 )
5352 15 mihad
            @(posedge pci_clock) ;
5353
 
5354 35 mihad
        perr_asserted = 1 ;
5355 15 mihad
    end
5356
    join
5357
 
5358
    if ( ok && perr_asserted)
5359
        test_ok ;
5360
    else
5361
    if ( !perr_asserted )
5362
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5363
 
5364
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5365
 
5366
    `ifdef HOST
5367
        repeat(4)
5368 26 mihad
            @(posedge pci_clock) ;
5369
        repeat(4)
5370 15 mihad
            @(posedge wb_clock) ;
5371
        if ( INT_O !== 1 )
5372
        begin
5373
            $display("Parity checker testing failed! Time %t ", $time) ;
5374
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5375
            test_fail("Interrupt Request was not triggered as expected") ;
5376
        end
5377
        else
5378
            test_ok ;
5379
    `else
5380
    `ifdef GUEST
5381 26 mihad
        repeat(4)
5382
            @(posedge wb_clock) ;
5383
        repeat(4)
5384 15 mihad
            @(posedge pci_clock) ;
5385
 
5386
        if ( INTA !== 1 )
5387
        begin
5388
            $display("Parity checker testing failed! Time %t ", $time) ;
5389
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5390
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5391
        end
5392
        else
5393
            test_ok ;
5394
    `endif
5395
    `endif
5396
 
5397
    // check statuses!
5398
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5399
    ok = 1 ;
5400
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5401
    if ( temp_val1[31] !== 1 )
5402
    begin
5403
        $display("Parity checker testing failed! Time %t ", $time) ;
5404
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5405
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5406
        ok = 0 ;
5407
    end
5408
 
5409
    if ( temp_val1[30] !== 1 )
5410
    begin
5411
        $display("Parity checker testing failed! Time %t ", $time) ;
5412
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5413
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5414
        ok = 0 ;
5415
    end
5416
 
5417
    if ( temp_val1[24] !== 0 )
5418
    begin
5419
        $display("Parity checker testing failed! Time %t ", $time) ;
5420
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5421
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5422
        ok = 0 ;
5423
    end
5424
 
5425
    if ( ok )
5426
        test_ok ;
5427
 
5428
    // clear statuses
5429
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5430
 
5431
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5432
 
5433
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5434
    ok = 1 ;
5435
 
5436
    `ifdef HOST
5437
    if ( temp_val1[4] !== 1 )
5438
    begin
5439
        $display("Parity checker testing failed! Time %t ", $time) ;
5440
        $display("System error interrupt status bit not set when expected!") ;
5441
        test_fail("System error interrupt status bit not set when expected") ;
5442
        ok = 0 ;
5443
    end
5444
    `else
5445
    if ( temp_val1[4] !== 0 )
5446
    begin
5447
        $display("Parity checker testing failed! Time %t ", $time) ;
5448
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5449
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5450
        ok = 0 ;
5451
    end
5452
    `endif
5453
 
5454
    if ( temp_val1[3] !== 0 )
5455
    begin
5456
        $display("Parity checker testing failed! Time %t ", $time) ;
5457
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5458
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5459
        ok = 0 ;
5460
    end
5461
 
5462
    if ( ok )
5463
        test_ok ;
5464
 
5465
    // clear statuses
5466
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5467
 
5468
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5469
    fork
5470
    begin
5471
        ipci_unsupported_commands_master.master_reference
5472
        (
5473
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5474
            32'h5555_5555,      // second part of address in dual address cycle
5475
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5476
            `BC_MEM_WRITE,      // normal command
5477
            4'h0,               // byte enables
5478
            32'h1234_5678,      // data
5479
            1'b0,               // make address parity error on first phase of dual address
5480
            1'b1,               // make address parity error on second phase of dual address
5481
            ok                  // result of operation
5482
        ) ;
5483 35 mihad
        if ( !perr_asserted )
5484
            disable wait_serr15 ;
5485 15 mihad
    end
5486
    begin:wait_serr15
5487
        perr_asserted = 0 ;
5488
        @(posedge pci_clock) ;
5489 35 mihad
        while( SERR !== 0 )
5490 15 mihad
            @(posedge pci_clock) ;
5491
 
5492 35 mihad
        perr_asserted = 1 ;
5493 15 mihad
    end
5494
    join
5495
 
5496
    if ( ok && perr_asserted)
5497
        test_ok ;
5498
    else
5499
    if ( !perr_asserted )
5500
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5501
 
5502
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5503
 
5504
    `ifdef HOST
5505
        repeat(4)
5506 26 mihad
            @(posedge pci_clock) ;
5507
        repeat(4)
5508 15 mihad
            @(posedge wb_clock) ;
5509
        if ( INT_O !== 1 )
5510
        begin
5511
            $display("Parity checker testing failed! Time %t ", $time) ;
5512
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5513
            test_fail("Interrupt Request was not triggered as expected") ;
5514
        end
5515
        else
5516
            test_ok ;
5517
    `else
5518
    `ifdef GUEST
5519 26 mihad
        repeat(4)
5520
            @(posedge wb_clock) ;
5521
        repeat(4)
5522 15 mihad
            @(posedge pci_clock) ;
5523
 
5524
        if ( INTA !== 1 )
5525
        begin
5526
            $display("Parity checker testing failed! Time %t ", $time) ;
5527
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5528
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5529
        end
5530
        else
5531
            test_ok ;
5532
    `endif
5533
    `endif
5534
 
5535
    // check statuses!
5536
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5537
    ok = 1 ;
5538
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5539
    if ( temp_val1[31] !== 1 )
5540
    begin
5541
        $display("Parity checker testing failed! Time %t ", $time) ;
5542
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5543
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5544
        ok = 0 ;
5545
    end
5546
 
5547
    if ( temp_val1[30] !== 1 )
5548
    begin
5549
        $display("Parity checker testing failed! Time %t ", $time) ;
5550
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5551
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5552
        ok = 0 ;
5553
    end
5554
 
5555
    if ( temp_val1[24] !== 0 )
5556
    begin
5557
        $display("Parity checker testing failed! Time %t ", $time) ;
5558
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5559
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5560
        ok = 0 ;
5561
    end
5562
 
5563
    if ( ok )
5564
        test_ok ;
5565
 
5566
    // clear statuses
5567
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5568
 
5569
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5570
 
5571
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5572
    ok = 1 ;
5573
 
5574
    `ifdef HOST
5575
    if ( temp_val1[4] !== 1 )
5576
    begin
5577
        $display("Parity checker testing failed! Time %t ", $time) ;
5578
        $display("System error interrupt status bit not set when expected!") ;
5579
        test_fail("System error interrupt status bit not set when expected") ;
5580
        ok = 0 ;
5581
    end
5582
    `else
5583
    if ( temp_val1[4] !== 0 )
5584
    begin
5585
        $display("Parity checker testing failed! Time %t ", $time) ;
5586
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5587
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5588
        ok = 0 ;
5589
    end
5590
    `endif
5591
 
5592
    if ( temp_val1[3] !== 0 )
5593
    begin
5594
        $display("Parity checker testing failed! Time %t ", $time) ;
5595
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5596
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5597
        ok = 0 ;
5598
    end
5599
 
5600
    if ( ok )
5601
        test_ok ;
5602
 
5603
    // clear statuses
5604
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5605
 
5606
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5607
    fork
5608
    begin
5609
        ipci_unsupported_commands_master.master_reference
5610
        (
5611
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5612
            32'h5555_5555,      // second part of address in dual address cycle
5613
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5614
            `BC_MEM_WRITE,      // normal command
5615
            4'h0,               // byte enables
5616
            32'h1234_5678,      // data
5617
            1'b1,               // make address parity error on first phase of dual address
5618
            1'b1,               // make address parity error on second phase of dual address
5619
            ok                  // result of operation
5620
        ) ;
5621 35 mihad
        if ( !perr_asserted )
5622
            disable wait_serr16 ;
5623 15 mihad
    end
5624
    begin:wait_serr16
5625
        perr_asserted = 0 ;
5626
        @(posedge pci_clock) ;
5627 35 mihad
        while( SERR !== 0 )
5628 15 mihad
            @(posedge pci_clock) ;
5629
 
5630 35 mihad
        perr_asserted = 1 ;
5631 15 mihad
    end
5632
    join
5633
 
5634
    if ( ok && perr_asserted)
5635
        test_ok ;
5636
    else
5637
    if ( !perr_asserted )
5638
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5639
 
5640
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5641
 
5642
    `ifdef HOST
5643
        repeat(4)
5644 26 mihad
            @(posedge pci_clock) ;
5645
        repeat(4)
5646 15 mihad
            @(posedge wb_clock) ;
5647
        if ( INT_O !== 1 )
5648
        begin
5649
            $display("Parity checker testing failed! Time %t ", $time) ;
5650
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5651
            test_fail("Interrupt Request was not triggered as expected") ;
5652
        end
5653
        else
5654
            test_ok ;
5655
    `else
5656
    `ifdef GUEST
5657 26 mihad
        repeat(4)
5658
            @(posedge wb_clock) ;
5659
        repeat(4)
5660 15 mihad
            @(posedge pci_clock) ;
5661
 
5662
        if ( INTA !== 1 )
5663
        begin
5664
            $display("Parity checker testing failed! Time %t ", $time) ;
5665
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5666
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5667
        end
5668
        else
5669
            test_ok ;
5670
    `endif
5671
    `endif
5672
 
5673
    // check statuses!
5674
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5675
    ok = 1 ;
5676
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5677
    if ( temp_val1[31] !== 1 )
5678
    begin
5679
        $display("Parity checker testing failed! Time %t ", $time) ;
5680
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5681
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5682
        ok = 0 ;
5683
    end
5684
 
5685
    if ( temp_val1[30] !== 1 )
5686
    begin
5687
        $display("Parity checker testing failed! Time %t ", $time) ;
5688
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5689
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5690
        ok = 0 ;
5691
    end
5692
 
5693
    if ( temp_val1[24] !== 0 )
5694
    begin
5695
        $display("Parity checker testing failed! Time %t ", $time) ;
5696
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5697
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5698
        ok = 0 ;
5699
    end
5700
 
5701
    if ( ok )
5702
        test_ok ;
5703
 
5704
    // clear statuses
5705
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5706
 
5707
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5708
 
5709
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5710
    ok = 1 ;
5711
 
5712
    `ifdef HOST
5713
    if ( temp_val1[4] !== 1 )
5714
    begin
5715
        $display("Parity checker testing failed! Time %t ", $time) ;
5716
        $display("System error interrupt status bit not set when expected!") ;
5717
        test_fail("System error interrupt status bit not set when expected") ;
5718
        ok = 0 ;
5719
    end
5720
    `else
5721
    if ( temp_val1[4] !== 0 )
5722
    begin
5723
        $display("Parity checker testing failed! Time %t ", $time) ;
5724
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5725
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5726
        ok = 0 ;
5727
    end
5728
    `endif
5729
 
5730
    if ( temp_val1[3] !== 0 )
5731
    begin
5732
        $display("Parity checker testing failed! Time %t ", $time) ;
5733
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5734
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5735
        ok = 0 ;
5736
    end
5737
 
5738
    if ( ok )
5739
        test_ok ;
5740
 
5741
    // clear statuses
5742
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5743
 
5744
    // now just disable Parity Error response - on Address par errors nothing should happen
5745
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5746
 
5747
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5748
    fork
5749
    begin
5750
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5751
               target_address, 32'h1234_5678,
5752
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5753
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5754
        do_pause( 1 ) ;
5755
    end
5756
    begin:wait_serr12
5757
        perr_asserted = 0 ;
5758
        @(posedge pci_clock) ;
5759
        while( SERR === 1 )
5760
            @(posedge pci_clock) ;
5761
 
5762
        perr_asserted = 1 ;
5763
        $display("Parity checker testing failed! Time %t ", $time) ;
5764
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5765
        test_fail("SERR asserted when parity error response was disabled") ;
5766
    end
5767
    begin
5768
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5769
        if ( ok !== 1 )
5770
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5771
 
5772 35 mihad
        @(posedge pci_clock) ;
5773
        #1 ;
5774
        if ( !perr_asserted )
5775
            disable wait_serr12 ;
5776 15 mihad
    end
5777
    join
5778
 
5779
    if ( ok && !perr_asserted )
5780
        test_ok ;
5781
 
5782
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5783
    `ifdef HOST
5784 26 mihad
        repeat (4)
5785
            @(posedge pci_clock) ;
5786 15 mihad
        repeat(4)
5787
            @(posedge wb_clock) ;
5788
        if ( INT_O !== 0 )
5789
        begin
5790
            $display("Parity checker testing failed! Time %t ", $time) ;
5791
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5792
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5793
        end
5794
        else
5795
            test_ok ;
5796
    `else
5797
    `ifdef GUEST
5798 26 mihad
        repeat(4)
5799
            @(posedge wb_clock) ;
5800
        repeat (4)
5801 15 mihad
            @(posedge pci_clock) ;
5802
 
5803
        if ( INTA !== 1 )
5804
        begin
5805
            $display("Parity checker testing failed! Time %t ", $time) ;
5806
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5807
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5808
        end
5809
        else
5810
            test_ok ;
5811
    `endif
5812
    `endif
5813
 
5814
    // check statuses!
5815
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5816
    ok = 1 ;
5817
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5818
    if ( temp_val1[31] !== 1 )
5819
    begin
5820
        $display("Parity checker testing failed! Time %t ", $time) ;
5821
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5822
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5823
        ok = 0 ;
5824
    end
5825
 
5826
    if ( temp_val1[30] !== 0 )
5827
    begin
5828
        $display("Parity checker testing failed! Time %t ", $time) ;
5829
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5830
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5831
        ok = 0 ;
5832
    end
5833
 
5834
    if ( temp_val1[24] !== 0 )
5835
    begin
5836
        $display("Parity checker testing failed! Time %t ", $time) ;
5837
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5838
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5839
        ok = 0 ;
5840
    end
5841
 
5842
    if ( ok )
5843
        test_ok ;
5844
 
5845
    // clear statuses
5846
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5847
 
5848
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5849
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5850
    ok = 1 ;
5851
    if ( temp_val1[4] !== 0 )
5852
    begin
5853
        $display("Parity checker testing failed! Time %t ", $time) ;
5854
        $display("System error interrupt status bit set when not expected!") ;
5855
        test_fail("System error interrupt status bit set when not expected") ;
5856
        ok = 0 ;
5857
    end
5858
 
5859
    if ( temp_val1[3] !== 0 )
5860
    begin
5861
        $display("Parity checker testing failed! Time %t ", $time) ;
5862
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5863
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5864
        ok = 0 ;
5865
    end
5866
 
5867
    if ( ok )
5868
        test_ok ;
5869
 
5870
    // clear statuses
5871
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5872
 
5873
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5874
    fork
5875
    begin
5876
        ipci_unsupported_commands_master.master_reference
5877
        (
5878
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5879
            32'h5555_5555,      // second part of address in dual address cycle
5880
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5881
            `BC_MEM_WRITE,      // normal command
5882
            4'h0,               // byte enables
5883
            32'h1234_5678,      // data
5884
            1'b1,               // make address parity error on first phase of dual address
5885
            1'b0,               // make address parity error on second phase of dual address
5886
            ok                  // result of operation
5887
        ) ;
5888 35 mihad
        if ( !perr_asserted )
5889
            disable wait_serr17 ;
5890 15 mihad
    end
5891
    begin:wait_serr17
5892
        perr_asserted = 0 ;
5893
        @(posedge pci_clock) ;
5894
        while( SERR === 1 )
5895
            @(posedge pci_clock) ;
5896
 
5897
        perr_asserted = 1 ;
5898
        $display("Parity checker testing failed! Time %t ", $time) ;
5899
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5900
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5901
    end
5902
    join
5903
 
5904
    if ( ok && !perr_asserted)
5905
        test_ok ;
5906
 
5907
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5908
    fork
5909
    begin
5910
        ipci_unsupported_commands_master.master_reference
5911
        (
5912
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5913
            32'h5555_5555,      // second part of address in dual address cycle
5914
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5915
            `BC_MEM_WRITE,      // normal command
5916
            4'h0,               // byte enables
5917
            32'h1234_5678,      // data
5918
            1'b0,               // make address parity error on first phase of dual address
5919
            1'b1,               // make address parity error on second phase of dual address
5920
            ok                  // result of operation
5921
        ) ;
5922 35 mihad
        if ( !perr_asserted )
5923
            disable wait_serr18 ;
5924 15 mihad
    end
5925
    begin:wait_serr18
5926
        perr_asserted = 0 ;
5927
        @(posedge pci_clock) ;
5928
        while( SERR === 1 )
5929
            @(posedge pci_clock) ;
5930
 
5931
        perr_asserted = 1 ;
5932
        $display("Parity checker testing failed! Time %t ", $time) ;
5933
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5934
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5935
    end
5936
    join
5937
 
5938
    if ( ok && !perr_asserted)
5939
        test_ok ;
5940
 
5941
    // check statuses!
5942
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5943
    ok = 1 ;
5944
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5945
    if ( temp_val1[31] !== 1 )
5946
    begin
5947
        $display("Parity checker testing failed! Time %t ", $time) ;
5948
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5949
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5950
        ok = 0 ;
5951
    end
5952
 
5953
    if ( temp_val1[30] !== 0 )
5954
    begin
5955
        $display("Parity checker testing failed! Time %t ", $time) ;
5956
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5957
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5958
        ok = 0 ;
5959
    end
5960
 
5961
    if ( temp_val1[24] !== 0 )
5962
    begin
5963
        $display("Parity checker testing failed! Time %t ", $time) ;
5964
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5965
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5966
        ok = 0 ;
5967
    end
5968
 
5969
    if ( ok )
5970
        test_ok ;
5971
 
5972
    // clear statuses
5973
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5974
 
5975
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5976
    fork
5977
    begin
5978
        ipci_unsupported_commands_master.master_reference
5979
        (
5980
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5981
            32'h5555_5555,      // second part of address in dual address cycle
5982
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5983
            `BC_MEM_WRITE,      // normal command
5984
            4'h0,               // byte enables
5985
            32'h1234_5678,      // data
5986
            1'b1,               // make address parity error on first phase of dual address
5987
            1'b1,               // make address parity error on second phase of dual address
5988
            ok                  // result of operation
5989
        ) ;
5990 35 mihad
        if ( !perr_asserted )
5991
            disable wait_serr19 ;
5992 15 mihad
    end
5993
    begin:wait_serr19
5994
        perr_asserted = 0 ;
5995
        @(posedge pci_clock) ;
5996
        while( SERR === 1 )
5997
            @(posedge pci_clock) ;
5998
 
5999
        perr_asserted = 1 ;
6000
        $display("Parity checker testing failed! Time %t ", $time) ;
6001
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
6002
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6003
    end
6004
    join
6005
 
6006
    if ( ok && !perr_asserted)
6007
        test_ok ;
6008
 
6009
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6010
 
6011
    `ifdef HOST
6012
        repeat(4)
6013 26 mihad
            @(posedge pci_clock) ;
6014
        repeat(4)
6015 15 mihad
            @(posedge wb_clock) ;
6016
        if ( INT_O !== 0 )
6017
        begin
6018
            $display("Parity checker testing failed! Time %t ", $time) ;
6019
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6020
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6021
        end
6022
        else
6023
            test_ok ;
6024
    `else
6025
    `ifdef GUEST
6026 26 mihad
        repeat(4)
6027
            @(posedge wb_clock) ;
6028
        repeat(4)
6029 15 mihad
            @(posedge pci_clock) ;
6030
 
6031
        if ( INTA !== 1 )
6032
        begin
6033
            $display("Parity checker testing failed! Time %t ", $time) ;
6034
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6035
            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") ;
6036
        end
6037
        else
6038
            test_ok ;
6039
    `endif
6040
    `endif
6041
 
6042
    // check statuses!
6043
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6044
    ok = 1 ;
6045
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6046
    if ( temp_val1[31] !== 1 )
6047
    begin
6048
        $display("Parity checker testing failed! Time %t ", $time) ;
6049
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6050
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6051
        ok = 0 ;
6052
    end
6053
 
6054
    if ( temp_val1[30] !== 0 )
6055
    begin
6056
        $display("Parity checker testing failed! Time %t ", $time) ;
6057
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6058
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6059
        ok = 0 ;
6060
    end
6061
 
6062
    if ( temp_val1[24] !== 0 )
6063
    begin
6064
        $display("Parity checker testing failed! Time %t ", $time) ;
6065
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6066
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6067
        ok = 0 ;
6068
    end
6069
 
6070
    if ( ok )
6071
        test_ok ;
6072
 
6073
    // clear statuses
6074
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6075
 
6076
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6077
 
6078
    // do normal write
6079
    fork
6080
    begin
6081
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6082
               target_address, 32'h1234_5678, `Test_All_Bytes,
6083
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6084
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6085
        do_pause( 1 ) ;
6086
    end
6087
    begin:wait_serr13
6088
        perr_asserted = 0 ;
6089
        @(posedge pci_clock) ;
6090
        while( SERR === 1 )
6091
            @(posedge pci_clock) ;
6092
 
6093
        perr_asserted = 1 ;
6094
        $display("Parity checker testing failed! Time %t ", $time) ;
6095
        $display("SERR asserted for no reason!") ;
6096
        test_fail("SERR was asserted for no reason") ;
6097
    end
6098
    begin
6099
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6100
        if ( ok !== 1 )
6101
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6102
 
6103 35 mihad
        @(posedge pci_clock) ;
6104
        #1 ;
6105
        if ( !perr_asserted )
6106
            disable wait_serr13 ;
6107 15 mihad
    end
6108
    join
6109
 
6110
    if ( ok && !perr_asserted )
6111
        test_ok ;
6112
 
6113
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6114
    `ifdef HOST
6115 26 mihad
        repeat( 4 )
6116
            @(posedge pci_clock) ;
6117 15 mihad
        repeat(4)
6118
            @(posedge wb_clock) ;
6119
        if ( INT_O !== 0 )
6120
        begin
6121
            $display("Parity checker testing failed! Time %t ", $time) ;
6122
            $display("Interrupt request asserted for no reason!") ;
6123
            test_fail("Interrupt request was asserted for no reason") ;
6124
        end
6125
        else
6126
            test_ok ;
6127
    `else
6128
    `ifdef GUEST
6129 26 mihad
        repeat(4)
6130
            @(posedge wb_clock) ;
6131
        repeat(4)
6132 15 mihad
            @(posedge pci_clock) ;
6133
 
6134
        if ( INTA !== 1 )
6135
        begin
6136
            $display("Parity checker testing failed! Time %t ", $time) ;
6137
            $display("Interrupt request asserted for no reason!") ;
6138
            test_fail("Interrupt request was asserted for no reason") ;
6139
        end
6140
        else
6141
            test_ok ;
6142
    `endif
6143
    `endif
6144
 
6145
    // check statuses!
6146
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6147
    ok = 1 ;
6148
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6149
    if ( temp_val1[31] !== 0 )
6150
    begin
6151
        $display("Parity checker testing failed! Time %t ", $time) ;
6152
        $display("Detected Parity Error bit was set for no reason!") ;
6153
        test_fail("Detected Parity Error bit was set for no reason") ;
6154
        ok = 0 ;
6155
    end
6156
 
6157
    if ( temp_val1[30] !== 0 )
6158
    begin
6159
        $display("Parity checker testing failed! Time %t ", $time) ;
6160
        $display("Signalled System Error bit was set for no reason!") ;
6161
        test_fail("Signalled System Error bit was set for no reason") ;
6162
        ok = 0 ;
6163
    end
6164
 
6165
    if ( temp_val1[24] !== 0 )
6166
    begin
6167
        $display("Parity checker testing failed! Time %t ", $time) ;
6168
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6169
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6170
        ok = 0 ;
6171
    end
6172
 
6173
    if ( ok )
6174
        test_ok ;
6175
 
6176
    // clear statuses
6177
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6178
 
6179
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6180
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6181
    ok = 1 ;
6182
 
6183
    if ( temp_val1[4] !== 0 )
6184
    begin
6185
        $display("Parity checker testing failed! Time %t ", $time) ;
6186
        $display("System error interrupt status bit set when not expected!") ;
6187
        test_fail("System error interrupt status bit set when not expected") ;
6188
        ok = 0 ;
6189
    end
6190
 
6191
    if ( temp_val1[3] !== 0 )
6192
    begin
6193
        $display("Parity checker testing failed! Time %t ", $time) ;
6194
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6195
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6196
        ok = 0 ;
6197
    end
6198
 
6199
    if ( ok )
6200
        test_ok ;
6201
 
6202
    // clear statuses
6203
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6204
 
6205
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6206
 
6207
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6208
 
6209
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6210
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6211
 
6212
    // setup target's image!
6213
    target_address  = Target_Base_Addr_R[1] ;
6214
 
6215
    // base address
6216
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6217
 
6218
    // address mask
6219
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6220
 
6221
    // image control
6222
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6223
 
6224
    // enable everything possible for parity checking
6225
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6226
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6227
 
6228
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6229
 
6230
    fork
6231
    begin
6232
        if ( target_mem_image === 1 )
6233
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6234
                   target_address, 32'h1234_5678,
6235
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6236
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6237
        else
6238
            PCIU_IO_WRITE_MAKE_PERR (
6239
                                    `Test_Master_1,
6240
                                    target_address,
6241
                                    32'h1234_5678,
6242
                                    4'h0,
6243
                                    1,
6244
                                    `Test_Target_Normal_Completion
6245
                                    );
6246
 
6247
        do_pause( 1 ) ;
6248
    end
6249
    begin:wait_perr11
6250
        perr_asserted = 0 ;
6251
        @(posedge pci_clock) ;
6252 35 mihad
        while ( PERR !== 0 )
6253 15 mihad
            @(posedge pci_clock) ;
6254
 
6255 35 mihad
        perr_asserted = 1 ;
6256 15 mihad
 
6257
    end
6258
    begin
6259
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6260
 
6261
        if ( ok !== 1 )
6262
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6263
 
6264
        repeat(2)
6265
            @(posedge pci_clock) ;
6266
 
6267 35 mihad
        #1 ;
6268
        if ( !perr_asserted )
6269
            disable wait_perr11 ;
6270 15 mihad
    end
6271
    join
6272
 
6273
    if ( ok && perr_asserted )
6274
        test_ok ;
6275
    else
6276
    if ( !perr_asserted )
6277
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6278
 
6279
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6280
    `ifdef HOST
6281 26 mihad
        repeat (4)
6282
            @(posedge pci_clock) ;
6283 15 mihad
        repeat(4)
6284
            @(posedge wb_clock) ;
6285
        if ( INT_O !== 0 )
6286
        begin
6287
            $display("Parity checker testing failed! Time %t ", $time) ;
6288
            $display("Interrupt request asserted for no reason!") ;
6289
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6290
        end
6291
        else
6292
            test_ok ;
6293
    `else
6294
    `ifdef GUEST
6295 26 mihad
        repeat(4)
6296
            @(posedge wb_clock) ;
6297
        repeat (4)
6298 15 mihad
            @(posedge pci_clock) ;
6299
 
6300
        if ( INTA !== 1 )
6301
        begin
6302
            $display("Parity checker testing failed! Time %t ", $time) ;
6303
            $display("Interrupt request asserted for no reason!") ;
6304
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6305
        end
6306
        else
6307
            test_ok ;
6308
 
6309
    `endif
6310
    `endif
6311
 
6312
    // check statuses!
6313
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6314
    ok = 1 ;
6315
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6316
    if ( temp_val1[31] !== 1 )
6317
    begin
6318
        $display("Parity checker testing failed! Time %t ", $time) ;
6319 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6320
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6321 15 mihad
        ok = 0 ;
6322
    end
6323
 
6324
    if ( temp_val1[30] !== 0 )
6325
    begin
6326
        $display("Parity checker testing failed! Time %t ", $time) ;
6327
        $display("Signalled System Error bit was set for no reason!") ;
6328
        test_fail("Signalled System Error bit was set for no reason") ;
6329
        ok = 0 ;
6330
    end
6331
 
6332
    if ( temp_val1[24] !== 0 )
6333
    begin
6334
        $display("Parity checker testing failed! Time %t ", $time) ;
6335
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6336
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6337
        ok = 0 ;
6338
    end
6339
 
6340
    if ( ok )
6341
        test_ok ;
6342
 
6343
    // clear statuses
6344
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6345
 
6346
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6347
 
6348
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6349
    ok = 1 ;
6350
    if ( temp_val1[4] !== 0 )
6351
    begin
6352
        $display("Parity checker testing failed! Time %t ", $time) ;
6353
        $display("System error interrupt status bit set when not expected!") ;
6354
        test_fail("System error interrupt status bit set when not expected") ;
6355
        ok = 0 ;
6356
    end
6357
 
6358
    if ( temp_val1[3] !== 0 )
6359
    begin
6360
        $display("Parity checker testing failed! Time %t ", $time) ;
6361
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6362
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6363
        ok = 0 ;
6364
    end
6365
 
6366
    if ( ok )
6367
        test_ok ;
6368
 
6369
    // clear statuses
6370
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6371
 
6372
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6373
 
6374
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6375
    fork
6376
    begin
6377
        if ( target_mem_image === 1 )
6378
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6379
                          target_address, 32'h1234_5678,
6380
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6381
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6382
        else
6383
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6384
 
6385
        do_pause( 1 ) ;
6386
    end
6387
    begin:wait_perr12
6388
        perr_asserted = 0 ;
6389
        @(posedge pci_clock) ;
6390 35 mihad
        while ( PERR !== 0 )
6391 15 mihad
            @(posedge pci_clock) ;
6392
 
6393 35 mihad
        perr_asserted = 1 ;
6394 15 mihad
    end
6395
    begin
6396
 
6397
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6398
        if ( ok !== 1 )
6399
        begin
6400
            test_fail("Bridge failed to process Target Memory read correctly") ;
6401
            disable main ;
6402
        end
6403
 
6404
        repeat(3)
6405
            @(posedge pci_clock) ;
6406
 
6407
        if ( target_mem_image === 1 )
6408
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6409
                    target_address, 32'h1234_5678,
6410
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6411
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6412
        else
6413
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6414
 
6415
        do_pause( 1 ) ;
6416
 
6417
    end
6418
    begin
6419
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6420
        if ( ok !== 1 )
6421
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6422
        else
6423
        begin
6424
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6425
            if ( ok !== 1 )
6426
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6427
        end
6428
 
6429 35 mihad
        repeat(2)
6430 15 mihad
            @(posedge pci_clock) ;
6431
 
6432 35 mihad
        #1 ;
6433
        if ( !perr_asserted )
6434
            disable wait_perr12 ;
6435 15 mihad
    end
6436
    join
6437
 
6438
    if ( ok && perr_asserted )
6439
        test_ok ;
6440
    else
6441
    if ( !perr_asserted )
6442
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6443
 
6444
 
6445
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6446
    `ifdef HOST
6447
        repeat(4)
6448 26 mihad
            @(posedge pci_clock) ;
6449
        repeat(4)
6450 15 mihad
            @(posedge wb_clock) ;
6451
        if ( INT_O !== 0 )
6452
        begin
6453
            $display("Parity checker testing failed! Time %t ", $time) ;
6454
            $display("Interrupt request asserted for no reason!") ;
6455
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6456
        end
6457
        else
6458
            test_ok ;
6459
    `else
6460
    `ifdef GUEST
6461 26 mihad
        repeat(4)
6462
            @(posedge wb_clock) ;
6463
        repeat(4)
6464 15 mihad
            @(posedge pci_clock) ;
6465
 
6466
        if ( INTA !== 1 )
6467
        begin
6468
            $display("Parity checker testing failed! Time %t ", $time) ;
6469
            $display("Interrupt request asserted for no reason!") ;
6470
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6471
        end
6472
        else
6473
            test_ok ;
6474
    `endif
6475
    `endif
6476
 
6477
    // check statuses!
6478
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6479
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6480
    ok = 1 ;
6481 45 mihad
    if ( temp_val1[31] !== 0 )
6482 15 mihad
    begin
6483
        $display("Parity checker testing failed! Time %t ", $time) ;
6484 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6485
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6486 15 mihad
        ok = 0 ;
6487
    end
6488
 
6489
    if ( temp_val1[30] !== 0 )
6490
    begin
6491
        $display("Parity checker testing failed! Time %t ", $time) ;
6492
        $display("Signalled System Error bit was set for no reason!") ;
6493
        test_fail("Signalled System Error bit was set for no reason") ;
6494
        ok = 0 ;
6495
    end
6496
 
6497
    if ( temp_val1[24] !== 0 )
6498
    begin
6499
        $display("Parity checker testing failed! Time %t ", $time) ;
6500
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6501
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6502
        ok = 0 ;
6503
    end
6504
 
6505
    if ( ok )
6506
        test_ok ;
6507
 
6508
    // clear statuses
6509
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6510
 
6511
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6512
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6513
    ok = 1 ;
6514
    if ( temp_val1[4] !== 0 )
6515
    begin
6516
        $display("Parity checker testing failed! Time %t ", $time) ;
6517
        $display("System error interrupt status bit set when not expected!") ;
6518
        test_fail("System error interrupt status bit set when not expected") ;
6519
        ok = 0 ;
6520
    end
6521
 
6522
    if ( temp_val1[3] !== 0 )
6523
    begin
6524
        $display("Parity checker testing failed! Time %t ", $time) ;
6525
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6526
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6527
        ok = 0 ;
6528
    end
6529
 
6530
    if ( ok )
6531
        test_ok ;
6532
    // clear statuses
6533
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6534
 
6535
    $fdisplay(pci_mon_log_file_desc,
6536
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6537
    test_name = "DISABLE USED IMAGES" ;
6538
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6539
    if ( ok !== 1 )
6540
    begin
6541
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6542
        test_fail("WB Image Address Mask register could not be written to") ;
6543
        disable main ;
6544
    end
6545
 
6546 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6547 15 mihad
    if ( ok !== 1 )
6548
    begin
6549
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6550
        test_fail("PCI Image Address Mask register could not be written to") ;
6551
        disable main ;
6552
    end
6553
 
6554
    // disable target's 1 response to parity errors
6555 45 mihad
    configuration_cycle_write(0,                        // bus number
6556
                              `TAR1_IDSEL_INDEX - 11,   // device number
6557
                              0,                        // function number
6558
                              1,                        // register number
6559
                              0,                        // type of configuration cycle
6560
                              4'b0001,                  // byte enables
6561
                              32'h0000_0007             // data
6562 15 mihad
                             ) ;
6563
 
6564
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6565
end
6566
endtask // parity_checking
6567
 
6568
task wb_to_pci_transactions ;
6569
    reg   [11:0] ctrl_offset ;
6570
    reg   [11:0] ba_offset ;
6571
    reg   [11:0] am_offset ;
6572
    reg   [11:0] pci_ctrl_offset ;
6573
    reg   [11:0] err_cs_offset ;
6574
    reg   [11:0] icr_offset ;
6575
    reg   [11:0] isr_offset ;
6576
    reg   [11:0] lat_tim_cls_offset ;
6577
 
6578
    reg `WRITE_STIM_TYPE  write_data ;
6579
    reg `READ_STIM_TYPE   read_data ;
6580
    reg `READ_RETURN_TYPE read_status ;
6581
 
6582
    reg `WRITE_RETURN_TYPE write_status ;
6583
    reg `WB_TRANSFER_FLAGS write_flags ;
6584
    reg [31:0] temp_val1 ;
6585
    reg [31:0] temp_val2 ;
6586
    reg        ok   ;
6587
 
6588
    reg [31:0] image_base ;
6589
    reg [31:0] target_address ;
6590
    integer i ;
6591
    integer required_reads ;
6592
    integer writes_left ;
6593
 
6594
begin:main
6595
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6596
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6597
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6598
    pci_ctrl_offset    = 12'h4 ;
6599
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6600
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6601
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6602
    lat_tim_cls_offset = 12'hC ;
6603
 
6604
    $display("Checking WB to PCI transaction lengths!") ;
6605
    target_address  = `BEH_TAR1_MEM_START ;
6606
    image_base      = 0 ;
6607
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6608
 
6609
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6610
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6611
    write_flags                    = 0 ;
6612
    write_flags`INIT_WAITS         = tb_init_waits ;
6613
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6614
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6615
 
6616
    // enable master & target operation
6617
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6618
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6619
    if ( ok !== 1 )
6620
    begin
6621
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6622
        test_fail("write to PCI Device Control register failed") ;
6623
        disable main ;
6624
    end
6625
 
6626
    // prepare image control register
6627
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6628
    if ( ok !== 1 )
6629
    begin
6630
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6631
        test_fail("write to WB Image Control register failed") ;
6632
        disable main ;
6633
    end
6634
 
6635
    // prepare base address register
6636
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6637
    if ( ok !== 1 )
6638
    begin
6639
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6640
        test_fail("write to WB Base Address register failed") ;
6641
        disable main ;
6642
    end
6643
 
6644
    // write address mask register
6645
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6646
    if ( ok !== 1 )
6647
    begin
6648
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6649
        test_fail("write to WB Address Mask register failed") ;
6650
        disable main ;
6651
    end
6652
 
6653
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6654
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6655
    if ( ok !== 1 )
6656
    begin
6657
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6658
        test_fail("write to WB Error Control and Status register failed") ;
6659
        disable main ;
6660
    end
6661
 
6662
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6663
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6664
    if ( ok !== 1 )
6665
    begin
6666
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6667
        test_fail("write to Interrupt Control register failed") ;
6668
        disable main ;
6669
    end
6670
 
6671
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6672
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6673
    if ( ok !== 1 )
6674
    begin
6675
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6676
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6677
        disable main ;
6678
    end
6679
 
6680
    $display("Testing single write transaction progress from WB to PCI!") ;
6681
    write_data`WRITE_ADDRESS = target_address ;
6682
    write_data`WRITE_DATA    = wmem_data[0] ;
6683
    write_data`WRITE_SEL     = 4'hF ;
6684
 
6685
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6686
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6687
 
6688
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6689
    fork
6690
    begin
6691
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6692
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6693
        begin
6694
            $display("Transaction progress testing failed! Time %t ", $time) ;
6695
            $display("Bridge failed to process single memory write!") ;
6696
            test_fail("bridge failed to post single memory write") ;
6697
            disable main ;
6698
        end
6699
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6700
    end
6701
    begin
6702
        // wait two retries, then enable target response
6703
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6704
        if ( ok !== 1 )
6705
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6706
        else
6707
            test_ok ;
6708
 
6709
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6710
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6711
        if ( ok !== 1 )
6712
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6713
        else
6714
            test_ok ;
6715
 
6716
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6717
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6718
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6719
 
6720
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6721
        if ( ok !== 1 )
6722
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6723
        else
6724
            test_ok ;
6725
    end
6726
    join
6727
 
6728
    $display("Testing burst write transaction progress from WB to PCI!") ;
6729
    write_data`WRITE_ADDRESS = target_address ;
6730
    write_data`WRITE_DATA    = wmem_data[0] ;
6731
    write_data`WRITE_SEL     = 4'hF ;
6732
 
6733
    wishbone_master.blk_write_data[0] = write_data ;
6734
 
6735
    write_data`WRITE_ADDRESS = target_address + 4 ;
6736
    write_data`WRITE_DATA    = wmem_data[1] ;
6737
    write_data`WRITE_SEL     = 4'hF ;
6738
 
6739
    wishbone_master.blk_write_data[1] = write_data ;
6740
 
6741
    write_flags`WB_TRANSFER_SIZE = 2 ;
6742
    write_flags`WB_TRANSFER_CAB  = 1 ;
6743
 
6744
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6745
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6746
 
6747
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6748
 
6749
    fork
6750
    begin
6751
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6752
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6753
        begin
6754
            $display("Transaction progress testing failed! Time %t ", $time) ;
6755
            $display("Bridge failed to process whole CAB memory write!") ;
6756
            test_fail("bridge failed to post whole CAB memory write") ;
6757
            disable main ;
6758
        end
6759
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6760
    end
6761
    begin
6762
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6763
        if ( ok !== 1 )
6764
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6765
        else
6766
            test_ok ;
6767
 
6768
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6769
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6770
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6771
 
6772
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6773
        if ( ok !== 1 )
6774
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6775
        else
6776
            test_ok ;
6777
 
6778
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6779
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6780
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6781
 
6782
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6783
        if ( ok !== 1 )
6784
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6785
        else
6786
            test_ok ;
6787
    end
6788
    join
6789
 
6790
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6791
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6792
 
6793
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6794
    // try same write with other terminations
6795
    fork
6796
    begin
6797
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6798
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6799
        begin
6800
            $display("Transaction progress testing failed! Time %t ", $time) ;
6801
            $display("Bridge failed to process whole CAB memory write!") ;
6802
            test_fail("bridge failed to post whole CAB memory write") ;
6803
            disable main ;
6804
        end
6805
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6806
    end
6807
    begin
6808
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6809
        if ( ok !== 1 )
6810
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6811
        else
6812
            test_ok ;
6813
 
6814
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6815
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6816
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6817
 
6818
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6819
        if ( ok !== 1 )
6820
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6821
        else
6822
            test_ok ;
6823
    end
6824
    join
6825
 
6826
    // repeat the write with normal completion
6827
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6828
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6829
 
6830
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6831
    fork
6832
    begin
6833
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6834
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6835
        begin
6836
            $display("Transaction progress testing failed! Time %t ", $time) ;
6837
            $display("Bridge failed to process whole CAB memory write!") ;
6838
            test_fail("bridge failed to post whole CAB memory write") ;
6839
            disable main ;
6840
        end
6841
    end
6842
    begin
6843
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6844
        if ( ok !== 1 )
6845
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6846
        else
6847
            test_ok ;
6848
    end
6849
    join
6850
 
6851
    // do the same thing with burst length of 3
6852
    write_data`WRITE_ADDRESS = target_address + 8 ;
6853
    write_data`WRITE_DATA    = wmem_data[2] ;
6854
    write_data`WRITE_SEL     = 4'hF ;
6855
 
6856
    wishbone_master.blk_write_data[2] = write_data ;
6857
 
6858
    write_flags`WB_TRANSFER_SIZE = 3 ;
6859
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6860
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6861
 
6862
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6863
 
6864
    fork
6865
    begin
6866
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6867
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6868
        begin
6869
            $display("Transaction progress testing failed! Time %t ", $time) ;
6870
            $display("Bridge failed to process whole CAB memory write!") ;
6871
            test_fail("bridge failed to post whole CAB memory write") ;
6872
            disable main ;
6873
        end
6874
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6875
    end
6876
    begin
6877
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6878
        if ( ok !== 1 )
6879
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6880
        else
6881
            test_ok ;
6882
 
6883
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6884
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6885
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6886
 
6887
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6888
        if ( ok !== 1 )
6889
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6890
        else
6891
            test_ok ;
6892
    end
6893
    join
6894
 
6895
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6896
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6897
 
6898
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6899
    fork
6900
    begin
6901
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6902
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6903
        begin
6904
            $display("Transaction progress testing failed! Time %t ", $time) ;
6905
            $display("Bridge failed to process whole CAB memory write!") ;
6906
            test_fail("bridge failed to post whole CAB memory write") ;
6907
            disable main ;
6908
        end
6909
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6910
    end
6911
    begin
6912
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6913
        if ( ok !== 1 )
6914
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6915
        else
6916
            test_ok ;
6917
 
6918
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6919
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6920
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6921
 
6922
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6923
        if ( ok !== 1 )
6924
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6925
        else
6926
            test_ok ;
6927
 
6928
    end
6929
    join
6930
 
6931
    // repeat with normal completion
6932
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6933
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6934
 
6935
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6936
    fork
6937
    begin
6938
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6939
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6940
        begin
6941
            $display("Transaction progress testing failed! Time %t ", $time) ;
6942
            $display("Bridge failed to process whole CAB memory write!") ;
6943
            test_fail("bridge failed to post whole CAB memory write") ;
6944
            disable main ;
6945
        end
6946
    end
6947
    begin
6948
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6949
        if ( ok !== 1 )
6950
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6951
        else
6952
            test_ok ;
6953
 
6954
    end
6955
    join
6956
 
6957
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6958
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6959
    begin
6960
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6961
        write_data`WRITE_DATA    = wmem_data[i] ;
6962
        write_data`WRITE_SEL     = 4'hF ;
6963
 
6964
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6965
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6966
 
6967
        wishbone_master.blk_write_data[i]   = write_data ;
6968
        wishbone_master.blk_read_data_in[i] = read_data ;
6969
    end
6970
 
6971
    write_flags`WB_TRANSFER_CAB      = 1 ;
6972
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6973
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6974
 
6975
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6976
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6977
 
6978
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6979
    fork
6980
    begin
6981
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6982
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6983
        begin
6984
            $display("Transaction progress testing failed! Time %t ", $time) ;
6985
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6986
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6987
            test_fail("bridge failed to post whole CAB memory write") ;
6988
            disable main ;
6989
        end
6990
 
6991
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6992
 
6993
        // read here just checks if data was transfered OK
6994
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6995
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6996
 
6997
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6998
 
6999
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
7000
        begin
7001
            $display("Transaction progress testing failed! Time %t ", $time) ;
7002
            $display("Bridge processed CAB read wrong!") ;
7003
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7004
        end
7005
 
7006
    end
7007
    begin
7008
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7009
        if ( ok !== 1 )
7010
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7011
        else
7012
            test_ok ;
7013
 
7014
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7015
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7016
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7017
 
7018
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7019
        if ( ok !== 1 )
7020
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7021
        else
7022
            test_ok ;
7023
 
7024
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7025
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7026
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7027
 
7028
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7029
        if ( ok !== 1 )
7030
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7031
        else
7032
            test_ok ;
7033
 
7034
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7035
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7036
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7037
 
7038
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7039
        if ( ok !== 1 )
7040
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7041
        else
7042
            test_ok ;
7043
 
7044
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7045
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7046
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7047
 
7048
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7049
        if ( ok !== 1 )
7050
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7051
        else
7052
            test_ok ;
7053
 
7054
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7055
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7056
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7057
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7058
        begin
7059
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7060
            if ( ok !== 1 )
7061
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7062
        end
7063
    end
7064
    join
7065
 
7066
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7067
    begin
7068
        read_status = wishbone_master.blk_read_data_out[i] ;
7069
        if (read_status`READ_DATA !== wmem_data[i])
7070
        begin
7071
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7072
            test_fail("data read from target wasn't the same as data written to it") ;
7073
            ok = 0 ;
7074
        end
7075
    end
7076
 
7077
    if ( ok )
7078
        test_ok ;
7079
 
7080
    $display("Testing single read transaction progress from WB to PCI!") ;
7081
    read_data`READ_ADDRESS = target_address + 8 ;
7082
    read_data`READ_SEL     = 4'hF ;
7083
 
7084
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7085
 
7086
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7087
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7088
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7089
 
7090
    fork
7091
    begin
7092
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7093
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7094
        begin
7095
            $display("Transaction progress testing failed! Time %t ", $time) ;
7096
            $display("Bridge processed single read wrong!") ;
7097
            test_fail("bridge processed single read wrong") ;
7098
            disable main ;
7099
        end
7100
 
7101
        if (read_status`READ_DATA !== wmem_data[2])
7102
        begin
7103
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7104
            test_fail("data returned from single read was not as expected") ;
7105
        end
7106
        else
7107
        if ( ok )
7108
            test_ok ;
7109
    end
7110
    begin
7111
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7112
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7113
 
7114
        if ( ok !== 1 )
7115
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7116
 
7117
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7118
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7119
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7120
 
7121
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7122
        if ( ok !== 1 )
7123
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7124
    end
7125
    join
7126
 
7127
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7128
 
7129
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7130
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7131
 
7132
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7133
    // first fill target's memory with enough data to fill WBR_FIFO
7134
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7135
    begin
7136
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7137
        write_data`WRITE_DATA    = wmem_data[i] ;
7138
        write_data`WRITE_SEL     = 4'hF ;
7139
 
7140
        wishbone_master.blk_write_data[i] = write_data ;
7141
    end
7142
 
7143
    write_flags`WB_TRANSFER_CAB = 1 ;
7144
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7145
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7146
 
7147
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7148
 
7149
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7150
    begin
7151
        $display("Transaction progress testing failed! Time %t ", $time) ;
7152
        $display("Bridge processed CAB write wrong!") ;
7153
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7154
        disable main ;
7155
    end
7156
 
7157
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7158
    // perform single read to force write data to pci
7159
    read_data`READ_ADDRESS = target_address + 8;
7160
    read_data`READ_SEL     = 4'hF ;
7161
 
7162
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7163
 
7164
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7165
    begin
7166
        $display("Transaction progress testing failed! Time %t ", $time) ;
7167
        $display("Bridge processed single read wrong!") ;
7168
        test_fail("bridge didn't process single memory read as expected") ;
7169
        disable main ;
7170
    end
7171
 
7172
    wishbone_master.blk_read_data_in[0] = read_data ;
7173
 
7174
    read_data`READ_ADDRESS = target_address + 12 ;
7175
    read_data`READ_SEL     = 4'hF ;
7176
 
7177
    wishbone_master.blk_read_data_in[1] = read_data ;
7178
 
7179
    read_data`READ_ADDRESS = target_address + 16 ;
7180
    read_data`READ_SEL     = 4'hF ;
7181
 
7182
    wishbone_master.blk_read_data_in[2] = read_data ;
7183
 
7184
    write_flags`WB_TRANSFER_CAB  = 1 ;
7185
    write_flags`WB_TRANSFER_SIZE = 2 ;
7186
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7187
    read_status = 0 ;
7188
 
7189
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7190
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7191
 
7192
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7193
 
7194
    ok = 1 ;
7195
    fork
7196
    begin
7197
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7198
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7199
 
7200
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7201
        begin
7202
            $display("Transaction progress testing failed! Time %t ", $time) ;
7203
            $display("Bridge processed CAB read wrong!") ;
7204
            test_fail("bridge didn't process disconnected burst read as expected") ;
7205
        end
7206
        else
7207
        begin
7208
 
7209
            read_status = wishbone_master.blk_read_data_out[0] ;
7210
 
7211
            if (read_status`READ_DATA !== wmem_data[2])
7212
            begin
7213
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7214
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7215
            end
7216
            else
7217
                test_ok ;
7218
        end
7219
 
7220
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7221
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7222
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7223
 
7224
        read_status = 0 ;
7225
 
7226
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7227
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7228
 
7229
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
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 disconnected burst read as expected") ;
7234
        end
7235
        else
7236
        begin
7237
 
7238
            read_status = wishbone_master.blk_read_data_out[0] ;
7239
 
7240
            if (read_status`READ_DATA !== wmem_data[3])
7241
            begin
7242
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7243
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7244
            end
7245
            else
7246
                test_ok ;
7247
        end
7248
 
7249
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7250
        // complete delayed read which was requested
7251
        read_data = wishbone_master.blk_read_data_in[2] ;
7252
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7253
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7254
 
7255
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7256
        begin
7257
            $display("Transaction progress testing failed! Time %t ", $time) ;
7258
            $display("Bridge processed single out of burst read wrong!") ;
7259
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7260
        end
7261
        else
7262
        begin
7263
 
7264
            if (read_status`READ_DATA !== wmem_data[4])
7265
            begin
7266
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7267
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7268
            end
7269
            else
7270
                test_ok ;
7271
        end
7272
 
7273
    end
7274
    begin
7275
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7276
 
7277
        if ( ok !== 1 )
7278
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7279
 
7280
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7281
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7282
 
7283
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7284
        if ( ok !== 1 )
7285
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7286
 
7287
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7288
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7289
 
7290
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7291
        if ( ok !== 1 )
7292
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7293
    end
7294
    join
7295
 
7296
    // now try burst read with normal termination
7297
    read_data`READ_ADDRESS = target_address + 12 ;
7298
    read_data`READ_SEL     = 4'hF ;
7299
 
7300
    wishbone_master.blk_read_data_in[0] = read_data ;
7301
 
7302
    read_data`READ_ADDRESS = target_address + 16 ;
7303
    read_data`READ_SEL     = 4'hF ;
7304
 
7305
    wishbone_master.blk_read_data_in[1] = read_data ;
7306
 
7307
    write_flags`WB_TRANSFER_SIZE = 2 ;
7308
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7309
    write_flags`WB_TRANSFER_CAB = 1 ;
7310
 
7311
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7312
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7313
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7314
 
7315
    fork
7316
    begin
7317
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7318
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7319
        begin
7320
            $display("Transaction progress testing failed! Time %t ", $time) ;
7321
            $display("Bridge processed CAB read wrong!") ;
7322
            test_fail("bridge didn't process burst read as expected") ;
7323
            ok = 0 ;
7324
        end
7325
    end
7326
    begin
7327
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7328
        if ( ok !== 1 )
7329
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7330
    end
7331
    join
7332
 
7333
    if ( ok )
7334
    begin
7335
        read_status = wishbone_master.blk_read_data_out[0] ;
7336
        if ( read_status`READ_DATA !== wmem_data[3] )
7337
        begin
7338
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7339
            test_fail("data provided from normaly terminated read was wrong") ;
7340
            ok = 0 ;
7341
        end
7342
 
7343
        read_status = wishbone_master.blk_read_data_out[1] ;
7344
        if ( read_status`READ_DATA !== wmem_data[4] )
7345
        begin
7346
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7347
            test_fail("data provided from normaly terminated read was wrong") ;
7348
            ok = 0 ;
7349
        end
7350
    end
7351
 
7352
    if ( ok )
7353
        test_ok ;
7354
 
7355
    // disable memory read line command and enable prefetch
7356
    // prepare image control register
7357
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7358
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7359
    if ( ok !== 1 )
7360
    begin
7361
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7362
        test_fail("WB Image Control register couldn't be written to") ;
7363
        disable main ;
7364
    end
7365
 
7366
    write_flags`WB_TRANSFER_SIZE = 4 ;
7367
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7368
    write_flags`WB_TRANSFER_CAB = 1 ;
7369
 
7370
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7371
 
7372
    for ( i = 0 ; i < 4 ; i = i + 1 )
7373
    begin
7374
        read_data`READ_ADDRESS = target_address + i*4 ;
7375
        read_data`READ_SEL     = 4'b1010 ;
7376
 
7377
        wishbone_master.blk_read_data_in[i] = read_data ;
7378
    end
7379
 
7380
    fork
7381
    begin
7382
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7383
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7384
        begin
7385
            $display("Transaction progress testing failed! Time %t ", $time) ;
7386
            $display("Bridge processed CAB read wrong!") ;
7387
            test_fail("bridge didn't process prefetched burst read as expected") ;
7388
            ok = 0 ;
7389
        end
7390
    end
7391
    begin
7392
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7393
        if ( ok !== 1 )
7394
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7395
    end
7396
    join
7397
 
7398
    if ( ok )
7399
    begin
7400
        for ( i = 0 ; i < 4 ; i = i + 1 )
7401
        begin
7402
            read_status = wishbone_master.blk_read_data_out[i] ;
7403
            if ( read_status`READ_DATA !== wmem_data[i] )
7404
            begin
7405
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7406
                test_fail("burst read returned unexpected data") ;
7407
                ok = 0 ;
7408
            end
7409
        end
7410
    end
7411
 
7412
    if ( ok )
7413
        test_ok ;
7414
 
7415
    // do one single read with different byte enables
7416
    read_data`READ_ADDRESS = target_address + 4 ;
7417
    read_data`READ_SEL     = 4'b1010 ;
7418
 
7419
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7420
    fork
7421
    begin
7422
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7423
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7424
        begin
7425
            $display("Transaction progress testing failed! Time %t ", $time) ;
7426
            $display("Bridge processed single read wrong!") ;
7427
            test_fail("bridge didn't process single memory read as expected") ;
7428
            ok = 0 ;
7429
        end
7430
    end
7431
    begin
7432
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7433
        if ( ok !== 1 )
7434
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7435
    end
7436
    join
7437
 
7438
    // check read data
7439
    if ( ok )
7440
    begin
7441
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7442
        begin
7443
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7444
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7445
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7446
            ok = 0 ;
7447
            test_fail("unexpected data received from single read") ;
7448
        end
7449
    end
7450
 
7451
    if ( ok )
7452
         test_ok ;
7453
 
7454
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7455
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7456
 
7457
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7458
    if ( ok !== 1 )
7459
    begin
7460
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7461
        test_fail("WB Image Control register could not be written") ;
7462
        disable main ;
7463
    end
7464
 
7465
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7466
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7467
    begin
7468
        read_data`READ_ADDRESS = target_address + i*4 ;
7469
        read_data`READ_SEL     = 4'b1111 ;
7470
 
7471
        wishbone_master.blk_read_data_in[i] = read_data ;
7472
    end
7473
 
7474
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7475
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7476
    write_flags`WB_TRANSFER_CAB = 1 ;
7477
 
7478
    fork
7479
    begin
7480
        read_status         = 0 ;
7481
        read_status`CYC_RTY = 1 ;
7482
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7483
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7484
 
7485
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7486
        begin
7487
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7488
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7489
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7490
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7491
            ok = 0 ;
7492
        end
7493
    end
7494
    begin
7495
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7496
        if ( ok !== 1 )
7497
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7498
    end
7499
    join
7500
 
7501
    // now repeat single read to flush redundant read initiated
7502
    write_flags`WB_TRANSFER_SIZE = 1 ;
7503
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7504
    write_flags`WB_TRANSFER_CAB = 1 ;
7505
 
7506
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7507
    read_data`READ_SEL     = 4'hF ;
7508
 
7509
    wishbone_master.blk_read_data_in[0] = read_data ;
7510
 
7511
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7512
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7513
 
7514
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7515
    begin
7516
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7517
        $display(" PCI bridge failed to process single CAB read!") ;
7518
        test_fail("single CAB write was not processed as expected") ;
7519
    end
7520
 
7521
    // because last read could be very long on PCI - delete target abort status
7522
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7523
 
7524
    // write unsupported value to cache line size register
7525
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7526
 
7527
    read_data`READ_ADDRESS = target_address ;
7528
    read_data`READ_SEL     = 4'hF ;
7529
    wishbone_master.blk_read_data_in[0] = read_data ;
7530
 
7531
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7532
    // perform a read
7533
    fork
7534
    begin
7535
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7536
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7537
        begin
7538
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7539
            $display(" PCI bridge failed to process single CAB read!") ;
7540
            test_fail("burst read was not processed as expected") ;
7541
            ok = 0 ;
7542
        end
7543
    end
7544
    begin
7545
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7546
        if ( ok !== 1 )
7547
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7548
    end
7549
    join
7550
 
7551
    if ( ok )
7552
        test_ok ;
7553
 
7554
    // write 2 to cache line size register
7555
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7556
 
7557
    // perform a read
7558
    fork
7559
    begin
7560
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7561
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7562
        begin
7563
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7564
            $display(" PCI bridge failed to process single CAB read!") ;
7565
            test_fail("burst read was not processed as expected") ;
7566
            ok = 0 ;
7567
        end
7568
    end
7569
    begin
7570
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7571
        if ( ok !== 1 )
7572
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7573
    end
7574
    join
7575
 
7576
    if ( ok )
7577
        test_ok ;
7578
 
7579
    // write 0 to cache line size
7580
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7581
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7582
 
7583
    // perform a read
7584
    fork
7585
    begin
7586
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7587
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7588
        begin
7589
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7590
            $display(" PCI bridge failed to process single CAB read!") ;
7591
            test_fail("burst read was not processed as expected") ;
7592
            ok = 0 ;
7593
        end
7594
    end
7595
    begin
7596
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7597
        if ( ok !== 1 )
7598
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7599
    end
7600
    join
7601
 
7602
    if ( ok )
7603
        test_ok ;
7604
 
7605
    // write normal value to cls register
7606
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7607
 
7608
    $display("Testing Master's latency timer operation!") ;
7609
    $display("Testing Latency timer during Master Writes!") ;
7610
 
7611
    for ( i = 0 ; i < 6 ; i = i + 1 )
7612
    begin
7613
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7614
        write_data`WRITE_SEL     = 4'b1111 ;
7615
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7616
 
7617
        wishbone_master.blk_write_data[i] = write_data ;
7618
    end
7619
 
7620
    write_flags`WB_TRANSFER_SIZE = 6 ;
7621
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7622
    write_flags`WB_TRANSFER_CAB = 1 ;
7623
 
7624
    // start wb write, pci write and monitor in parallel
7625
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7626
    fork
7627
    begin
7628
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7629
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7630
        begin
7631
            $display("Transaction progress testing failed! Time %t ", $time) ;
7632
            $display("Bridge failed to process CAB write!") ;
7633
            test_fail("bridge didn't post whole burst memory write") ;
7634
            disable main ;
7635
        end
7636
    end
7637
    begin
7638
        // wait for bridge's master to start transaction
7639
        @(posedge pci_clock) ;
7640
        while ( FRAME === 1 )
7641
            @(posedge pci_clock) ;
7642
 
7643
        // start behavioral master request
7644
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7645
               target_address, wmem_data[1023], `Test_All_Bytes,
7646
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7647
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7648
 
7649
        do_pause ( 1 ) ;
7650
    end
7651
    begin
7652
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7653
        if ( ok !== 1 )
7654
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7655
        else
7656
            test_ok ;
7657
    end
7658
    join
7659
 
7660
    // perform a read to check data
7661
    for ( i = 0 ; i < 6 ; i = i + 1 )
7662
    begin
7663
        read_data`READ_ADDRESS = target_address + i*4 ;
7664
        read_data`READ_SEL     = 4'b1111 ;
7665
 
7666
        wishbone_master.blk_read_data_in[i] = read_data ;
7667
    end
7668
 
7669
    write_flags`WB_TRANSFER_SIZE = 6 ;
7670
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7671
    write_flags`WB_TRANSFER_CAB = 1 ;
7672
 
7673
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7674
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7675
 
7676
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7677
    begin
7678
        $display("Transaction progress testing failed! Time %t ", $time) ;
7679
        $display("Bridge failed to process CAB read!") ;
7680
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7681
        disable main ;
7682
    end
7683
 
7684
    ok = 1 ;
7685
    for ( i = 0 ; i < 6 ; i = i + 1 )
7686
    begin
7687
        read_status = wishbone_master.blk_read_data_out[i] ;
7688
 
7689
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7690
        begin
7691
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7692
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7693
            test_fail("unexpected data read back from PCI") ;
7694
            ok = 0 ;
7695
        end
7696
    end
7697
 
7698
    if ( ok )
7699
        test_ok ;
7700
 
7701
    $display("Testing Latency timer during Master Reads!") ;
7702
 
7703
    // at least 2 words are transfered during Master Reads terminated with timeout
7704
    write_flags`WB_TRANSFER_SIZE = 2 ;
7705
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7706
    fork
7707
    begin
7708
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7709
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7710
        begin
7711
            $display("Transaction progress testing failed! Time %t ", $time) ;
7712
            $display("Bridge failed to process CAB read!") ;
7713
            test_fail("bridge didn't process burst read as expected") ;
7714
            ok = 0 ;
7715
        end
7716
    end
7717
    begin
7718
        // wait for bridge's master to start transaction
7719
        @(posedge pci_clock) ;
7720
        while ( FRAME === 1 )
7721
            @(posedge pci_clock) ;
7722
 
7723
        // start behavioral master request
7724
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7725
               target_address, wmem_data[0], `Test_All_Bytes,
7726
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7727
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7728
 
7729
        do_pause ( 1 ) ;
7730
    end
7731
    begin
7732
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7733
        if ( ok !== 1 )
7734
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7735
    end
7736
    join
7737
 
7738
    // check data provided by target
7739
    if ( ok )
7740
    begin
7741
        for ( i = 0 ; i < 2 ; i = i + 1 )
7742
        begin
7743
            read_status = wishbone_master.blk_read_data_out[i] ;
7744
 
7745
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7746
            begin
7747
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7748
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7749
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7750
                ok = 0 ;
7751
            end
7752
        end
7753
    end
7754
    if ( ok )
7755
        test_ok ;
7756
 
7757
    test_name = "DISABLE_IMAGE" ;
7758
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7759
    if ( ok !== 1 )
7760
    begin
7761
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7762
        test_fail("write to WB Address Mask register failed") ;
7763
        disable main ;
7764
    end
7765
 
7766
end
7767
endtask //wb_to_pci_transactions
7768
 
7769
task iack_cycle ;
7770
    reg `READ_STIM_TYPE   read_data ;
7771
    reg `READ_RETURN_TYPE read_status ;
7772
    reg `WB_TRANSFER_FLAGS flags ;
7773
 
7774
    reg [31:0] temp_var ;
7775
    reg ok ;
7776 45 mihad
    reg ok_wb ;
7777
    reg ok_pci ;
7778
 
7779
    reg [31:0] irq_vector ;
7780 15 mihad
begin
7781
 
7782 45 mihad
    ok     = 1 ;
7783
    ok_wb  = 1 ;
7784
    ok_pci = 1 ;
7785
 
7786 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7787
 
7788
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7789
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7790
 
7791
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7792
    read_data`READ_SEL     = 4'hF ;
7793
 
7794
    flags = 0 ;
7795
 
7796
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7797
 
7798
    irq_vector  = 32'hAAAA_AAAA ;
7799
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7800
 
7801 45 mihad
    // disable both pci blue behavioral targets
7802
    configuration_cycle_write
7803
    (
7804
        0,                          // bus number [7:0]
7805
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7806
        0,                          // function number [2:0]
7807
        1,                          // register number [5:0]
7808
        0,                          // type [1:0]
7809
        4'h1,                       // byte enables [3:0]
7810
        32'h0000_0044               // data to write [31:0]
7811
    ) ;
7812
 
7813
    configuration_cycle_write
7814
    (
7815
        0,                          // bus number [7:0]
7816
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7817
        0,                          // function number [2:0]
7818
        1,                          // register number [5:0]
7819
        0,                          // type [1:0]
7820
        4'h1,                       // byte enables [3:0]
7821
        32'h0000_0044               // data to write [31:0]
7822
    ) ;
7823
 
7824 15 mihad
    fork
7825
    begin
7826
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7827
    end
7828
    begin
7829 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7830
        if ( ok_pci !== 1 )
7831 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7832
    end
7833
    join
7834
 
7835
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7836
    begin
7837 45 mihad
        ok_wb = 0 ;
7838 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7839
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7840
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7841
    end
7842 45 mihad
 
7843
    if ( ok_pci && ok_wb )
7844 15 mihad
        test_ok ;
7845 45 mihad
 
7846
    ok_wb = 1 ;
7847
    ok_pci = 1 ;
7848
    ok = 1 ;
7849 15 mihad
 
7850 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7851
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7852 15 mihad
 
7853
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7854 45 mihad
    // enable pci blue behavioral target 1
7855
    configuration_cycle_write
7856
    (
7857
        0,                          // bus number [7:0]
7858
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7859
        0,                          // function number [2:0]
7860
        1,                          // register number [5:0]
7861
        0,                          // type [1:0]
7862
        4'h1,                       // byte enables [3:0]
7863
        32'h0000_0047               // data to write [31:0]
7864
    ) ;
7865 15 mihad
    fork
7866
    begin
7867
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7868
    end
7869
    begin
7870 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7871
        if ( ok_pci !== 1 )
7872 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7873
    end
7874
    join
7875
 
7876
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7877
    begin
7878 45 mihad
        ok_wb = 0 ;
7879 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7880
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7881
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7882
    end
7883
 
7884
    if ( read_status`READ_DATA !== irq_vector )
7885
    begin
7886
        $display(" Time %t ", $time ) ;
7887
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7888
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7889 45 mihad
        ok_wb = 0 ;
7890 15 mihad
    end
7891
 
7892 45 mihad
    if ( ok_pci && ok_wb )
7893 15 mihad
        test_ok ;
7894
 
7895 45 mihad
    ok_pci = 1 ;
7896
    ok_wb  = 1 ;
7897
    ok     = 1 ;
7898
 
7899 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7900 45 mihad
    irq_vector  = 32'h5555_5555 ;
7901
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7902
 
7903 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7904
    fork
7905
    begin
7906
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7907
    end
7908
    begin
7909 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7910
        if ( ok_pci !== 1 )
7911 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7912
    end
7913
    join
7914
 
7915
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7916
    begin
7917
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7918
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7919
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7920 45 mihad
        ok_wb = 0 ;
7921 15 mihad
    end
7922
 
7923 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7924 15 mihad
    begin
7925
        $display(" Time %t ", $time ) ;
7926 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7927 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7928 45 mihad
        ok_wb = 0 ;
7929 15 mihad
    end
7930
 
7931 45 mihad
    if (ok_pci && ok_wb)
7932 15 mihad
        test_ok ;
7933
 
7934 45 mihad
    ok_pci = 1 ;
7935
    ok_wb  = 1 ;
7936
    ok     = 1 ;
7937 15 mihad
 
7938 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7939
 
7940
    // set target to terminate with target abort
7941
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7942
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7943
 
7944
    fork
7945
    begin
7946
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7947
    end
7948
    begin
7949
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7950
        if ( ok_pci !== 1 )
7951
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7952
    end
7953
    join
7954
 
7955
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7956
    begin
7957
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7958
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7959
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7960
        ok_wb = 0 ;
7961
    end
7962
 
7963
    // set target to terminate with target abort
7964
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7965
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7966
 
7967
    // enable pci blue behavioral target 2
7968
    configuration_cycle_write
7969
    (
7970
        0,                          // bus number [7:0]
7971
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7972
        0,                          // function number [2:0]
7973
        1,                          // register number [5:0]
7974
        0,                          // type [1:0]
7975
        4'h1,                       // byte enables [3:0]
7976
        32'h0000_0047               // data to write [31:0]
7977
    ) ;
7978
 
7979
    // read PCI Device status
7980
    config_read(12'h4, 4'hC, temp_var) ;
7981
    if (temp_var[29] !== 1)
7982
    begin
7983
        $display("Time %t", $time) ;
7984
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7985
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7986
        ok_wb = 0 ;
7987
    end
7988
 
7989
    if (temp_var[28] !== 1)
7990
    begin
7991
        $display("Time %t", $time) ;
7992
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7993
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7994
        ok_wb = 0 ;
7995
    end
7996
 
7997
    // clearing the status bits
7998
        config_write(12'h4, temp_var, 4'hC, ok);
7999
 
8000
    if ( ok && ok_pci && ok_wb )
8001
        test_ok ;
8002
 
8003 15 mihad
end
8004
endtask //iack_cycle
8005
 
8006
task transaction_ordering ;
8007
    reg   [11:0] wb_ctrl_offset ;
8008
    reg   [11:0] wb_ba_offset ;
8009
    reg   [11:0] wb_am_offset ;
8010
    reg   [11:0] pci_ctrl_offset ;
8011
    reg   [11:0] pci_ba_offset ;
8012
    reg   [11:0] pci_am_offset ;
8013
    reg   [11:0] pci_device_ctrl_offset ;
8014
    reg   [11:0] wb_err_cs_offset ;
8015
    reg   [11:0] pci_err_cs_offset ;
8016
    reg   [11:0] icr_offset ;
8017
    reg   [11:0] isr_offset ;
8018
    reg   [11:0] lat_tim_cls_offset ;
8019
 
8020
    reg `WRITE_STIM_TYPE  write_data ;
8021
    reg `READ_STIM_TYPE   read_data ;
8022
    reg `READ_RETURN_TYPE read_status ;
8023
 
8024
    reg `WRITE_RETURN_TYPE write_status ;
8025
    reg `WB_TRANSFER_FLAGS write_flags ;
8026
    reg [31:0] temp_val1 ;
8027
    reg [31:0] temp_val2 ;
8028
    reg        ok   ;
8029
 
8030
    reg [31:0] wb_image_base ;
8031
    reg [31:0] wb_target_address ;
8032
    reg [31:0] pci_image_base ;
8033
    integer i ;
8034
 
8035
    reg     error_monitor_done ;
8036
begin:main
8037
    write_flags`INIT_WAITS = tb_init_waits ;
8038
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
8039
 
8040
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8041
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8042
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8043
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8044
 
8045
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8046
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8047
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8048
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8049
 
8050
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8051
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8052
    lat_tim_cls_offset = 12'hC ;
8053
    pci_device_ctrl_offset    = 12'h4 ;
8054
 
8055
    wb_target_address  = `BEH_TAR1_MEM_START ;
8056
    wb_image_base      = 0 ;
8057
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8058
 
8059
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8060
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8061
    write_flags                    = 0 ;
8062
    write_flags`INIT_WAITS         = 0 ;
8063
    write_flags`SUBSEQ_WAITS       = 0 ;
8064
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8065
 
8066
    pci_image_base = Target_Base_Addr_R[1] ;
8067
 
8068
    // enable master & target operation
8069
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8070
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8071
    if ( ok !== 1 )
8072
    begin
8073
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8074
        test_fail("write to PCI Device Control register failed") ;
8075
        disable main ;
8076
    end
8077
 
8078
    // prepare image control register
8079
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8080
    if ( ok !== 1 )
8081
    begin
8082
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8083
        test_fail("write to WB Image Control register failed") ;
8084
        disable main ;
8085
    end
8086
 
8087
    // prepare base address register
8088
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8089
    if ( ok !== 1 )
8090
    begin
8091
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8092
        test_fail("write to WB Base Address register failed") ;
8093
        disable main ;
8094
    end
8095
 
8096
    // write address mask register
8097
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8098
    if ( ok !== 1 )
8099
    begin
8100
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8101
        test_fail("write to WB Address Mask register failed") ;
8102
        disable main ;
8103
    end
8104
 
8105
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8106
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8107
    if ( ok !== 1 )
8108
    begin
8109
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8110
        test_fail("write to WB Error Control and Status register failed") ;
8111
        disable main ;
8112
    end
8113
 
8114
    // prepare image control register
8115
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8116
    if ( ok !== 1 )
8117
    begin
8118
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8119
        test_fail("write to PCI Image Control register failed") ;
8120
        disable main ;
8121
    end
8122
 
8123
    // prepare base address register
8124
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8125
    if ( ok !== 1 )
8126
    begin
8127
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8128
        test_fail("write to PCI Base Address register failed") ;
8129
        disable main ;
8130
    end
8131
 
8132
    // write address mask register
8133
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8134
    if ( ok !== 1 )
8135
    begin
8136
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8137
        test_fail("write to PCI Address Mask register failed") ;
8138
        disable main ;
8139
    end
8140
 
8141
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8142
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8143
    if ( ok !== 1 )
8144
    begin
8145
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8146
        test_fail("write to PCI Error Control and Status register failed") ;
8147
        disable main ;
8148
    end
8149
 
8150
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8151
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8152
    if ( ok !== 1 )
8153
    begin
8154
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8155
        test_fail("write to Interrupt Control register failed") ;
8156
        disable main ;
8157
    end
8158
 
8159
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8160
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8161
    if ( ok !== 1 )
8162
    begin
8163
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8164
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8165
        disable main ;
8166
    end
8167
 
8168
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8169
 
8170
    // prepare wb_master write and read data
8171
    for ( i = 0 ; i < 4 ; i = i + 1 )
8172
    begin
8173
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8174
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8175
        write_data`WRITE_SEL     = 4'hF ;
8176
 
8177
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8178
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8179
 
8180
        wishbone_master.blk_write_data[i]   = write_data ;
8181
        wishbone_master.blk_read_data_in[i] = read_data ;
8182
    end
8183
 
8184
    // put wishbone slave in acknowledge and pci target in retry mode
8185
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8186
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8187
 
8188
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8189
 
8190
    fork
8191
    begin
8192
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8193
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8194
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8195
        begin
8196
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8197
            test_fail("Bridge didn't post single memory write as expected") ;
8198
        end
8199
 
8200
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8201
        if ( ok !== 1 )
8202
        begin
8203
            $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) ;
8204
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8205
            ok = 0 ;
8206
        end
8207
 
8208
        // now post single write to target - normal progress
8209
        if ( target_mem_image == 1 )
8210
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8211
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8212
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8213
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8214
        else
8215
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8216
 
8217
        do_pause( 1 ) ;
8218
 
8219
    end
8220
    begin:error_monitor_1
8221 35 mihad
        error_monitor_done = 0 ;
8222 15 mihad
        @(error_event_int) ;
8223
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8224
        ok = 0 ;
8225 35 mihad
        error_monitor_done = 1 ;
8226 15 mihad
    end
8227
    begin
8228
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8229
        if ( ok !== 1 )
8230
        begin
8231
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8232
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8233
        end
8234
        else
8235
        begin
8236 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8237
//            while ( FRAME === 0 || IRDY === 0 )
8238
//                @(posedge pci_clock) ;
8239 15 mihad
 
8240
            // enable response in PCI target
8241
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8242
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8243
 
8244
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8245
            if ( ok !== 1 )
8246
            begin
8247
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8248
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8249
            end
8250
        end
8251
 
8252 35 mihad
        #1 ;
8253
        if ( !error_monitor_done )
8254
            disable error_monitor_1 ;
8255 15 mihad
    end
8256
    join
8257
 
8258
    if ( ok )
8259
        test_ok ;
8260
 
8261
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8262
 
8263
    // put WISHBONE slave in retry mode
8264
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8265
 
8266
    fork
8267
    begin
8268
        // now post single write to target - normal progress
8269
        if ( target_mem_image == 1 )
8270
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8271
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8272
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8273
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8274
        else
8275
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8276
 
8277
        do_pause( 1 ) ;
8278
 
8279
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8280
        if ( ok !== 1 )
8281
        begin
8282
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8283
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8284
        end
8285
 
8286
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8287
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8288
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8289
        begin
8290
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8291
            test_fail("Bridge didn't post single memory write as expected") ;
8292
        end
8293
 
8294
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8295
        if ( ok !== 1 )
8296
        begin
8297
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8298
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8299
            ok = 0 ;
8300
        end
8301
 
8302
        wait ( CYC_O === 0 ) ;
8303
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8304
 
8305
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8306
        if ( ok !== 1 )
8307
        begin
8308
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8309
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8310
        end
8311
 
8312 35 mihad
        #1 ;
8313
        if ( !error_monitor_done )
8314
            disable error_monitor_2 ;
8315 15 mihad
    end
8316
    begin:error_monitor_2
8317 35 mihad
        error_monitor_done = 0 ;
8318 15 mihad
        @(error_event_int) ;
8319
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8320
        ok = 0 ;
8321 35 mihad
        error_monitor_done = 1 ;
8322 15 mihad
    end
8323
    join
8324
 
8325
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8326
 
8327
    // put wishbone slave in acknowledge and pci target in retry mode
8328
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8329
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8330
 
8331
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8332
 
8333
    fork
8334
    begin
8335
        write_flags`WB_TRANSFER_SIZE = 3 ;
8336
        write_flags`WB_TRANSFER_CAB  = 1 ;
8337
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8338
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8339
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8340
        begin
8341
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8342
            test_fail("Bridge didn't post burst memory write as expected") ;
8343
        end
8344
 
8345
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8346
        if ( ok !== 1 )
8347
        begin
8348
            $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) ;
8349
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8350
            ok = 0 ;
8351
        end
8352
 
8353
        // now post single write to target - normal progress
8354
        if ( target_mem_image == 1 )
8355
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8356
                        pci_image_base, 32'h5555_5555, 4'h0,
8357
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8358
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8359
        else
8360
        begin
8361
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8362
            do_pause( 1 ) ;
8363
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8364
        end
8365
 
8366
        do_pause( 1 ) ;
8367
 
8368
    end
8369
    begin:error_monitor_3
8370 35 mihad
        error_monitor_done = 0 ;
8371 15 mihad
        @(error_event_int) ;
8372
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8373
        ok = 0 ;
8374 35 mihad
        error_monitor_done = 1 ;
8375 15 mihad
    end
8376
    begin
8377
        if ( target_mem_image == 1 )
8378
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8379
        else
8380
        begin
8381
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8382
            if ( ok )
8383
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8384
        end
8385
 
8386
        if ( ok !== 1 )
8387
        begin
8388
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8389
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8390
        end
8391
        else
8392
        begin
8393 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8394
//            while ( FRAME === 0 || IRDY === 0 )
8395
//                @(posedge pci_clock) ;
8396 15 mihad
 
8397
            // enable response in PCI target
8398
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8399
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8400
 
8401
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8402
            if ( ok !== 1 )
8403
            begin
8404
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8405
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8406
            end
8407
        end
8408
 
8409 35 mihad
        #1 ;
8410
        if ( !error_monitor_done )
8411
            disable error_monitor_3 ;
8412 15 mihad
    end
8413
    join
8414
 
8415
    if ( ok )
8416
        test_ok ;
8417
 
8418
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8419
 
8420
    // put WISHBONE slave in retry mode
8421
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8422
 
8423
    fork
8424
    begin
8425
        // now post single write to target - normal progress
8426
        if ( target_mem_image == 1 )
8427
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8428
                        pci_image_base, 32'h5555_5555, 4'h0,
8429
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8430
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8431
        else
8432
        begin
8433
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8434
            do_pause( 1 ) ;
8435
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8436
        end
8437
 
8438
        do_pause( 1 ) ;
8439
 
8440
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8441
 
8442
        if ( ok !== 1 )
8443
        begin
8444
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8445
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8446
        end
8447
 
8448
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8449
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8450
        write_flags`WB_TRANSFER_CAB      = 1 ;
8451
 
8452
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8453
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8454
        begin
8455
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8456
            test_fail("Bridge didn't post burst memory write as expected") ;
8457
        end
8458
 
8459
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8460
        if ( ok !== 1 )
8461
        begin
8462
            $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) ;
8463
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8464
            ok = 0 ;
8465
        end
8466
 
8467
        @(posedge wb_clock) ;
8468
        while ( CYC_O === 1 )
8469
            @(posedge wb_clock) ;
8470
 
8471
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8472
 
8473
        if ( target_mem_image == 1 )
8474
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8475
        else
8476
        begin
8477
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8478
            if ( ok )
8479
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8480
        end
8481
 
8482 35 mihad
        #1 ;
8483
        if ( !error_monitor_done )
8484
            disable error_monitor_4 ;
8485 15 mihad
    end
8486
    begin:error_monitor_4
8487 35 mihad
        error_monitor_done = 0 ;
8488 15 mihad
        @(error_event_int) ;
8489
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8490
        ok = 0 ;
8491 35 mihad
        error_monitor_done = 1 ;
8492 15 mihad
    end
8493
    join
8494
 
8495
    if ( ok )
8496
        test_ok ;
8497
 
8498
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8499
 
8500
    // put wishbone slave in acknowledge and pci target in retry mode
8501
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8502
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8503
 
8504
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8505
 
8506
    master1_check_received_data = 1 ;
8507
 
8508
    error_monitor_done = 0 ;
8509
    fork
8510
    begin:error_monitor_5
8511
        @(error_event_int or error_monitor_done) ;
8512
        if ( !error_monitor_done )
8513
        begin
8514
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8515
            ok = 0 ;
8516
        end
8517
    end
8518
    begin
8519
 
8520
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8521
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8522
        begin
8523
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8524
            test_fail("Bridge didn't post single memory write as expected") ;
8525
        end
8526
 
8527
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8528
        if ( ok !== 1 )
8529
        begin
8530
            $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) ;
8531
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8532
            ok = 0 ;
8533
        end
8534
 
8535
        // start Read Through pci target
8536
        if ( target_mem_image == 1 )
8537
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8538
                          pci_image_base, 32'h5555_5555,
8539
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8540
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8541
        else
8542
            PCIU_IO_READ
8543
             (
8544
                `Test_Master_1,
8545
                pci_image_base,
8546
                32'h5555_5555,
8547
                4'h0,
8548
                1,
8549
                `Test_Target_Retry_On
8550
             );
8551
 
8552
         do_pause( 1 ) ;
8553
 
8554
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8555
         if ( ok !== 1 )
8556
         begin
8557
            $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) ;
8558
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8559
         end
8560
 
8561
         // repeat the read 4 times - it should be retried all the time by pci target
8562
        for ( i = 0 ; i < 4 ; i = i + 1 )
8563
        begin
8564
            if ( target_mem_image == 1 )
8565
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8566
                            pci_image_base, 32'h5555_5555,
8567
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8568
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8569
            else
8570
                PCIU_IO_READ
8571
                (
8572
                    `Test_Master_1,
8573
                    pci_image_base,
8574
                    32'h5555_5555,
8575
                    4'h0,
8576
                    1,
8577
                    `Test_Target_Retry_On
8578
                );
8579
 
8580
            do_pause( 1 ) ;
8581
        end
8582
 
8583
        // now do posted write through target - it must go through OK
8584
        if ( target_mem_image == 1 )
8585
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8586
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8587
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8588
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8589
        else
8590
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8591
 
8592
        do_pause( 1 ) ;
8593
 
8594
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8595
        if ( ok !== 1 )
8596
        begin
8597
           $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) ;
8598
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8599
        end
8600
 
8601
        // start a read through wb_slave
8602
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8603
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8604
        begin
8605
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8606
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8607
            ok = 0 ;
8608
        end
8609
 
8610 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8611
//        while ( FRAME === 0 || IRDY === 0 )
8612
//            @(posedge pci_clock) ;
8613 15 mihad
 
8614
        // set the target to normal completion
8615
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8616
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8617
 
8618
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8619
        if ( ok !== 1 )
8620
        begin
8621
            $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) ;
8622
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8623
            ok = 0 ;
8624
        end
8625
 
8626
        // now wait for delayed read to finish
8627
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8628
        if ( ok !== 1 )
8629
        begin
8630
            $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) ;
8631
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8632
            ok = 0 ;
8633
        end
8634
 
8635
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8636
        fork
8637
        begin
8638
                if ( target_mem_image == 1 )
8639
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8640
                                pci_image_base, 32'h5555_5555, 4'h0,
8641
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8642
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8643
                else
8644
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8645
 
8646
                do_pause( 1 ) ;
8647
                end
8648
                begin
8649
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8650
                end
8651
                join
8652
 
8653
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8654
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8655
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8656
        begin
8657
            $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) ;
8658
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8659
            ok = 0 ;
8660
        end
8661
 
8662
        fork
8663
        begin
8664
        // now complete a read from PCI Target
8665
            if ( target_mem_image == 1 )
8666
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8667
                            pci_image_base, 32'h5555_5555,
8668
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8669
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8670
            else
8671
                PCIU_IO_READ
8672
                (
8673
                    `Test_Master_1,
8674
                    pci_image_base,
8675
                    32'h5555_5555,
8676
                    4'h0,
8677
                    1,
8678
                    `Test_Target_Normal_Completion
8679
                );
8680
 
8681
            do_pause( 1 ) ;
8682
        end
8683
        begin
8684
            if ( target_mem_image == 1 )
8685
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8686
            else
8687
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8688
        end
8689
        join
8690
 
8691
        @(posedge pci_clock) ;
8692
        repeat( 4 )
8693
            @(posedge wb_clock) ;
8694
 
8695
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8696
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8697
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8698
        begin
8699
            $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) ;
8700
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8701
            ok = 0 ;
8702
        end
8703
 
8704
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8705
        if ( ok !== 1 )
8706
        begin
8707
            $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) ;
8708
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8709
            ok = 0 ;
8710
        end
8711
 
8712
        // finish a read on WISHBONE also
8713
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8714
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8715
        begin
8716
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8717
            test_fail("WB Slave didn't process single delayed read as expected") ;
8718
        end
8719
 
8720
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8721
        begin
8722
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8723
            ok = 0 ;
8724
        end
8725
 
8726
 
8727
        error_monitor_done = 1 ;
8728
    end
8729
    join
8730
 
8731
    if ( ok )
8732
        test_ok ;
8733
 
8734
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8735
 
8736
    // put wishbone slave in retry and pci target in completion mode
8737
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8738
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8739
 
8740
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8741
 
8742
    master1_check_received_data = 1 ;
8743
 
8744
    error_monitor_done = 0 ;
8745
    fork
8746
    begin:error_monitor_6
8747
        @(error_event_int or error_monitor_done) ;
8748
        if ( !error_monitor_done )
8749
        begin
8750
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8751
            ok = 0 ;
8752
        end
8753
    end
8754
    begin
8755
 
8756
        // do a write through Target
8757
        fork
8758
        begin
8759
            if ( target_mem_image == 1 )
8760
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8761
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8762
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8763
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8764
            else
8765
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8766
 
8767
            do_pause( 1 ) ;
8768
        end
8769
        begin
8770
            if ( target_mem_image == 1 )
8771
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8772
            else
8773
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8774
        end
8775
        join
8776
 
8777
        // start a read through WB slave
8778
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8779
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8780
        begin
8781
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8782
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8783
            ok = 0 ;
8784
        end
8785
 
8786
        // now wait for this read to finish on pci
8787
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8788
        if ( ok !== 1 )
8789
        begin
8790
            $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) ;
8791
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8792
            ok = 0 ;
8793
        end
8794
 
8795
        // repeat the read four times - it should be retried
8796
        for ( i = 0 ; i < 4 ; i = i + 1 )
8797
        begin
8798
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8799
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8800
            begin
8801
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8802
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8803
                ok = 0 ;
8804
            end
8805
        end
8806
 
8807
        // posted write through WB Slave - must go through
8808
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8809
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8810
        begin
8811
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8812
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8813
            ok = 0 ;
8814
        end
8815
 
8816
        // write must come through
8817
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8818
        if ( ok !== 1 )
8819
        begin
8820
            $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) ;
8821
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8822
            ok = 0 ;
8823
        end
8824
 
8825
        // do a read through pci target
8826
        if ( target_mem_image == 1 )
8827
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8828
                          pci_image_base + 12, 32'hDEAD_BEAF,
8829
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8830
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8831
        else
8832
            PCIU_IO_READ
8833
             (
8834
                `Test_Master_1,
8835
                pci_image_base + 12,
8836
                32'hDEAD_BEAF,
8837
                4'h0,
8838
                1,
8839
                `Test_Target_Retry_On
8840
             );
8841
 
8842
         do_pause( 1 ) ;
8843
 
8844
        // wait for current cycle to finish on WB
8845 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8846
//        @(posedge wb_clock) ;
8847
//        while( CYC_O === 1 )
8848
//            @(posedge wb_clock) ;
8849 15 mihad
 
8850
        // set slave response to acknowledge
8851
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8852
 
8853
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8854
        if ( ok !== 1 )
8855
        begin
8856
            $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) ;
8857
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8858
        end
8859
 
8860
        // check the read to finish on wb
8861
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8862
        if ( ok !== 1 )
8863
        begin
8864
            $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) ;
8865
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8866
        end
8867
 
8868
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8869
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8870
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8871
        begin
8872
            $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) ;
8873
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8874
            ok = 0 ;
8875
        end
8876
 
8877
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8878
        fork
8879
        begin
8880
            if ( target_mem_image == 1 )
8881
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8882
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8883
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8884
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8885
            else
8886
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8887
        end
8888
        begin
8889
            if ( target_mem_image == 1 )
8890
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8891
            else
8892
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8893
        end
8894
        join
8895
 
8896
        do_pause( 1 ) ;
8897
 
8898
        // complete a read in WB Slave Unit
8899
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8900
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8901
        begin
8902
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8903
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8904
            ok = 0 ;
8905
        end
8906
 
8907
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8908
        begin
8909
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8910
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8911
            ok = 0 ;
8912
        end
8913
 
8914
        // wait for statuses to be propagated from one side of bridge to another
8915
        repeat( 4 )
8916
            @(posedge pci_clock) ;
8917
 
8918
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8919
        fork
8920
        begin
8921
            if ( target_mem_image == 1 )
8922
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8923
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8924
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8925
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8926
            else
8927
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8928
 
8929
            do_pause( 1 ) ;
8930
        end
8931
        begin
8932
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8933
            if ( ok !== 1 )
8934
            begin
8935
                $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) ;
8936
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8937
            end
8938
        end
8939
        join
8940
 
8941
        // finish the last read in PCI Target Unit
8942
        if ( target_mem_image == 1 )
8943
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8944
                          pci_image_base + 12, 32'hDEAD_BEAF,
8945
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8946
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8947
        else
8948
            PCIU_IO_READ
8949
             (
8950
                `Test_Master_1,
8951
                pci_image_base + 12,
8952
                32'hDEAD_BEAF,
8953
                4'h0,
8954
                1,
8955
                `Test_Target_Normal_Completion
8956
             );
8957
 
8958
         do_pause( 1 ) ;
8959
 
8960
         error_monitor_done = 1 ;
8961
    end
8962
    join
8963
 
8964
    if ( ok )
8965
        test_ok ;
8966
 
8967
end
8968
endtask // transaction_ordering
8969
 
8970
task pci_transaction_progress_monitor ;
8971
    input [31:0] address ;
8972
    input [3:0]  bus_command ;
8973
    input [31:0] num_of_transfers ;
8974
    input [31:0] num_of_cycles ;
8975
    input check_transfers ;
8976
    input check_cycles ;
8977
    input doing_fast_back_to_back ;
8978
    output ok ;
8979
    reg in_use ;
8980
    integer deadlock_counter ;
8981
    integer transfer_counter ;
8982
    integer cycle_counter ;
8983
    integer deadlock_max_val ;
8984
begin:main
8985
 
8986
    if ( in_use === 1 )
8987
    begin
8988
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8989
        ok = 0 ;
8990
        disable main ;
8991
    end
8992
 
8993
    // approximate number of cycles on WB bus for maximum transaction length
8994
    deadlock_max_val = tb_init_waits + 100 +
8995
                       `WBW_DEPTH *
8996
                       (tb_subseq_waits + 1 +
8997
                       `ifdef REGISTER_WBS_OUTPUTS
8998
                       1) ;
8999
                       `else
9000
                       0) ;
9001
                       `endif
9002
 
9003
    // time used for maximum transaction length on WB
9004
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
9005
 
9006
    // maximum pci clock cycles
9007
    `ifdef PCI33
9008
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
9009
    `else
9010
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
9011
    `endif
9012
 
9013
    in_use = 1 ;
9014
    ok     = 1 ;
9015
 
9016
    fork
9017
    begin:wait_start
9018
 
9019
        deadlock_counter = 0 ;
9020
 
9021
        @(posedge pci_clock) ;
9022
 
9023
        if ( doing_fast_back_to_back !== 1 )
9024
        begin
9025
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
9026
            begin
9027 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
9028
                    deadlock_counter = 0 ;
9029
                else
9030
                    deadlock_counter = deadlock_counter + 1 ;
9031 15 mihad
                @(posedge pci_clock) ;
9032
            end
9033
            if ( FRAME !== 1 )
9034
            begin
9035
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9036
                in_use = 0 ;
9037
                ok     = 0 ;
9038
                disable main ;
9039
            end
9040
        end
9041
 
9042
        deadlock_counter = 0 ;
9043
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
9044
        begin
9045
            deadlock_counter = deadlock_counter + 1 ;
9046
            @(posedge pci_clock) ;
9047
        end
9048
 
9049
        if ( FRAME !== 0 )
9050
        begin
9051
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9052
            in_use = 0 ;
9053
            ok     = 0 ;
9054
            disable main ;
9055
        end
9056
    end //wait_start
9057
 
9058
    begin:addr_bc_monitor
9059
 
9060
        @(posedge pci_clock) ;
9061
 
9062
        if ( doing_fast_back_to_back !== 1 )
9063
        begin
9064
            while ( FRAME !== 1 )
9065
                @(posedge pci_clock) ;
9066
        end
9067
 
9068
        while( FRAME !== 0 )
9069
            @(posedge pci_clock) ;
9070
 
9071
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9072
        if ( bus_command !== `BC_IACK )
9073
        begin
9074
            if ( AD !== address )
9075
            begin
9076
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9077
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9078
                ok = 0 ;
9079
            end
9080
        end
9081
 
9082
        if ( CBE !== bus_command )
9083
        begin
9084
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9085
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9086
            ok = 0 ;
9087
        end
9088
    end //addr_bc_monitor
9089
 
9090
    begin:transfer_checker
9091
        transfer_counter = 0 ;
9092
 
9093
        @(posedge pci_clock) ;
9094
 
9095
        if ( doing_fast_back_to_back !== 1 )
9096
        begin
9097
            while ( FRAME !== 1 )
9098
                @(posedge pci_clock) ;
9099
        end
9100
 
9101
        while( FRAME !== 0 )
9102
            @(posedge pci_clock) ;
9103
 
9104
        while( FRAME === 0 )
9105
        begin
9106
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9107
                transfer_counter = transfer_counter + 1 ;
9108
            @(posedge pci_clock) ;
9109
        end
9110
 
9111
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9112
        begin
9113
            @(posedge pci_clock) ;
9114
        end
9115
 
9116
        if ( (TRDY === 0) && (DEVSEL === 0) )
9117
                transfer_counter = transfer_counter + 1 ;
9118
 
9119
        if ( check_transfers === 1 )
9120
        begin
9121
            if ( transfer_counter !== num_of_transfers )
9122
            begin
9123
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9124
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9125
                ok = 0 ;
9126
            end
9127
        end
9128
    end //transfer_checker
9129
    begin:cycle_checker
9130
        if ( check_cycles )
9131
        begin
9132
            cycle_counter = 0 ;
9133
            @(posedge pci_clock) ;
9134
 
9135
            if ( doing_fast_back_to_back !== 1)
9136
            begin
9137
                while ( FRAME !== 1 )
9138
                    @(posedge pci_clock) ;
9139
            end
9140
 
9141
            while( FRAME !== 0 )
9142
                @(posedge pci_clock) ;
9143
 
9144
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9145
            begin
9146
                cycle_counter = cycle_counter + 1 ;
9147
                @(posedge pci_clock) ;
9148
            end
9149
 
9150
            if ( FRAME !== 1 )
9151
            begin
9152
                while ((FRAME === 0) && (MAS0_GNT === 0))
9153
                    @(posedge pci_clock) ;
9154
 
9155
                if ( FRAME !== 1 )
9156
                begin
9157
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9158
                        @(posedge pci_clock) ;
9159
 
9160
                    @(posedge pci_clock) ;
9161
 
9162
                    if ( FRAME !== 1 )
9163
                    begin
9164
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9165
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9166
                        ok = 0 ;
9167
                    end
9168
                end
9169
            end
9170
        end
9171
    end // cycle_checker
9172
    join
9173
 
9174
    in_use = 0 ;
9175
end
9176
endtask //pci_transaction_progress_monitor
9177
 
9178
reg CYC_O_previous ;
9179
always@(posedge wb_clock or posedge reset)
9180
begin
9181
    if ( reset )
9182
        CYC_O_previous <= #1 1'b0 ;
9183
    else
9184
        CYC_O_previous <= #1 CYC_O ;
9185
end
9186
 
9187
task wb_transaction_progress_monitor ;
9188
    input [31:0] address ;
9189
    input        write ;
9190
    input [31:0] num_of_transfers ;
9191
    input check_transfers ;
9192
    output ok ;
9193
    reg in_use ;
9194
    integer deadlock_counter ;
9195
    integer transfer_counter ;
9196
    integer deadlock_max_val ;
9197
begin:main
9198
    if ( in_use === 1 )
9199
    begin
9200
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9201
        ok = 0 ;
9202
        disable main ;
9203
    end
9204
 
9205
    // number of cycles on WB bus for maximum transaction length
9206
    deadlock_max_val = 4 - tb_init_waits + 100 +
9207
                       `PCIW_DEPTH *
9208
                       (4 - tb_subseq_waits + 1) ;
9209
 
9210
    // time used for maximum transaction length on PCI
9211
    `ifdef PCI33
9212
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9213
    `else
9214
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9215
    `endif
9216
 
9217
    // maximum wb clock cycles
9218
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9219
 
9220
    in_use = 1 ;
9221
    ok     = 1 ;
9222
 
9223
    fork
9224
    begin:wait_start
9225
        deadlock_counter = 0 ;
9226
        @(posedge wb_clock) ;
9227
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9228
        begin
9229 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9230
                deadlock_counter = deadlock_counter + 1 ;
9231
            else
9232
                deadlock_counter = 0;
9233 15 mihad
            @(posedge wb_clock) ;
9234
        end
9235
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9236
        begin
9237
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9238
            in_use = 0 ;
9239
            ok     = 0 ;
9240
            disable main ;
9241
        end
9242
 
9243
        deadlock_counter = 0 ;
9244
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9245
        begin
9246
            deadlock_counter = deadlock_counter + 1 ;
9247
            @(posedge wb_clock) ;
9248
        end
9249
 
9250
        if ( CYC_O !== 1 )
9251
        begin
9252
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9253
            in_use = 0 ;
9254
            ok     = 0 ;
9255
            disable main ;
9256
        end
9257
    end //wait_start
9258
    begin:addr_monitor
9259
        @(posedge wb_clock) ;
9260
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9261
            @(posedge wb_clock) ;
9262
 
9263
        while( CYC_O !== 1 )
9264
            @(posedge wb_clock) ;
9265
 
9266
        while (STB_O !== 1 )
9267
            @(posedge wb_clock) ;
9268
 
9269
        if ( WE_O !== write )
9270
        begin
9271
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9272
            if ( write !== 1 )
9273
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9274
            else
9275
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9276
        end
9277
 
9278
        if ( ADR_O !== address )
9279
        begin
9280
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9281
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9282
            ok = 0 ;
9283
        end
9284
    end
9285
    begin:transfer_checker
9286
        transfer_counter = 0 ;
9287
        @(posedge wb_clock) ;
9288
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9289
            @(posedge wb_clock) ;
9290
 
9291
        while( CYC_O !== 1 )
9292
            @(posedge wb_clock) ;
9293
 
9294 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9295 15 mihad
        begin
9296
            if ( (STB_O === 1) && (ACK_I === 1) )
9297
                transfer_counter = transfer_counter + 1 ;
9298
            @(posedge wb_clock) ;
9299
        end
9300
 
9301
        if ( check_transfers === 1 )
9302
        begin
9303
            if ( transfer_counter !== num_of_transfers )
9304
            begin
9305
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9306
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9307
                ok = 0 ;
9308
            end
9309
        end
9310
    end //transfer_checker
9311
    join
9312
 
9313
    in_use = 0 ;
9314
end
9315
endtask // wb_transaction_progress_monitor
9316
 
9317
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9318
// so they are not re-entered
9319
task wb_transaction_progress_monitor_backup ;
9320
    input [31:0] address ;
9321
    input        write ;
9322
    input [31:0] num_of_transfers ;
9323
    input check_transfers ;
9324
    output ok ;
9325
    reg in_use ;
9326
    integer deadlock_counter ;
9327
    integer transfer_counter ;
9328
    integer deadlock_max_val ;
9329
begin:main
9330
    if ( in_use === 1 )
9331
    begin
9332
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9333
        ok = 0 ;
9334
        disable main ;
9335
    end
9336
 
9337
    // number of cycles on WB bus for maximum transaction length
9338
    deadlock_max_val = 4 - tb_init_waits + 100 +
9339
                       `PCIW_DEPTH *
9340
                       (4 - tb_subseq_waits + 1) ;
9341
 
9342
    // time used for maximum transaction length on PCI
9343
    `ifdef PCI33
9344
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9345
    `else
9346
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9347
    `endif
9348
 
9349
    // maximum wb clock cycles
9350
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9351
 
9352
    in_use = 1 ;
9353
    ok     = 1 ;
9354
 
9355
    fork
9356
    begin:wait_start
9357
        deadlock_counter = 0 ;
9358
        @(posedge wb_clock) ;
9359
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9360
        begin
9361 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9362
                deadlock_counter = deadlock_counter + 1 ;
9363
            else
9364
                deadlock_counter = 0;
9365 15 mihad
            @(posedge wb_clock) ;
9366
        end
9367
        if ( CYC_O !== 0 )
9368
        begin
9369
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9370
            in_use = 0 ;
9371
            ok     = 0 ;
9372
            disable main ;
9373
        end
9374
 
9375
        deadlock_counter = 0 ;
9376
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9377
        begin
9378
            deadlock_counter = deadlock_counter + 1 ;
9379
            @(posedge wb_clock) ;
9380
        end
9381
 
9382
        if ( CYC_O !== 1 )
9383
        begin
9384
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9385
            in_use = 0 ;
9386
            ok     = 0 ;
9387
            disable main ;
9388
        end
9389
    end //wait_start
9390
    begin:addr_monitor
9391
        @(posedge wb_clock) ;
9392
        while ( CYC_O !== 0 )
9393
            @(posedge wb_clock) ;
9394
 
9395
        while( CYC_O !== 1 )
9396
            @(posedge wb_clock) ;
9397
 
9398
        while (STB_O !== 1 )
9399
            @(posedge wb_clock) ;
9400
 
9401
        if ( WE_O !== write )
9402
        begin
9403
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9404
            if ( write !== 1 )
9405
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9406
            else
9407
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9408
        end
9409
 
9410
        if ( ADR_O !== address )
9411
        begin
9412
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9413
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9414
            ok = 0 ;
9415
        end
9416
    end
9417
    begin:transfer_checker
9418
        transfer_counter = 0 ;
9419
        @(posedge wb_clock) ;
9420
        while ( CYC_O !== 0 )
9421
            @(posedge wb_clock) ;
9422
 
9423
        while( CYC_O !== 1 )
9424
            @(posedge wb_clock) ;
9425
 
9426
        while( CYC_O === 1 )
9427
        begin
9428
            if ( (STB_O === 1) && (ACK_I === 1) )
9429
                transfer_counter = transfer_counter + 1 ;
9430
            @(posedge wb_clock) ;
9431
        end
9432
 
9433
        if ( check_transfers === 1 )
9434
        begin
9435
            if ( transfer_counter !== num_of_transfers )
9436
            begin
9437
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9438
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9439
                ok = 0 ;
9440
            end
9441
        end
9442
    end //transfer_checker
9443
    join
9444
 
9445
    in_use = 0 ;
9446
end
9447
endtask // wb_transaction_progress_monitor_backup
9448
 
9449
task wb_transaction_stop ;
9450
    input [31:0] num_of_transfers ;
9451
    integer transfer_counter ;
9452
begin:main
9453
    begin:transfer_checker
9454
        transfer_counter = 0 ;
9455
        @(posedge wb_clock) ;
9456
        while ( CYC_O !== 0 )
9457
            @(posedge wb_clock) ;
9458
 
9459
        while( CYC_O !== 1 )
9460
            @(posedge wb_clock) ;
9461
 
9462
        if ( (STB_O === 1) && (ACK_I === 1) )
9463
            transfer_counter = transfer_counter + 1 ;
9464
 
9465
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9466
        begin
9467
            @(posedge wb_clock) ;
9468
            if ( (STB_O === 1) && (ACK_I === 1) )
9469
                transfer_counter = transfer_counter + 1 ;
9470
        end
9471
    end //transfer_checker
9472
end
9473
endtask // wb_transaction_stop
9474
 
9475
task musnt_respond ;
9476
    output ok ;
9477
    reg in_use ;
9478
    integer i ;
9479
begin:main
9480
    if ( in_use === 1 )
9481
    begin
9482
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9483
        #20 $stop ;
9484
        ok = 0 ;
9485
        disable main ;
9486
    end
9487
 
9488
    in_use = 1 ;
9489
    ok = 1 ;
9490
 
9491
    fork
9492
    begin:wait_start
9493
        @(negedge FRAME) ;
9494
        disable count ;
9495
    end
9496
    begin:count
9497
        i = 0 ;
9498
        while ( i < 1000 )
9499
        begin
9500
            @(posedge pci_clock) ;
9501
            i = i + 1 ;
9502
        end
9503
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9504
        ok = 0 ;
9505
        disable wait_start ;
9506
    end
9507
    join
9508
 
9509
    @(posedge pci_clock) ;
9510
    while ( FRAME === 0 && ok )
9511
    begin
9512
        if ( DEVSEL !== 1 )
9513
        begin
9514
            ok = 0 ;
9515
        end
9516
        @(posedge pci_clock) ;
9517
    end
9518
 
9519
    while ( IRDY === 0 && ok )
9520
    begin
9521
        if ( DEVSEL !== 1 )
9522
        begin
9523
            ok = 0 ;
9524
        end
9525
        @(posedge pci_clock) ;
9526
    end
9527
    in_use = 0 ;
9528
end
9529
endtask
9530
 
9531
function [31:0] wb_to_pci_addr_convert ;
9532
    input [31:0] wb_address ;
9533
    input [31:0] translation_address ;
9534
    input [31:0] translate ;
9535
 
9536
    reg   [31:0] temp_address ;
9537
begin
9538
    if ( translate !== 1 )
9539
    begin
9540
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9541
    end
9542
    else
9543
    begin
9544
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9545
    end
9546
 
9547
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9548
    wb_to_pci_addr_convert = temp_address ;
9549
end
9550
endfunction //wb_to_pci_addr_convert
9551
 
9552 45 mihad
`ifdef HOST
9553 15 mihad
task find_pci_devices ;
9554
    integer device_num ;
9555
    reg     found ;
9556
    reg [11:0] pci_ctrl_offset ;
9557
    reg ok ;
9558
    reg [31:0] data ;
9559 45 mihad
    reg [31:0] expected_data ;
9560
 
9561
    reg [5:0]  reg_num ;
9562 15 mihad
begin:main
9563 45 mihad
 
9564
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9565 15 mihad
    pci_ctrl_offset = 12'h004 ;
9566
 
9567
    // enable master & target operation
9568
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9569
 
9570
    if ( ok !== 1 )
9571
    begin
9572
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9573 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9574 15 mihad
        disable main ;
9575
    end
9576
    // find all possible devices on pci bus by performing configuration cycles
9577 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9578 15 mihad
    begin
9579
        find_device ( device_num, found ) ;
9580
 
9581
        // check pci status register - if device is not present, Received Master Abort bit must be set
9582
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9583
 
9584
        if ( (data[29] !== 0) && (found !== 0) )
9585 45 mihad
        begin
9586 15 mihad
            $display( "Time %t ", $time ) ;
9587
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9588
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9589 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9590
            ok = 0 ;
9591 15 mihad
        end
9592
 
9593
        if ( (data[29] !== 1) && (found !== 1) )
9594
        begin
9595
            $display( "Time %t ", $time ) ;
9596
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9597
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9598 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9599
            ok = 0 ;
9600 15 mihad
        end
9601
 
9602
        // clear Master Abort status if set
9603
        if ( data[29] !== 0 )
9604
        begin
9605
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9606
        end
9607 45 mihad
 
9608
        if (found === 1)
9609
        begin
9610
            // first check if found target is supposed to exist
9611
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9612
            begin
9613
                $display("Time %t", $time) ;
9614
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9615
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9616
                ok = 0 ;
9617
            end
9618
            else
9619
            begin
9620
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9621
                begin
9622
 
9623
                    data = 32'hFFFF_FFFF ;
9624
 
9625
                    expected_data = 0 ;
9626
 
9627
                    if (reg_num == 4)
9628
                    begin
9629
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9630
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9631
                    end
9632
                    else if (reg_num == 5)
9633
                    begin
9634
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9635
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9636
                    end
9637
 
9638
                    // write base address 0
9639
                    generate_configuration_cycle
9640
                    (
9641
                        'h0,            //bus_num
9642
                        device_num,     //device_num
9643
                        'h0,            //func_num
9644
                        reg_num,        //reg_num
9645
                        'h0,            //type
9646
                        4'hF,           // byte_enables
9647
                        data,           //data
9648
                        1'b1            //read0_write1
9649
                    );
9650
 
9651
                    // read data back
9652
                    generate_configuration_cycle
9653
                    (
9654
                        'h0,            //bus_num
9655
                        device_num,     //device_num
9656
                        'h0,            //func_num
9657
                        reg_num,        //reg_num
9658
                        'h0,            //type
9659
                        4'hF,           // byte_enables
9660
                        data,           //data
9661
                        1'b0            //read0_write1
9662
                    );
9663
 
9664
                    if (data !== expected_data)
9665
                    begin
9666
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9667
                        $display("Data read back not as expected!");
9668
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9669
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9670
                        ok = 0 ;
9671
                    end
9672
                end
9673
            end
9674
        end
9675 15 mihad
    end
9676 45 mihad
 
9677
    if (ok)
9678
        test_ok ;
9679 15 mihad
end //main
9680
endtask //find_pci_devices
9681
 
9682
task find_device ;
9683
    input [31:0] device_num ;
9684
    output  found ;
9685
 
9686
    reg [31:0] read_data ;
9687
begin
9688
    found = 1'b0 ;
9689
 
9690
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9691 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9692 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9693
    else
9694
    begin
9695
        $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]) ;
9696
        found = 1'b1 ;
9697
    end
9698
end
9699
endtask //find_device
9700 45 mihad
`endif
9701 15 mihad
 
9702
/*task set_bridge_parameters ;
9703
    reg [11:0] current_offset ;
9704
    reg [2:0] result ;
9705
    reg [31:0] write_data ;
9706
begin
9707
    // set burst size
9708
    // set latency timer
9709
    current_offset = 12'h00C ;
9710
    // set burst size to 16 and latency timer to 8
9711
    write_data     = {24'h0000_08, system_burst_size} ;
9712
    config_write(current_offset, write_data, 4'b1111) ;
9713
 
9714
    // set io image
9715
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9716
    write_data = 32'h0000_000_3 ;
9717
    config_write(current_offset, write_data, 4'b1111) ;
9718
 
9719
 
9720
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9721
    write_data = 32'h0001_000_1 ;
9722
    config_write(current_offset, write_data, 4'b1111) ;
9723
 
9724
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9725
    write_data = 32'hFFFF_0000 ;
9726
    config_write(current_offset, write_data, 4'b1111) ;
9727
 
9728
    // set memory image
9729
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9730
    write_data = 32'h0000_000_7 ;
9731
    config_write(current_offset, write_data, 4'b1111) ;
9732
 
9733
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9734
    write_data = 32'h0002_000_0 ;
9735
    config_write(current_offset, write_data, 4'b1111) ;
9736
 
9737
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9738
    write_data = 32'h0001_0000 ;
9739
    config_write(current_offset, write_data, 4'b1111) ;
9740
 
9741
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9742
    write_data = 32'hFFFF_0000 ;
9743
    config_write(current_offset, write_data, 4'b1111) ;
9744
 
9745
    // set parameters for bridge's target unit
9746
    // image control 0
9747
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9748
    write_data     = 32'h0000_0002 ;
9749
    config_write(current_offset, write_data, 4'b0001) ;
9750
 
9751
    // base_address 0
9752
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9753
    write_data      = 32'h2000_0000 ;
9754
    config_write(current_offset, write_data, 4'b1111) ;
9755
 
9756
    // address mask 0
9757
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9758
    write_data     = 32'hFFFF_F000 ;
9759
    config_write(current_offset, write_data, 4'b1111) ;
9760
 
9761
    // command register - enable response to io and mem space and PCI master
9762
    current_offset = 12'h004 ;
9763
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9764
    config_write(current_offset, write_data, 4'b1111) ;
9765
end
9766
endtask // set_bridge_parameters
9767
*/
9768
 
9769
task configuration_cycle_write ;
9770
    input [7:0]  bus_num ;
9771
    input [4:0]  device_num ;
9772
    input [2:0]  func_num ;
9773
    input [5:0]  reg_num ;
9774
    input [1:0]  type ;
9775
    input [3:0]  byte_enables ;
9776
    input [31:0] data ;
9777
 
9778
    reg [31:0] write_address ;
9779
    reg in_use ;
9780
    reg ok ;
9781
begin:main
9782
 
9783
    if ( in_use === 1 )
9784
    begin
9785 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9786 15 mihad
        disable main ;
9787
    end
9788
 
9789 45 mihad
    if ( (device_num > 20) && (type === 0) )
9790 15 mihad
    begin
9791
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9792
        disable main ;
9793
    end
9794
 
9795
    in_use = 1 ;
9796
 
9797 45 mihad
 
9798
`ifdef HOST
9799
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9800
`else
9801
`ifdef GUEST
9802
 
9803 15 mihad
    if ( type )
9804
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9805
    else
9806
    begin
9807
        write_address = 0 ;
9808
        write_address[10:0] = { func_num, reg_num, type } ;
9809
        write_address[11 + device_num] = 1'b1 ;
9810
    end
9811 45 mihad
 
9812
    fork
9813 15 mihad
    begin
9814 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9815
                            write_address,
9816
                            data, ~byte_enables,
9817
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9818
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9819
        do_pause(1) ;
9820 15 mihad
    end
9821 45 mihad
    begin
9822
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9823
    end
9824
    join
9825
`endif
9826
`endif
9827
 
9828
    in_use = 0 ;
9829
end
9830
endtask // configuration_cycle_write
9831 15 mihad
 
9832 45 mihad
task configuration_cycle_read ;
9833
    input [7:0]  bus_num ;
9834
    input [4:0]  device_num ;
9835
    input [2:0]  func_num ;
9836
    input [5:0]  reg_num ;
9837
    input [1:0]  type ;
9838
    input [3:0]  byte_enables ;
9839
    output [31:0] data ;
9840 15 mihad
 
9841 45 mihad
    reg [31:0] read_address ;
9842
    reg in_use ;
9843 15 mihad
 
9844 45 mihad
    reg master_check_data_prev ;
9845
begin:main
9846 15 mihad
 
9847 45 mihad
    if ( in_use === 1 )
9848 15 mihad
    begin
9849 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9850
        data = 32'hxxxx_xxxx ;
9851
        disable main ;
9852 15 mihad
    end
9853
 
9854 45 mihad
    in_use = 1 ;
9855 15 mihad
 
9856 45 mihad
`ifdef HOST
9857
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9858
`else
9859
`ifdef GUEST
9860
     master_check_data_prev = master1_check_received_data ;
9861 15 mihad
     if ( type )
9862 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9863 15 mihad
     else
9864
     begin
9865 45 mihad
         read_address = 0 ;
9866
         read_address[10:0] = { func_num, reg_num, type } ;
9867
         read_address[11 + device_num] = 1'b1 ;
9868 15 mihad
     end
9869 45 mihad
 
9870
     fork
9871
     begin
9872
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9873
                 read_address,
9874 15 mihad
                 data, ~byte_enables,
9875
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9876
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9877 45 mihad
         do_pause(1) ;
9878
     end
9879
     begin
9880
         @(master1_received_data_valid) ;
9881
         data = master1_received_data ;
9882
     end
9883
     join
9884 15 mihad
 
9885 45 mihad
    master1_check_received_data = master_check_data_prev ;
9886
`endif
9887
`endif
9888
 
9889 15 mihad
    in_use = 0 ;
9890
 
9891 45 mihad
end //main
9892
endtask // configuration_cycle_read
9893
 
9894 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9895
task test_conf_cycle_type1_reference ;
9896
    reg [31:0] address ;
9897
    reg in_use ;
9898
 
9899
    reg master_check_data_prev ;
9900
    reg [31:0] data ;
9901
    reg monitor_ok ;
9902
    reg master_ok ;
9903
begin:main
9904
 
9905
    if ( in_use === 1 )
9906
    begin
9907
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9908
        disable main ;
9909
    end
9910
 
9911
    in_use = 1 ;
9912
 
9913
    master_check_data_prev = master1_check_received_data ;
9914
 
9915
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9916
    address = `TAR0_IDSEL_ADDR ;
9917
 
9918
    address[1:0] = 2'b01 ;
9919
 
9920
    `ifdef HOST
9921
        conf_cyc_type1_target_bus_num = 255 ;
9922
    `endif
9923
    master_ok = 1 ;
9924
    fork
9925
    begin
9926
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9927
        do_pause(1) ;
9928
    end
9929
    begin:error_monitor1
9930
        @(error_event_int) ;
9931
        master_ok = 0 ;
9932
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9933
    end
9934
    begin
9935
        pci_transaction_progress_monitor
9936
        (
9937
            address,                                                // expected address on PCI bus
9938
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9939
            0,                                                      // expected number of succesfull data phases
9940
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9941
            1'b1,                                                   // monitor checking/not checking number of transfers
9942
            1'b0,                                                   // monitor checking/not checking number of cycles
9943
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9944
            monitor_ok                                              // status - 1 success, 0 failure
9945
        ) ;
9946
 
9947
        @(posedge pci_clock);
9948
        #1 ;
9949
 
9950
        if (master_ok)
9951
            disable error_monitor1 ;
9952
 
9953
        if (!monitor_ok)
9954
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9955
    end
9956
    join
9957
 
9958
    if (monitor_ok && master_ok)
9959
        test_ok ;
9960
 
9961
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9962
    master_ok = 1 ;
9963
    fork
9964
    begin
9965
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9966
        do_pause(1) ;
9967
    end
9968
    begin:error_monitor2
9969
        @(error_event_int) ;
9970
        master_ok = 0 ;
9971
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9972
    end
9973
    begin
9974
        pci_transaction_progress_monitor
9975
        (
9976
            address,                                                // expected address on PCI bus
9977
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9978
            0,                                                      // expected number of succesfull data phases
9979
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9980
            1'b1,                                                   // monitor checking/not checking number of transfers
9981
            1'b0,                                                   // monitor checking/not checking number of cycles
9982
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9983
            monitor_ok                                              // status - 1 success, 0 failure
9984
        ) ;
9985
 
9986
        @(posedge pci_clock);
9987
        #1 ;
9988
 
9989
        if (master_ok)
9990
            disable error_monitor2 ;
9991
 
9992
        if (!monitor_ok)
9993
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9994
    end
9995
    join
9996
 
9997
    master1_check_received_data = master_check_data_prev ;
9998
 
9999
    if (monitor_ok && master_ok)
10000
        test_ok ;
10001
 
10002
    in_use = 0 ;
10003
 
10004
end //main
10005
endtask // test_conf_cycle_type1_reference
10006
`endif
10007
 
10008 45 mihad
`ifdef HOST
10009
task generate_configuration_cycle ;
10010 15 mihad
    input [7:0]  bus_num ;
10011
    input [4:0]  device_num ;
10012
    input [2:0]  func_num ;
10013
    input [5:0]  reg_num ;
10014
    input [1:0]  type ;
10015
    input [3:0]  byte_enables ;
10016 45 mihad
    inout [31:0] data ;
10017
    input        read0_write1 ;
10018 15 mihad
 
10019
    reg `READ_STIM_TYPE read_data ;
10020
    reg `WB_TRANSFER_FLAGS  flags ;
10021
    reg `READ_RETURN_TYPE   read_status ;
10022
 
10023
    reg `WRITE_STIM_TYPE   write_data ;
10024
    reg `WRITE_RETURN_TYPE write_status ;
10025
 
10026 45 mihad
    reg [31:0] pci_address ;
10027 15 mihad
    reg in_use ;
10028 45 mihad
    reg ok ;
10029 15 mihad
 
10030
    reg [31:0] temp_var ;
10031
begin:main
10032
 
10033
    if ( in_use === 1 )
10034
    begin
10035 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10036 15 mihad
        data = 32'hxxxx_xxxx ;
10037
        disable main ;
10038
    end
10039
 
10040 45 mihad
    in_use = 1 ;
10041
 
10042
    if ( type )
10043
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10044
    else
10045 15 mihad
    begin
10046 45 mihad
        pci_address = 0 ;
10047
        pci_address[10:0] = { func_num, reg_num, type } ;
10048
        if (device_num <= 20)
10049
            pci_address[11 + device_num] = 1'b1 ;
10050
    end
10051
 
10052
    // setup flags
10053
    flags = 0 ;
10054
    flags`INIT_WAITS   = tb_init_waits ;
10055
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10056
 
10057
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10058
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10059
 
10060
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10061
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10062
    write_data`WRITE_SEL      = 4'hF ;
10063
    write_data`WRITE_TAG_STIM = 0 ;
10064
 
10065
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10066
 
10067
    // check if write succeeded
10068
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10069
    begin
10070
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10071 15 mihad
        data = 32'hxxxx_xxxx ;
10072 45 mihad
        in_use = 0 ;
10073 15 mihad
        disable main ;
10074
    end
10075
 
10076 45 mihad
    // setup flags for wb master to handle retries and read and write data
10077
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10078
 
10079
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10080
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10081
    read_data`READ_SEL          = byte_enables ;
10082
    write_data`WRITE_SEL        = byte_enables ;
10083
    read_data`READ_TAG_STIM     = 0 ;
10084
    write_data`WRITE_TAG_STIM   = 0 ;
10085
    write_data`WRITE_DATA       = data ;
10086
 
10087
    ok = 0 ;
10088
 
10089
    fork
10090
    begin
10091
        if (read0_write1 === 0)
10092
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10093
        else
10094
        if (read0_write1 === 1)
10095
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10096
    end
10097
    begin
10098
        pci_transaction_progress_monitor
10099
        (
10100
            pci_address,                                            // expected address on PCI bus
10101
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10102
            1,                                                      // expected number of succesfull data phases
10103
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10104
            1'b0,                                                   // monitor checking/not checking number of transfers
10105
            1'b0,                                                   // monitor checking/not checking number of cycles
10106
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10107
            ok                                                      // status - 1 success, 0 failure
10108
        ) ;
10109
    end
10110
    join
10111
 
10112
    // check if transfer succeeded
10113
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10114
    begin
10115
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10116
        data = 32'hxxxx_xxxx ;
10117
        in_use = 0 ;
10118
        disable main ;
10119
    end
10120
 
10121
    if (!ok)
10122
    begin
10123
        data = 32'hxxxx_xxxx ;
10124
        in_use = 0 ;
10125
        disable main ;
10126
    end
10127
 
10128
    if (read0_write1 === 0)
10129
        data = read_status`READ_DATA ;
10130
 
10131
    in_use = 0 ;
10132
end
10133
endtask // generate_configuration_cycle
10134
 
10135
task test_configuration_cycle_target_abort ;
10136
    reg `READ_STIM_TYPE read_data ;
10137
    reg `WB_TRANSFER_FLAGS  flags ;
10138
    reg `READ_RETURN_TYPE   read_status ;
10139
 
10140
    reg `WRITE_STIM_TYPE   write_data ;
10141
    reg `WRITE_RETURN_TYPE write_status ;
10142
 
10143
    reg [31:0] pci_address ;
10144
    reg in_use ;
10145
    reg ok_pci ;
10146
    reg ok_wb  ;
10147
    reg ok     ;
10148
 
10149
    reg [31:0] temp_var ;
10150
 
10151
begin:main
10152
 
10153
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10154
 
10155
    if ( in_use === 1 )
10156
    begin
10157
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10158
        disable main ;
10159
    end
10160
 
10161 15 mihad
    in_use = 1 ;
10162
 
10163 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10164
 
10165 15 mihad
    // setup flags
10166
    flags = 0 ;
10167 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10168
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10169 15 mihad
 
10170
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10171
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10172
 
10173
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10174 45 mihad
    temp_var                  = 0 ;
10175
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10176
    write_data`WRITE_DATA     = temp_var ;
10177 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10178
    write_data`WRITE_TAG_STIM = 0 ;
10179
 
10180
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10181
 
10182
    // check if write succeeded
10183
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10184
    begin
10185
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10186 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10187
        in_use = 0 ;
10188 15 mihad
        disable main ;
10189
    end
10190
 
10191 45 mihad
    // setup flags for wb master to handle retries and read and write data
10192 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10193
 
10194 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10195
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10196 15 mihad
 
10197 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10198
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10199
    read_data`READ_SEL          = 4'hF ;
10200
    write_data`WRITE_SEL        = 4'hF ;
10201
    read_data`READ_TAG_STIM     = 0 ;
10202
    write_data`WRITE_TAG_STIM   = 0 ;
10203
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10204
 
10205
    ok_pci = 0 ;
10206
    ok_wb  = 1 ;
10207
 
10208
    // set target to terminate with target abort
10209
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10210
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10211
    fork
10212
    begin
10213
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10214
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10215
        begin
10216
            $display("Time %t", $time) ;
10217
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10218
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10219
            ok_wb = 0 ;
10220
        end
10221
 
10222
        config_read( 12'h4, 4'hF, temp_var ) ;
10223
        if ( temp_var[29] !== 0 )
10224
        begin
10225
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10226
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10227
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10228
            ok_wb = 0 ;
10229
        end
10230
 
10231
        if ( temp_var[28] !== 1 )
10232
        begin
10233
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10234
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10235
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10236
            ok_wb = 0 ;
10237
        end
10238
 
10239
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10240
 
10241
        if (ok !== 1)
10242
        begin
10243
            ok_wb = 0 ;
10244
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10245
            $display("Write to PCI Device Status Register failed") ;
10246
            test_fail("Write to PCI Device Status Register failed") ;
10247
        end
10248
 
10249
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10250
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10251
        begin
10252
            $display("Time %t", $time) ;
10253
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10254
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10255
            ok_wb = 0 ;
10256
        end
10257
 
10258
        config_read( 12'h4, 4'hF, temp_var ) ;
10259
        if ( temp_var[29] !== 0 )
10260
        begin
10261
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10262
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10263
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10264
            ok_wb = 0 ;
10265
        end
10266
 
10267
        if ( temp_var[28] !== 1 )
10268
        begin
10269
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10270
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10271
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10272
            ok_wb = 0 ;
10273
        end
10274
 
10275
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10276
 
10277
        if (ok !== 1)
10278
        begin
10279
            ok_wb = 0 ;
10280
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10281
            $display("Write to PCI Device Status Register failed") ;
10282
            test_fail("Write to PCI Device Status Register failed") ;
10283
        end
10284
    end
10285
    begin
10286
        pci_transaction_progress_monitor
10287
        (
10288
            pci_address,                                            // expected address on PCI bus
10289
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10290
            0,                                                      // expected number of succesfull data phases
10291
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10292
            1'b1,                                                   // monitor checking/not checking number of transfers
10293
            1'b0,                                                   // monitor checking/not checking number of cycles
10294
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10295
            ok_pci                                                  // status - 1 success, 0 failure
10296
        ) ;
10297
 
10298
        if (ok_pci)
10299
        begin
10300
            pci_transaction_progress_monitor
10301
            (
10302
                pci_address,                                            // expected address on PCI bus
10303
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10304
                0,                                                      // expected number of succesfull data phases
10305
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10306
                1'b1,                                                   // monitor checking/not checking number of transfers
10307
                1'b0,                                                   // monitor checking/not checking number of cycles
10308
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10309
                ok_pci                                                  // status - 1 success, 0 failure
10310
            ) ;
10311
        end
10312
 
10313
        if (!ok_pci)
10314
        begin
10315
            $display("Time %t", $time) ;
10316
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10317
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10318
        end
10319
    end
10320
    join
10321
 
10322
    if (ok_pci && ok_wb)
10323
    begin
10324
        test_ok ;
10325
    end
10326
 
10327
    in_use = 0 ;
10328
 
10329
    // set target to terminate normally
10330
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10331
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10332
end
10333
endtask // test_configuration_cycle_target_abort
10334
 
10335
task test_configuration_cycle_type1_generation ;
10336
    reg `READ_STIM_TYPE read_data ;
10337
    reg `WB_TRANSFER_FLAGS  flags ;
10338
    reg `READ_RETURN_TYPE   read_status ;
10339
 
10340
    reg `WRITE_STIM_TYPE   write_data ;
10341
    reg `WRITE_RETURN_TYPE write_status ;
10342
 
10343
    reg [31:0] pci_address ;
10344
    reg in_use ;
10345
    reg ok_pci ;
10346
    reg ok_wb  ;
10347
    reg ok     ;
10348
 
10349
    reg [31:0] temp_var ;
10350
 
10351
begin:main
10352
 
10353
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10354
    conf_cyc_type1_target_data = 0 ;
10355
    conf_cyc_type1_target_bus_num = 0;
10356
 
10357
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10358
 
10359
    if ( in_use === 1 )
10360
    begin
10361
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10362
        disable main ;
10363
    end
10364
 
10365
    in_use = 1 ;
10366
 
10367
    pci_address        = 32'hAAAA_AAAA ;
10368
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10369
 
10370
    // setup flags
10371
    flags = 0 ;
10372
    flags`INIT_WAITS   = tb_init_waits ;
10373
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10374
 
10375
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10376
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10377
 
10378
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10379
    write_data`WRITE_DATA     = pci_address ;
10380
    write_data`WRITE_SEL      = 4'hF ;
10381
    write_data`WRITE_TAG_STIM = 0 ;
10382
 
10383
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10384
 
10385
    // check if write succeeded
10386
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10387
    begin
10388
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10389
        test_fail("write to configuration cycle address register was not possible") ;
10390
        in_use = 0 ;
10391
        disable main ;
10392
    end
10393
 
10394
    // setup flags for wb master to handle retries and read and write data
10395
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10396
 
10397
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10398
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10399
 
10400
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10401
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10402
    read_data`READ_SEL          = 4'hF ;
10403
    write_data`WRITE_SEL        = 4'hF ;
10404
    read_data`READ_TAG_STIM     = 0 ;
10405
    write_data`WRITE_TAG_STIM   = 0 ;
10406
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10407
 
10408
    ok_pci = 0 ;
10409
    ok_wb  = 1 ;
10410
 
10411
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10412
    pci_address[31:24] = 0 ;
10413
    fork
10414
    begin
10415
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10416
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10417
        begin
10418
            $display("Time %t", $time) ;
10419
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10420
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10421
            ok_wb = 0 ;
10422
        end
10423
 
10424
        config_read( 12'h4, 4'hF, temp_var ) ;
10425
        if ( temp_var[29] !== 1 )
10426
        begin
10427
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10428
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10429
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10430
            ok_wb = 0 ;
10431
        end
10432
 
10433
        if ( temp_var[28] !== 0 )
10434
        begin
10435
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10436
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10437
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10438
            ok_wb = 0 ;
10439
        end
10440
 
10441
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10442
 
10443
        if (ok !== 1)
10444
        begin
10445
            ok_wb = 0 ;
10446
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10447
            $display("Write to PCI Device Status Register failed") ;
10448
            test_fail("Write to PCI Device Status Register failed") ;
10449
        end
10450
 
10451
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10452
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10453
        begin
10454
            $display("Time %t", $time) ;
10455
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10456
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10457
            ok_wb = 0 ;
10458
        end
10459
 
10460
        config_read( 12'h4, 4'hF, temp_var ) ;
10461
        if ( temp_var[29] !== 1 )
10462
        begin
10463
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10464
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10465
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10466
            ok_wb = 0 ;
10467
        end
10468
 
10469
        if ( temp_var[28] !== 0 )
10470
        begin
10471
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10472
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10473
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10474
            ok_wb = 0 ;
10475
        end
10476
 
10477
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10478
 
10479
        if (ok !== 1)
10480
        begin
10481
            ok_wb = 0 ;
10482
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10483
            $display("Write to PCI Device Status Register failed") ;
10484
            test_fail("Write to PCI Device Status Register failed") ;
10485
        end
10486
    end
10487
    begin
10488
        pci_transaction_progress_monitor
10489
        (
10490
            pci_address,                                            // expected address on PCI bus
10491
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10492
            0,                                                      // expected number of succesfull data phases
10493
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10494
            1'b1,                                                   // monitor checking/not checking number of transfers
10495
            1'b0,                                                   // monitor checking/not checking number of cycles
10496
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10497
            ok_pci                                                  // status - 1 success, 0 failure
10498
        ) ;
10499
 
10500
        if (ok_pci)
10501
        begin
10502
            pci_transaction_progress_monitor
10503
            (
10504
                pci_address,                                            // expected address on PCI bus
10505
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10506
                0,                                                      // expected number of succesfull data phases
10507
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10508
                1'b1,                                                   // monitor checking/not checking number of transfers
10509
                1'b0,                                                   // monitor checking/not checking number of cycles
10510
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10511
                ok_pci                                                  // status - 1 success, 0 failure
10512
            ) ;
10513
        end
10514
 
10515
        if (!ok_pci)
10516
        begin
10517
            $display("Time %t", $time) ;
10518
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10519
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10520
        end
10521
    end
10522
    join
10523
 
10524
    if (ok_pci && ok_wb)
10525
    begin
10526
        test_ok ;
10527
    end
10528
 
10529
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10530
    conf_cyc_type1_target_data = 0 ;
10531
    conf_cyc_type1_target_bus_num = 8'h55;
10532
 
10533
    pci_address      = 32'h5555_5555 ;
10534
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10535
 
10536
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10537
 
10538
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10539
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10540
 
10541
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10542
    write_data`WRITE_DATA     = pci_address ;
10543
    write_data`WRITE_SEL      = 4'hF ;
10544
    write_data`WRITE_TAG_STIM = 0 ;
10545
 
10546
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10547
 
10548
    // check if write succeeded
10549
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10550
    begin
10551
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10552
        test_fail("write to configuration cycle address register was not possible") ;
10553
        in_use = 0 ;
10554
        disable main ;
10555
    end
10556
 
10557
    // setup flags for wb master to handle retries and read and write data
10558
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10559
 
10560
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10561
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10562
 
10563
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10564
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10565
    read_data`READ_SEL          = 4'hF ;
10566
    write_data`WRITE_SEL        = 4'hF ;
10567
    read_data`READ_TAG_STIM     = 0 ;
10568
    write_data`WRITE_TAG_STIM   = 0 ;
10569
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10570
 
10571
    ok_pci = 0 ;
10572
    ok_wb  = 1 ;
10573
 
10574
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10575
    pci_address[31:24] = 0 ;
10576
    fork
10577
    begin
10578
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10579
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10580
        begin
10581
            $display("Time %t", $time) ;
10582
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10583
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10584
            ok_wb = 0 ;
10585
        end
10586
 
10587
        config_read( 12'h4, 4'hF, temp_var ) ;
10588
        if ( temp_var[29] !== 0 )
10589
        begin
10590
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10591
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10592
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10593
            ok_wb = 0 ;
10594
        end
10595
 
10596
        if ( temp_var[28] !== 1 )
10597
        begin
10598
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10599
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10600
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10601
            ok_wb = 0 ;
10602
        end
10603
 
10604
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10605
 
10606
        if (ok !== 1)
10607
        begin
10608
            ok_wb = 0 ;
10609
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10610
            $display("Write to PCI Device Status Register failed") ;
10611
            test_fail("Write to PCI Device Status Register failed") ;
10612
        end
10613
 
10614
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10615
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10616
        begin
10617
            $display("Time %t", $time) ;
10618
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10619
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10620
            ok_wb = 0 ;
10621
        end
10622
 
10623
        config_read( 12'h4, 4'hF, temp_var ) ;
10624
        if ( temp_var[29] !== 0 )
10625
        begin
10626
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10627
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10628
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10629
            ok_wb = 0 ;
10630
        end
10631
 
10632
        if ( temp_var[28] !== 1 )
10633
        begin
10634
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10635
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10636
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10637
            ok_wb = 0 ;
10638
        end
10639
 
10640
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10641
 
10642
        if (ok !== 1)
10643
        begin
10644
            ok_wb = 0 ;
10645
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10646
            $display("Write to PCI Device Status Register failed") ;
10647
            test_fail("Write to PCI Device Status Register failed") ;
10648
        end
10649
    end
10650
    begin
10651
        pci_transaction_progress_monitor
10652
        (
10653
            pci_address,                                            // expected address on PCI bus
10654
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10655
            0,                                                      // expected number of succesfull data phases
10656
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10657
            1'b1,                                                   // monitor checking/not checking number of transfers
10658
            1'b0,                                                   // monitor checking/not checking number of cycles
10659
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10660
            ok_pci                                                  // status - 1 success, 0 failure
10661
        ) ;
10662
 
10663
        if (ok_pci)
10664
        begin
10665
            pci_transaction_progress_monitor
10666
            (
10667
                pci_address,                                            // expected address on PCI bus
10668
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10669
                0,                                                      // expected number of succesfull data phases
10670
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10671
                1'b1,                                                   // monitor checking/not checking number of transfers
10672
                1'b0,                                                   // monitor checking/not checking number of cycles
10673
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10674
                ok_pci                                                  // status - 1 success, 0 failure
10675
            ) ;
10676
        end
10677
 
10678
        if (!ok_pci)
10679
        begin
10680
            $display("Time %t", $time) ;
10681
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10682
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10683
        end
10684
    end
10685
    join
10686
 
10687
    if (ok_pci && ok_wb)
10688
    begin
10689
        test_ok ;
10690
    end
10691
 
10692
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10693
 
10694
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10695
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10696
    conf_cyc_type1_target_bus_num = 8'hAA;
10697
 
10698
    pci_address      = 32'hAAAA_AAAA ;
10699
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10700
 
10701
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10702
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10703
 
10704
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10705
    write_data`WRITE_DATA     = pci_address ;
10706
    write_data`WRITE_SEL      = 4'hF ;
10707
    write_data`WRITE_TAG_STIM = 0 ;
10708
 
10709
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10710
 
10711
    // check if write succeeded
10712
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10713
    begin
10714
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10715
        test_fail("write to configuration cycle address register was not possible") ;
10716
        in_use = 0 ;
10717
        disable main ;
10718
    end
10719
 
10720
    // setup flags for wb master to handle retries and read and write data
10721
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10722
 
10723
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10724
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10725
 
10726
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10727
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10728
    read_data`READ_SEL          = 4'b0101 ;
10729
    write_data`WRITE_SEL        = 4'b1010 ;
10730
    read_data`READ_TAG_STIM     = 0 ;
10731
    write_data`WRITE_TAG_STIM   = 0 ;
10732
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10733
 
10734
    ok_pci = 0 ;
10735
    ok_wb  = 1 ;
10736
 
10737
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10738
    pci_address[31:24] = 0 ;
10739
 
10740
    fork
10741
    begin
10742
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10743
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10744
        begin
10745
            $display("Time %t", $time) ;
10746
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10747
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10748
            ok_wb = 0 ;
10749
        end
10750
 
10751
        config_read( 12'h4, 4'hF, temp_var ) ;
10752
        if ( temp_var[29] !== 0 )
10753
        begin
10754
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10755
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10756
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10757
            ok_wb = 0 ;
10758
        end
10759
 
10760
        if ( temp_var[28] !== 0 )
10761
        begin
10762
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10763
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10764
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10765
            ok_wb = 0 ;
10766
        end
10767
 
10768
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10769
 
10770
        if (ok !== 1)
10771
        begin
10772
            ok_wb = 0 ;
10773
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10774
            $display("Write to PCI Device Status Register failed") ;
10775
            test_fail("Write to PCI Device Status Register failed") ;
10776
        end
10777
 
10778
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10779
        begin
10780
            ok_wb = 0 ;
10781
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10782
            $display("Read Data provided by the bridge was not as expected!") ;
10783
            test_fail("Read Data provided by the bridge was not as expected") ;
10784
        end
10785
 
10786
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10787
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10788
        begin
10789
            $display("Time %t", $time) ;
10790
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10791
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10792
            ok_wb = 0 ;
10793
        end
10794
 
10795
        config_read( 12'h4, 4'hF, temp_var ) ;
10796
        if ( temp_var[29] !== 0 )
10797
        begin
10798
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10799
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10800
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10801
            ok_wb = 0 ;
10802
        end
10803
 
10804
        if ( temp_var[28] !== 0 )
10805
        begin
10806
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10807
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10808
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10809
            ok_wb = 0 ;
10810
        end
10811
 
10812
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10813
 
10814
        if (ok !== 1)
10815
        begin
10816
            ok_wb = 0 ;
10817
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10818
            $display("Write to PCI Device Status Register failed") ;
10819
            test_fail("Write to PCI Device Status Register failed") ;
10820
        end
10821
 
10822
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10823
        begin
10824
            ok_wb = 0 ;
10825
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10826
            $display("Data written by the bridge was not as expected!") ;
10827
            test_fail("Data written by the bridge was not as expected") ;
10828
        end
10829
 
10830
    end
10831
    begin
10832
        ok = 1 ;
10833
        repeat(8)
10834
        begin
10835
            pci_transaction_progress_monitor
10836
            (
10837
                pci_address,                                            // expected address on PCI bus
10838
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10839
                0,                                                      // expected number of succesfull data phases
10840
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10841
                1'b1,                                                   // monitor checking/not checking number of transfers
10842
                1'b0,                                                   // monitor checking/not checking number of cycles
10843
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10844
                ok_pci                                                  // status - 1 success, 0 failure
10845
            ) ;
10846
 
10847
            if (!ok_pci)
10848
            begin
10849
                ok = 0 ;
10850
                $display("Time %t", $time) ;
10851
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10852
            end
10853
        end
10854
 
10855
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10856
 
10857
        pci_transaction_progress_monitor
10858
        (
10859
            pci_address,                                            // expected address on PCI bus
10860
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10861
            1,                                                      // expected number of succesfull data phases
10862
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10863
            1'b1,                                                   // monitor checking/not checking number of transfers
10864
            1'b0,                                                   // monitor checking/not checking number of cycles
10865
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10866
            ok_pci                                                  // status - 1 success, 0 failure
10867
        ) ;
10868
 
10869
        if (!ok_pci)
10870
        begin
10871
            ok = 0 ;
10872
            $display("Time %t", $time) ;
10873
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10874
        end
10875
 
10876
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10877
        repeat(8)
10878
        begin
10879
            pci_transaction_progress_monitor
10880
            (
10881
                pci_address,                                            // expected address on PCI bus
10882
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10883
                0,                                                      // expected number of succesfull data phases
10884
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10885
                1'b1,                                                   // monitor checking/not checking number of transfers
10886
                1'b0,                                                   // monitor checking/not checking number of cycles
10887
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10888
                ok_pci                                                  // status - 1 success, 0 failure
10889
            ) ;
10890
 
10891
            if (!ok_pci)
10892
            begin
10893
                ok = 0 ;
10894
                $display("Time %t", $time) ;
10895
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10896
            end
10897
        end
10898
 
10899
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10900
        pci_transaction_progress_monitor
10901
        (
10902
            pci_address,                                            // expected address on PCI bus
10903
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10904
            1,                                                      // expected number of succesfull data phases
10905
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10906
            1'b1,                                                   // monitor checking/not checking number of transfers
10907
            1'b0,                                                   // monitor checking/not checking number of cycles
10908
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10909
            ok_pci                                                  // status - 1 success, 0 failure
10910
        ) ;
10911
 
10912
        if (!ok_pci)
10913
        begin
10914
            ok = 0 ;
10915
            $display("Time %t", $time) ;
10916
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10917
        end
10918
 
10919
        if (!ok)
10920
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10921
    end
10922
    join
10923
 
10924
    if (ok_pci && ok_wb)
10925
    begin
10926
        test_ok ;
10927
    end
10928
 
10929
    in_use = 0 ;
10930
end
10931
endtask // test_configuration_cycle_type1_generation
10932
`endif
10933
 
10934
task test_initial_conf_values ;
10935
    reg [11:0] register_offset ;
10936
    reg [31:0] expected_value ;
10937
    reg        failed ;
10938
`ifdef HOST
10939
    reg `READ_STIM_TYPE    read_data ;
10940
    reg `WB_TRANSFER_FLAGS flags ;
10941
    reg `READ_RETURN_TYPE  read_status ;
10942
 
10943
    reg `WRITE_STIM_TYPE   write_data ;
10944
    reg `WRITE_RETURN_TYPE write_status ;
10945
begin
10946
    failed     = 0 ;
10947
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10948
    flags      = 0 ;
10949
    read_data  = 0 ;
10950
    write_data = 0 ;
10951
 
10952
    read_data`READ_SEL = 4'hF ;
10953
 
10954
    flags`INIT_WAITS           = tb_init_waits ;
10955
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10956
 
10957
    // test MEM/IO map bit initial value in each PCI BAR
10958
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10959
 
10960
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10961
 
10962 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10963
 
10964 45 mihad
    `ifdef NO_CNF_IMAGE
10965
        `ifdef PCI_IMAGE0
10966
            if (`PCI_AM0)
10967
                expected_value = `PCI_BA0_MEM_IO ;
10968
            else
10969
                expected_value = 32'h0000_0000 ;
10970
        `else
10971
            expected_value = 32'h0000_0000 ;
10972
        `endif
10973
    `else
10974
        expected_value = 32'h0000_0000 ;
10975
    `endif
10976
 
10977 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10978
    begin
10979 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10980
        failed = 1 ;
10981 15 mihad
    end
10982 45 mihad
    else
10983
    begin
10984
        if (read_status`READ_DATA !== expected_value)
10985
        begin
10986
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10987
            failed = 1 ;
10988
        end
10989
    end
10990 15 mihad
 
10991 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10992 15 mihad
 
10993 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10994
 
10995
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10996
 
10997
    if (`PCI_AM1)
10998
        expected_value = `PCI_BA1_MEM_IO ;
10999
    else
11000
        expected_value = 32'h0000_0000 ;
11001
 
11002
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11003
    begin
11004
        test_fail("read from P_BA1 register didn't succeede") ;
11005
        failed = 1 ;
11006
    end
11007
    else
11008
    begin
11009
        if (read_status`READ_DATA !== expected_value)
11010
        begin
11011
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11012
            failed = 1 ;
11013
        end
11014
    end
11015
 
11016
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11017
 
11018
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11019
 
11020
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11021
 
11022
    `ifdef PCI_IMAGE2
11023
        if (`PCI_AM2)
11024
            expected_value = `PCI_BA2_MEM_IO ;
11025
        else
11026
            expected_value = 32'h0000_0000 ;
11027 15 mihad
    `else
11028 45 mihad
        expected_value = 32'h0000_0000 ;
11029
    `endif
11030 15 mihad
 
11031 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11032
    begin
11033
        test_fail("read from P_BA2 register didn't succeede") ;
11034
        failed = 1 ;
11035
    end
11036
    else
11037
    begin
11038
        if (read_status`READ_DATA !== expected_value)
11039
        begin
11040
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11041
            failed = 1 ;
11042
        end
11043
    end
11044 15 mihad
 
11045 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11046
 
11047
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11048
 
11049
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11050
 
11051
    `ifdef PCI_IMAGE3
11052
        if (`PCI_AM3)
11053
            expected_value = `PCI_BA3_MEM_IO ;
11054
        else
11055
            expected_value = 32'h0000_0000 ;
11056
    `else
11057
        expected_value = 32'h0000_0000 ;
11058 15 mihad
    `endif
11059 45 mihad
 
11060
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11061
    begin
11062
        test_fail("read from P_BA3 register didn't succeede") ;
11063
        failed = 1 ;
11064
    end
11065
    else
11066
    begin
11067
        if (read_status`READ_DATA !== expected_value)
11068
        begin
11069
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11070
            failed = 1 ;
11071
        end
11072
    end
11073
 
11074
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11075
 
11076
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11077
 
11078
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11079
 
11080
    `ifdef PCI_IMAGE4
11081
        if (`PCI_AM4)
11082
            expected_value = `PCI_BA4_MEM_IO ;
11083
        else
11084
            expected_value = 32'h0000_0000 ;
11085
    `else
11086
        expected_value = 32'h0000_0000 ;
11087 15 mihad
    `endif
11088
 
11089 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11090
    begin
11091
        test_fail("read from P_BA4 register didn't succeede") ;
11092
        failed = 1 ;
11093
    end
11094
    else
11095
    begin
11096
        if (read_status`READ_DATA !== expected_value)
11097
        begin
11098
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11099
            failed = 1 ;
11100
        end
11101
    end
11102 15 mihad
 
11103 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11104 15 mihad
 
11105 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11106
 
11107
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11108
 
11109
    `ifdef PCI_IMAGE5
11110
        if(`PCI_AM5)
11111
            expected_value = `PCI_BA5_MEM_IO ;
11112
        else
11113
            expected_value = 32'h0000_0000 ;
11114
    `else
11115
        expected_value = 32'h0000_0000 ;
11116
    `endif
11117
 
11118
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11119
    begin
11120
        test_fail("read from P_BA5 register didn't succeede") ;
11121
        failed = 1 ;
11122
    end
11123
    else
11124
    begin
11125
        if (read_status`READ_DATA !== expected_value)
11126
        begin
11127
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11128
            failed = 1 ;
11129
        end
11130
    end
11131
 
11132
    // test Address Mask initial values
11133
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11134
 
11135
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11136
 
11137
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11138
 
11139
    `ifdef NO_CNF_IMAGE
11140
        `ifdef PCI_IMAGE0
11141
            expected_value = {`PCI_AM0, 12'h000};
11142
 
11143
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11144
        `else
11145
            expected_value = 32'h0000_0000 ;
11146
        `endif
11147
    `else
11148
        expected_value = 32'hFFFF_FFFF ;
11149
 
11150
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11151
    `endif
11152
 
11153
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11154
    begin
11155
        test_fail("read from P_AM0 register didn't succeede") ;
11156
        failed = 1 ;
11157
    end
11158
    else
11159
    begin
11160
        if (read_status`READ_DATA !== expected_value)
11161
        begin
11162
            test_fail("AM0 initial value was not set as defined");
11163
            failed = 1 ;
11164
        end
11165
    end
11166
 
11167
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11168
 
11169
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11170
 
11171
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11172
 
11173
    expected_value = {`PCI_AM1, 12'h000};
11174
 
11175
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11176
 
11177
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11178
    begin
11179
        test_fail("read from P_AM1 register didn't succeede") ;
11180
        failed = 1 ;
11181
    end
11182
    else
11183
    begin
11184
        if (read_status`READ_DATA !== expected_value)
11185
        begin
11186
            test_fail("AM1 initial value was not set as defined");
11187
            failed = 1 ;
11188
        end
11189
    end
11190
 
11191
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11192
 
11193
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11194
 
11195
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11196
 
11197
    `ifdef PCI_IMAGE2
11198
        expected_value = {`PCI_AM2, 12'h000};
11199
 
11200
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11201
    `else
11202
        expected_value = 32'h0000_0000 ;
11203
    `endif
11204
 
11205
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11206
    begin
11207
        test_fail("read from P_AM2 register didn't succeede") ;
11208
        failed = 1 ;
11209
    end
11210
    else
11211
    begin
11212
        if (read_status`READ_DATA !== expected_value)
11213
        begin
11214
            test_fail("AM2 initial value was not set as defined");
11215
            failed = 1 ;
11216
        end
11217
    end
11218
 
11219
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11220
 
11221
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11222
 
11223
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11224
 
11225
    `ifdef PCI_IMAGE3
11226
        expected_value = {`PCI_AM3, 12'h000};
11227
 
11228
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11229
    `else
11230
        expected_value = 32'h0000_0000 ;
11231
    `endif
11232
 
11233
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11234
    begin
11235
        test_fail("read from P_AM3 register didn't succeede") ;
11236
        failed = 1 ;
11237
    end
11238
    else
11239
    begin
11240
        if (read_status`READ_DATA !== expected_value)
11241
        begin
11242
            test_fail("AM3 initial value was not set as defined");
11243
            failed = 1 ;
11244
        end
11245
    end
11246
 
11247
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11248
 
11249
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11250
 
11251
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11252
 
11253
    `ifdef PCI_IMAGE4
11254
        expected_value = {`PCI_AM4, 12'h000};
11255
 
11256
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11257
    `else
11258
        expected_value = 32'h0000_0000 ;
11259
    `endif
11260
 
11261
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11262
    begin
11263
        test_fail("read from P_AM4 register didn't succeede") ;
11264
        failed = 1 ;
11265
    end
11266
    else
11267
    begin
11268
        if (read_status`READ_DATA !== expected_value)
11269
        begin
11270
            test_fail("AM4 initial value was not set as defined");
11271
            failed = 1 ;
11272
        end
11273
    end
11274
 
11275
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11276
 
11277
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11278
 
11279
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11280
 
11281
    `ifdef PCI_IMAGE5
11282
        expected_value = {`PCI_AM5, 12'h000};
11283
 
11284
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11285
    `else
11286
        expected_value = 32'h0000_0000 ;
11287
    `endif
11288
 
11289
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11290
    begin
11291
        test_fail("read from P_AM5 register didn't succeede") ;
11292
        failed = 1 ;
11293
    end
11294
    else
11295
    begin
11296
        if (read_status`READ_DATA !== expected_value)
11297
        begin
11298
            test_fail("AM5 initial value was not set as defined");
11299
            failed = 1 ;
11300
        end
11301
    end
11302
 
11303
`endif
11304
 
11305
`ifdef GUEST
11306
    reg [31:0] read_data ;
11307
begin
11308
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11309
    failed    = 0 ;
11310
 
11311
    // check all images' BARs
11312
 
11313
    // BAR0
11314
    configuration_cycle_read
11315
    (
11316
        8'h00,                          // bus number [7:0]
11317
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11318
        3'h0,                           // function number [2:0]
11319
        6'h4,                           // register number [5:0]
11320
        2'h0,                           // type [1:0]
11321
        4'hF,                           // byte enables [3:0]
11322
        read_data                       // data returned from configuration read [31:0]
11323
    ) ;
11324
 
11325
    expected_value = 32'h0000_0000 ;
11326
 
11327
    if( read_data !== expected_value)
11328
    begin
11329
        test_fail("initial value of BAR0 register not as expected") ;
11330
        failed = 1 ;
11331
    end
11332
 
11333
    // BAR1
11334
    configuration_cycle_read
11335
    (
11336
        8'h00,                          // bus number [7:0]
11337
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11338
        3'h0,                           // function number [2:0]
11339
        6'h5,                           // register number [5:0]
11340
        2'h0,                           // type [1:0]
11341
        4'hF,                           // byte enables [3:0]
11342
        read_data                       // data returned from configuration read [31:0]
11343
    ) ;
11344
 
11345
    if (`PCI_AM1)
11346
        expected_value = `PCI_BA1_MEM_IO ;
11347
    else
11348
        expected_value = 32'h0000_0000 ;
11349
 
11350
    if( read_data !== expected_value)
11351
    begin
11352
        test_fail("initial value of BAR1 register not as expected") ;
11353
        failed = 1 ;
11354
    end
11355
 
11356
    // BAR2
11357
    configuration_cycle_read
11358
    (
11359
        8'h00,                          // bus number [7:0]
11360
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11361
        3'h0,                           // function number [2:0]
11362
        6'h6,                           // register number [5:0]
11363
        2'h0,                           // type [1:0]
11364
        4'hF,                           // byte enables [3:0]
11365
        read_data                       // data returned from configuration read [31:0]
11366
    ) ;
11367
 
11368
    `ifdef PCI_IMAGE2
11369
    if (`PCI_AM2)
11370
        expected_value = `PCI_BA2_MEM_IO ;
11371
    else
11372
        expected_value = 32'h0000_0000 ;
11373
    `else
11374
    expected_value = 32'h0 ;
11375
    `endif
11376
 
11377
    if( read_data !== expected_value)
11378
    begin
11379
        test_fail("initial value of BAR2 register not as expected") ;
11380
        failed = 1 ;
11381
    end
11382
 
11383
    // BAR3
11384
    configuration_cycle_read
11385
    (
11386
        8'h00,                          // bus number [7:0]
11387
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11388
        3'h0,                           // function number [2:0]
11389
        6'h7,                           // register number [5:0]
11390
        2'h0,                           // type [1:0]
11391
        4'hF,                           // byte enables [3:0]
11392
        read_data                       // data returned from configuration read [31:0]
11393
    ) ;
11394
 
11395
    `ifdef PCI_IMAGE3
11396
    if(`PCI_AM3)
11397
        expected_value = `PCI_BA3_MEM_IO ;
11398
    else
11399
        expected_value = 32'h0000_0000 ;
11400
    `else
11401
    expected_value = 32'h0 ;
11402
    `endif
11403
 
11404
    if( read_data !== expected_value)
11405
    begin
11406
        test_fail("initial value of BAR3 register not as expected") ;
11407
        failed = 1 ;
11408
    end
11409
 
11410
    // BAR4
11411
    configuration_cycle_read
11412
    (
11413
        8'h00,                          // bus number [7:0]
11414
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11415
        3'h0,                           // function number [2:0]
11416
        6'h8,                           // register number [5:0]
11417
        2'h0,                           // type [1:0]
11418
        4'hF,                           // byte enables [3:0]
11419
        read_data                       // data returned from configuration read [31:0]
11420
    ) ;
11421
 
11422
    `ifdef PCI_IMAGE4
11423
    if (`PCI_AM4)
11424
        expected_value = `PCI_BA4_MEM_IO ;
11425
    else
11426
        expected_value = 32'h0000_0000 ;
11427
    `else
11428
    expected_value = 32'h0 ;
11429
    `endif
11430
 
11431
    if( read_data !== expected_value)
11432
    begin
11433
        test_fail("initial value of BAR4 register not as expected") ;
11434
        failed = 1 ;
11435
    end
11436
 
11437
    // BAR5
11438
    configuration_cycle_read
11439
    (
11440
        8'h00,                          // bus number [7:0]
11441
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11442
        3'h0,                           // function number [2:0]
11443
        6'h9,                           // register number [5:0]
11444
        2'h0,                           // type [1:0]
11445
        4'hF,                           // byte enables [3:0]
11446
        read_data                       // data returned from configuration read [31:0]
11447
    ) ;
11448
 
11449
    `ifdef PCI_IMAGE5
11450
    if(`PCI_AM5)
11451
        expected_value = `PCI_BA5_MEM_IO ;
11452
    else
11453
        expected_value = 32'h0000_0000 ;
11454
    `else
11455
    expected_value = 32'h0 ;
11456
    `endif
11457
 
11458
    if( read_data !== expected_value)
11459
    begin
11460
        test_fail("initial value of BAR5 register not as expected") ;
11461
        failed = 1 ;
11462
    end
11463
 
11464
    // write all 1s to BAR0
11465
    read_data = 32'hFFFF_FFFF ;
11466
 
11467
    // BAR0
11468
    configuration_cycle_write
11469
    (
11470
        8'h00,                          // bus number [7:0]
11471
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11472
        3'h0,                           // function number [2:0]
11473
        6'h4,                           // register number [5:0]
11474
        2'h0,                           // type [1:0]
11475
        4'hF,                           // byte enables [3:0]
11476
        read_data                       // data to write [31:0]
11477
    ) ;
11478
 
11479
    expected_value = 32'hFFFF_FFFF ;
11480
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11481
 
11482
    configuration_cycle_read
11483
    (
11484
        8'h00,                          // bus number [7:0]
11485
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11486
        3'h0,                           // function number [2:0]
11487
        6'h4,                           // register number [5:0]
11488
        2'h0,                           // type [1:0]
11489
        4'hF,                           // byte enables [3:0]
11490
        read_data                       // data to write [31:0]
11491
    ) ;
11492
 
11493
    if ( read_data !== expected_value )
11494
    begin
11495
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11496
        failed = 1 ;
11497
    end
11498
 
11499
    // write all 1s to BAR1
11500
    read_data = 32'hFFFF_FFFF ;
11501
 
11502
    // BAR1
11503
    configuration_cycle_write
11504
    (
11505
        8'h00,                          // bus number [7:0]
11506
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11507
        3'h0,                           // function number [2:0]
11508
        6'h5,                           // register number [5:0]
11509
        2'h0,                           // type [1:0]
11510
        4'hF,                           // byte enables [3:0]
11511
        read_data                       // data to write [31:0]
11512
    ) ;
11513
 
11514
    expected_value = {`PCI_AM1, 12'h000} ;
11515
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11516
    if (`PCI_AM1)
11517
        expected_value[0] = `PCI_BA1_MEM_IO ;
11518
 
11519
    configuration_cycle_read
11520
    (
11521
        8'h00,                          // bus number [7:0]
11522
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11523
        3'h0,                           // function number [2:0]
11524
        6'h5,                           // register number [5:0]
11525
        2'h0,                           // type [1:0]
11526
        4'hF,                           // byte enables [3:0]
11527
        read_data                       // data to write [31:0]
11528
    ) ;
11529
 
11530
    if ( read_data !== expected_value )
11531
    begin
11532
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11533
        failed = 1 ;
11534
    end
11535
 
11536
    // write all 1s to BAR2
11537
    read_data = 32'hFFFF_FFFF ;
11538
 
11539
    // BAR2
11540
    configuration_cycle_write
11541
    (
11542
        8'h00,                          // bus number [7:0]
11543
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11544
        3'h0,                           // function number [2:0]
11545
        6'h6,                           // register number [5:0]
11546
        2'h0,                           // type [1:0]
11547
        4'hF,                           // byte enables [3:0]
11548
        read_data                       // data to write [31:0]
11549
    ) ;
11550
 
11551
`ifdef PCI_IMAGE2
11552
    expected_value = {`PCI_AM2, 12'h000} ;
11553
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11554
    if (`PCI_AM2)
11555
        expected_value[0] = `PCI_BA2_MEM_IO ;
11556
`else
11557
    expected_value = 0 ;
11558
`endif
11559
 
11560
    configuration_cycle_read
11561
    (
11562
        8'h00,                          // bus number [7:0]
11563
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11564
        3'h0,                           // function number [2:0]
11565
        6'h6,                           // register number [5:0]
11566
        2'h0,                           // type [1:0]
11567
        4'hF,                           // byte enables [3:0]
11568
        read_data                       // data to write [31:0]
11569
    ) ;
11570
 
11571
    if ( read_data !== expected_value )
11572
    begin
11573
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11574
        failed = 1 ;
11575
    end
11576
 
11577
    // write all 1s to BAR3
11578
    read_data = 32'hFFFF_FFFF ;
11579
 
11580
    // BAR3
11581
    configuration_cycle_write
11582
    (
11583
        8'h00,                          // bus number [7:0]
11584
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11585
        3'h0,                           // function number [2:0]
11586
        6'h7,                           // register number [5:0]
11587
        2'h0,                           // type [1:0]
11588
        4'hF,                           // byte enables [3:0]
11589
        read_data                       // data to write [31:0]
11590
    ) ;
11591
 
11592
`ifdef PCI_IMAGE3
11593
    expected_value = {`PCI_AM3, 12'h000} ;
11594
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11595
    if(`PCI_AM3)
11596
        expected_value[0] = `PCI_BA3_MEM_IO ;
11597
`else
11598
    expected_value = 0 ;
11599
`endif
11600
 
11601
    configuration_cycle_read
11602
    (
11603
        8'h00,                          // bus number [7:0]
11604
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11605
        3'h0,                           // function number [2:0]
11606
        6'h7,                           // register number [5:0]
11607
        2'h0,                           // type [1:0]
11608
        4'hF,                           // byte enables [3:0]
11609
        read_data                       // data to write [31:0]
11610
    ) ;
11611
 
11612
    if ( read_data !== expected_value )
11613
    begin
11614
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11615
        failed = 1 ;
11616
    end
11617
 
11618
    // write all 1s to BAR4
11619
    read_data = 32'hFFFF_FFFF ;
11620
 
11621
    // BAR4
11622
    configuration_cycle_write
11623
    (
11624
        8'h00,                          // bus number [7:0]
11625
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11626
        3'h0,                           // function number [2:0]
11627
        6'h8,                           // register number [5:0]
11628
        2'h0,                           // type [1:0]
11629
        4'hF,                           // byte enables [3:0]
11630
        read_data                       // data to write [31:0]
11631
    ) ;
11632
 
11633
`ifdef PCI_IMAGE4
11634
    expected_value = {`PCI_AM4, 12'h000} ;
11635
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11636
    if(`PCI_AM4)
11637
        expected_value[0] = `PCI_BA4_MEM_IO ;
11638
`else
11639
    expected_value = 0 ;
11640
`endif
11641
 
11642
    configuration_cycle_read
11643
    (
11644
        8'h00,                          // bus number [7:0]
11645
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11646
        3'h0,                           // function number [2:0]
11647
        6'h8,                           // register number [5:0]
11648
        2'h0,                           // type [1:0]
11649
        4'hF,                           // byte enables [3:0]
11650
        read_data                       // data to write [31:0]
11651
    ) ;
11652
 
11653
    if ( read_data !== expected_value )
11654
    begin
11655
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11656
        failed = 1 ;
11657
    end
11658
 
11659
    // write all 1s to BAR5
11660
    read_data = 32'hFFFF_FFFF ;
11661
 
11662
    // BAR5
11663
    configuration_cycle_write
11664
    (
11665
        8'h00,                          // bus number [7:0]
11666
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11667
        3'h0,                           // function number [2:0]
11668
        6'h9,                           // register number [5:0]
11669
        2'h0,                           // type [1:0]
11670
        4'hF,                           // byte enables [3:0]
11671
        read_data                       // data to write [31:0]
11672
    ) ;
11673
 
11674
`ifdef PCI_IMAGE5
11675
    expected_value = {`PCI_AM5, 12'h000} ;
11676
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11677
    if(`PCI_AM5)
11678
        expected_value[0] = `PCI_BA5_MEM_IO ;
11679
`else
11680
    expected_value = 0 ;
11681
`endif
11682
 
11683
    configuration_cycle_read
11684
    (
11685
        8'h00,                          // bus number [7:0]
11686
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11687
        3'h0,                           // function number [2:0]
11688
        6'h9,                           // register number [5:0]
11689
        2'h0,                           // type [1:0]
11690
        4'hF,                           // byte enables [3:0]
11691
        read_data                       // data to write [31:0]
11692
    ) ;
11693
 
11694
    if ( read_data !== expected_value )
11695
    begin
11696
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11697
        failed = 1 ;
11698
    end
11699
`endif
11700
 
11701
    if (!failed)
11702
        test_ok ;
11703
end
11704
endtask
11705
 
11706 15 mihad
task display_warning;
11707
    input [31:0] error_address ;
11708
    input [31:0] expected_data ;
11709
    input [31:0] actual ;
11710
begin
11711
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11712
end
11713
endtask // display warning
11714
 
11715
/*############################################################################
11716
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11717
=====================
11718
############################################################################*/
11719
 
11720
// Task reslease the PCI bus for 'delay' clocks
11721
task do_pause;
11722
  input  [15:0] delay;
11723
  reg    [15:0] cnt;
11724
  begin
11725
    test_start <= 1'b0;  // no device is allowed to take this
11726
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11727
    begin
11728
      if (~pci_reset_comb)
11729
      begin
11730
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11731
      end
11732
      `NO_ELSE;
11733
    end
11734
  end
11735
endtask // do_pause
11736
 
11737
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11738
task DO_REF;
11739
  input  [79:0] name;
11740
  input  [2:0] master_number;
11741
  input  [PCI_BUS_DATA_RANGE:0] address;
11742
  input  [3:0] command;
11743
  input  [PCI_BUS_DATA_RANGE:0] data;
11744
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11745
  input  [9:0] size;
11746
  input   make_addr_par_error, make_data_par_error;
11747
  input  [7:0] master_wait_states;
11748
  input  [7:0] target_wait_states;
11749
  input  [1:0] target_devsel_speed;
11750
  input   fast_back_to_back;
11751
  input  [2:0] target_termination;
11752
  input   expect_master_abort;
11753
  reg     waiting;
11754
  begin
11755
// Cautiously wait for previous command to be done
11756
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11757
    begin
11758
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11759
      begin
11760
        if (~pci_reset_comb)
11761
        begin
11762
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11763
        end
11764
        `NO_ELSE;
11765
      end
11766
      else
11767
      begin
11768
        waiting = 1'b0;  // ready to do next command
11769
      end
11770
    end
11771
    next_test_name[79:0] <= name[79:0];
11772
    test_master_number <= master_number[2:0];
11773
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11774
    test_command[3:0] <= command[3:0] ;
11775
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11776
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11777
    test_size <= size;
11778
    test_make_addr_par_error <= make_addr_par_error;
11779
    test_make_data_par_error <= make_data_par_error;
11780
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11781
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11782
    test_target_initial_wait_states <= target_wait_states[7:4];
11783
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11784
    test_target_devsel_speed <= target_devsel_speed[1:0];
11785
    test_fast_back_to_back <= fast_back_to_back;
11786
    test_target_termination <= target_termination[2:0];
11787
    test_expect_master_abort <= expect_master_abort;
11788
    test_start <= 1'b1;
11789
    if (~pci_reset_comb)
11790
    begin
11791
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11792
    end
11793
    `NO_ELSE;
11794
// wait for new command to start
11795
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11796
    begin
11797
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11798
      begin
11799
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11800
      end
11801
      else
11802
      begin
11803
        waiting = 1'b0;  // ready to do next command
11804
      end
11805
    end
11806
  end
11807
endtask // DO_REF
11808
 
11809
// Use Macros defined in pci_defines.vh as paramaters
11810
 
11811
// DO_REF (name[79:0], master_number[2:0],
11812
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11813
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11814
//          make_addr_par_error, make_data_par_error,
11815
//          master_wait_states[8:0], target_wait_states[8:0],
11816
//          target_devsel_speed[1:0], fast_back_to_back,
11817
//          target_termination[2:0],
11818
//          expect_master_abort);
11819
//
11820
// Example:
11821
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11822
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11823
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11824
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11825
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11826
 
11827
// Access a location with no high-order bits set, assuring that no device responds
11828
task PCIU_CONFIG_READ_MASTER_ABORT;
11829
  input  [79:0] name;
11830
  input  [2:0] master_number;
11831 51 mihad
  input  [31:0] address ;
11832
  input  [3:0] be ;
11833 15 mihad
  begin
11834 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11835
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11836
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11837 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11838
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11839
  end
11840
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11841
 
11842
// Access a location with no high-order bits set, assuring that no device responds
11843
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11844
  input  [79:0] name;
11845
  input  [2:0] master_number;
11846 51 mihad
  input  [31:0] address ;
11847
  input  [3:0] be ;
11848 15 mihad
  begin
11849 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11850
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11851
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11852 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11853
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11854
  end
11855
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11856
 
11857
// Access a location with no high-order bits set, assuring that no device responds
11858
task PCIU_MEM_READ_MASTER_ABORT;
11859
  input  [79:0] name;
11860
  input  [2:0] master_number;
11861
  input  [9:0] size;
11862
  begin
11863
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11864
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11865
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11866
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11867
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11868
  end
11869
endtask // PCIU_MEM_READ_MASTER_ABORT
11870
 
11871
// Access a location with no high-order bits set, assuring that no device responds
11872
task PCIU_MEM_WRITE_MASTER_ABORT;
11873
  input  [79:0] name;
11874
  input  [2:0] master_number;
11875
  input  [9:0] size;
11876
  begin
11877
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11878
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11879
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11880
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11881
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11882
  end
11883
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11884
 
11885
// Do variable length transfers with various paramaters
11886
task PCIU_CONFIG_READ;
11887
  input  [79:0] name;
11888
  input  [2:0] master_number;
11889
  input  [PCI_BUS_DATA_RANGE:0] address;
11890
  input  [PCI_BUS_DATA_RANGE:0] data;
11891
  input  [3:0] be ;
11892
  input  [9:0] size;
11893
  input  [7:0] master_wait_states;
11894
  input  [7:0] target_wait_states;
11895
  input  [1:0] target_devsel_speed;
11896
  input  [2:0] target_termination;
11897
  begin
11898
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11899
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11900
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11901
              8'h0_0, target_wait_states[7:0],
11902
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11903
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11904
  end
11905
endtask // PCIU_CONFIG_READ
11906
 
11907
task PCIU_CONFIG_WRITE;
11908
  input  [79:0] name;
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] be ;
11913
  input  [9:0] size;
11914
  input  [7:0] master_wait_states;
11915
  input  [7:0] target_wait_states;
11916
  input  [1:0] target_devsel_speed;
11917
  input  [2:0] target_termination;
11918
  begin
11919
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11920
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11921
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11922
              8'h0_0, target_wait_states[7:0],
11923
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11924
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11925
  end
11926
endtask // PCIU_CONFIG_WRITE
11927
 
11928
task PCIU_READ;
11929
  input  [2:0] master_number;
11930
  input  [PCI_BUS_DATA_RANGE:0] address;
11931
  input  [3:0] command;
11932
  input  [PCI_BUS_DATA_RANGE:0] data;
11933
  input  [3:0] byte_en;
11934
  input  [9:0] size;
11935
  input  [7:0] master_wait_states;
11936
  input  [7:0] target_wait_states;
11937
  input  [1:0] target_devsel_speed;
11938
  input  [2:0] target_termination;
11939
  reg    [79:0] name;
11940
  begin
11941
    if (command == `BC_MEM_READ)
11942
        name = "MEM_READ  " ;
11943
    else if (command == `BC_MEM_READ_LN)
11944
        name = "MEM_RD_LN " ;
11945
    else if (command == `BC_MEM_READ_MUL )
11946
        name = "MEM_RD_MUL" ;
11947
    else
11948
        name = "WRONG_READ" ;
11949
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11950
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11951
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11952
              8'h0_0, target_wait_states[7:0],
11953
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11954
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11955
  end
11956
endtask // PCIU_READ
11957
 
11958
task PCIU_MEM_READ;
11959
  input  [79:0] name;
11960
  input  [2:0] master_number;
11961
  input  [PCI_BUS_DATA_RANGE:0] address;
11962
  input  [PCI_BUS_DATA_RANGE:0] data;
11963
  input  [9:0] size;
11964
  input  [7:0] master_wait_states;
11965
  input  [7:0] target_wait_states;
11966
  input  [1:0] target_devsel_speed;
11967
  input  [2:0] target_termination;
11968
  begin
11969
 
11970
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11971
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11972
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11973
              8'h0_0, target_wait_states[7:0],
11974
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11975
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11976
  end
11977
endtask // PCIU_MEM_READ
11978
 
11979
task PCIU_IO_READ;
11980
  input  [2:0] master_number;
11981
  input  [PCI_BUS_DATA_RANGE:0] address;
11982
  input  [PCI_BUS_DATA_RANGE:0] data;
11983
  input  [3:0] byte_en ;
11984
  input  [9:0] size;
11985
  input  [2:0] target_termination ;
11986
  begin
11987
 
11988
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11989
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11990
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11991
              8'h0_0, `Test_One_Zero_Target_WS,
11992
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11993
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11994
  end
11995
endtask // PCIU_IO_READ
11996
 
11997
task PCIU_IO_READ_MAKE_PERR;
11998
  input  [2:0] master_number;
11999
  input  [PCI_BUS_DATA_RANGE:0] address;
12000
  input  [PCI_BUS_DATA_RANGE:0] data;
12001
  input  [3:0] byte_en ;
12002
  input  [9:0] size;
12003
  input  [2:0] target_termination ;
12004
  begin
12005
 
12006
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12007
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12008
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12009
              8'h0_0, `Test_One_Zero_Target_WS,
12010
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12011
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12012
  end
12013
endtask // PCIU_IO_READ_MAKE_PERR
12014
 
12015
task PCIU_MEM_READ_LN;
12016
  input  [79:0] name;
12017
  input  [2:0] master_number;
12018
  input  [PCI_BUS_DATA_RANGE:0] address;
12019
  input  [PCI_BUS_DATA_RANGE:0] data;
12020
  input  [9:0] size;
12021
  input  [7:0] master_wait_states;
12022
  input  [7:0] target_wait_states;
12023
  input  [1:0] target_devsel_speed;
12024
  input  [2:0] target_termination;
12025
  begin
12026
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12027
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12028
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12029
              8'h0_0, target_wait_states[7:0],
12030
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12031
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12032
  end
12033
endtask // PCIU_MEM_READ_LN
12034
 
12035
task PCIU_MEM_READ_MUL;
12036
  input  [79:0] name;
12037
  input  [2:0] master_number;
12038
  input  [PCI_BUS_DATA_RANGE:0] address;
12039
  input  [PCI_BUS_DATA_RANGE:0] data;
12040
  input  [9:0] size;
12041
  input  [7:0] master_wait_states;
12042
  input  [7:0] target_wait_states;
12043
  input  [1:0] target_devsel_speed;
12044
  input  [2:0] target_termination;
12045
  begin
12046
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12047
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12048
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12049
              8'h0_0, target_wait_states[7:0],
12050
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12051
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12052
  end
12053
endtask // PCIU_MEM_READ_MUL
12054
 
12055
task PCIU_MEM_READ_MAKE_PERR;
12056
  input  [79:0] name;
12057
  input  [2:0] master_number;
12058
  input  [PCI_BUS_DATA_RANGE:0] address;
12059
  input  [PCI_BUS_DATA_RANGE:0] data;
12060
  input  [9:0] size;
12061
  input  [7:0] master_wait_states;
12062
  input  [7:0] target_wait_states;
12063
  input  [1:0] target_devsel_speed;
12064
  input  [2:0] target_termination;
12065
  begin
12066
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12067
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12068
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12069
              8'h0_0, target_wait_states[7:0],
12070
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12071
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12072
  end
12073
endtask // PCIU_MEM_READ_MAKE_PERR
12074
 
12075
task PCIU_MEM_WRITE;
12076
  input  [79:0] name;
12077
  input  [2:0] master_number;
12078
  input  [PCI_BUS_DATA_RANGE:0] address;
12079
  input  [PCI_BUS_DATA_RANGE:0] data;
12080
  input  [3:0] byte_en;
12081
  input  [9:0] size;
12082
  input  [7:0] master_wait_states;
12083
  input  [7:0] target_wait_states;
12084
  input  [1:0] target_devsel_speed;
12085
  input  [2:0] target_termination;
12086
  begin
12087
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12088
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12089
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12090
              8'h0_0, target_wait_states[7:0],
12091
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12092
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12093
  end
12094
endtask // PCIU_MEM_WRITE
12095
 
12096
task PCIU_IO_WRITE;
12097
  input  [2:0] master_number;
12098
  input  [PCI_BUS_DATA_RANGE:0] address;
12099
  input  [PCI_BUS_DATA_RANGE:0] data;
12100
  input  [3:0] byte_en;
12101
  input  [9:0] size;
12102
  input  [2:0] target_termination ;
12103
  begin
12104
 
12105
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12106
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12107
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12108
              8'h0_0, `Test_One_Zero_Target_WS,
12109
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12110
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12111
  end
12112
endtask // PCIU_IO_WRITE
12113
 
12114
task PCIU_IO_WRITE_MAKE_PERR ;
12115
  input  [2:0] master_number;
12116
  input  [PCI_BUS_DATA_RANGE:0] address;
12117
  input  [PCI_BUS_DATA_RANGE:0] data;
12118
  input  [3:0] byte_en;
12119
  input  [9:0] size;
12120
  input  [2:0] target_termination ;
12121
  begin
12122
 
12123
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12124
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12125
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12126
              8'h0_0, `Test_One_Zero_Target_WS,
12127
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12128
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12129
  end
12130
endtask // PCIU_IO_WRITE
12131
 
12132
task PCIU_MEM_WRITE_MAKE_SERR;
12133
  input  [79:0] name;
12134
  input  [2:0] master_number;
12135
  input  [PCI_BUS_DATA_RANGE:0] address;
12136
  input  [PCI_BUS_DATA_RANGE:0] data;
12137
  input  [9:0] size;
12138
  input  [7:0] master_wait_states;
12139
  input  [7:0] target_wait_states;
12140
  input  [1:0] target_devsel_speed;
12141
  input  [2:0] target_termination;
12142
  begin
12143
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12144
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12145
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12146
              8'h0_0, target_wait_states[7:0],
12147
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12148
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12149
  end
12150
endtask // PCIU_MEM_WRITE_MAKE_SERR
12151
 
12152
task PCIU_MEM_WRITE_MAKE_PERR;
12153
  input  [79:0] name;
12154
  input  [2:0] master_number;
12155
  input  [PCI_BUS_DATA_RANGE:0] address;
12156
  input  [PCI_BUS_DATA_RANGE:0] data;
12157
  input  [9:0] size;
12158
  input  [7:0] master_wait_states;
12159
  input  [7:0] target_wait_states;
12160
  input  [1:0] target_devsel_speed;
12161
  input  [2:0] target_termination;
12162
  begin
12163
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12164
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12165
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12166
              8'h0_0, target_wait_states[7:0],
12167
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12168
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12169
  end
12170
endtask // PCIU_MEM_WRITE
12171
 
12172
/*--------------------------------------------------------------------------
12173
Initialization CASES
12174
--------------------------------------------------------------------------*/
12175
 
12176
// Initialize the basic Config Registers of the PCI bridge target device
12177
task configure_bridge_target;
12178
    reg [11:0] offset ;
12179
    reg [31:0] data ;
12180
    `ifdef HOST
12181
    reg `WRITE_STIM_TYPE   write_data ;
12182
    reg `WB_TRANSFER_FLAGS write_flags ;
12183
    reg `WRITE_RETURN_TYPE write_status ;
12184
    `else
12185
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12186
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12187
    `endif
12188
 
12189
    reg [31:0] temp_var ;
12190
begin
12191
`ifdef HOST //  set Header
12192
    offset  = 12'h4 ; // PCI Header Command register
12193
    data    = 32'h0000_0007 ; // enable master & target operation
12194
 
12195
    write_flags                      = 0 ;
12196
    write_flags`INIT_WAITS           = tb_init_waits ;
12197
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12198
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12199
 
12200
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12201
    write_data`WRITE_SEL      = 4'h1 ;
12202
    write_data`WRITE_TAG_STIM = 0 ;
12203
    write_data`WRITE_DATA     = data ;
12204
 
12205
    next_test_name[79:0] <= "Init_Tar_R";
12206
 
12207
    $display(" bridge target - Enabling master and target operation!");
12208
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12209
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12210
    begin
12211
        $display("Write to configuration space failed! Time %t ", $time) ;
12212
    end
12213
 
12214
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12215
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12216
 
12217
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12218
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12219
 
12220
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12221
    write_data`WRITE_SEL      = 4'hf ;
12222
    write_data`WRITE_TAG_STIM = 0 ;
12223
    write_data`WRITE_DATA     = data ;
12224
 
12225
 `ifdef  NO_CNF_IMAGE
12226
  `ifdef PCI_IMAGE0 //      set P_BA0
12227
 
12228
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12229
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12230
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12231
    begin
12232
        $display("Write to configuration space failed! Time %t ", $time) ;
12233
    end
12234
  `endif
12235
 `else //      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
 
12245
`else // GUEST, set Header, set P_BA0
12246
    data            = 32'h0000_0007 ; // enable master & target operation
12247
    byte_enables    = 4'hF ;
12248
    $display(" bridge target - Enabling master and target operation!");
12249 45 mihad
    configuration_cycle_write(0,                        // bus number
12250
                              `TAR0_IDSEL_INDEX - 11,   // device number
12251
                              0,                        // function number
12252
                              1,                        // register number
12253
                              0,                        // type of configuration cycle
12254
                              byte_enables,             // byte enables
12255
                              data                      // data
12256 15 mihad
                             ) ;
12257
 
12258
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12259
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12260
    byte_enables = 4'hf ;
12261 45 mihad
    configuration_cycle_write(0,                        // bus number
12262
                              `TAR0_IDSEL_INDEX - 11,   // device number
12263
                              0,                        // function number
12264
                              4,                        // register number
12265
                              0,                        // type of configuration cycle
12266
                              byte_enables,             // byte enables
12267
                              data                      // data
12268 15 mihad
                             ) ;
12269
 
12270
`endif
12271
end
12272
endtask // configure_bridge_target
12273
 
12274
// Initialize the basic Config Registers of the PCI bridge target device
12275
task configure_bridge_target_base_addresses;
12276
    reg [11:0] offset ;
12277
    reg [31:0] data ;
12278
    `ifdef HOST
12279
    reg `WRITE_STIM_TYPE   write_data ;
12280
    reg `WB_TRANSFER_FLAGS write_flags ;
12281
    reg `WRITE_RETURN_TYPE write_status ;
12282
    `else
12283
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12284
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12285
    `endif
12286
 
12287
    reg [31:0] temp_var ;
12288
begin
12289
`ifdef HOST //  set Header
12290
    offset  = 12'h4 ; // PCI Header Command register
12291
    data    = 32'h0000_0007 ; // enable master & target operation
12292
 
12293
    write_flags                    = 0 ;
12294
    write_flags`INIT_WAITS         = tb_init_waits ;
12295
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12296
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12297
 
12298
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12299
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12300
 
12301
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12302
    write_data`WRITE_SEL      = 4'h1 ;
12303
    write_data`WRITE_TAG_STIM = 0 ;
12304
    write_data`WRITE_DATA     = data ;
12305
 
12306
    next_test_name[79:0] <= "Init_Tar_R";
12307
 
12308
    $display(" bridge target - Enabling master and target operation!");
12309
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12310
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12311
    begin
12312
        $display("Write to configuration space failed! Time %t ", $time) ;
12313
    end
12314
 
12315
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12316
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12317
 
12318
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12319
    write_data`WRITE_SEL      = 4'hf ;
12320
    write_data`WRITE_TAG_STIM = 0 ;
12321
    write_data`WRITE_DATA     = data ;
12322
 
12323
 `ifdef  NO_CNF_IMAGE
12324
  `ifdef PCI_IMAGE0 //      set P_BA0
12325
 
12326
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12327
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12328
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12329
    begin
12330
        $display("Write to configuration space failed! Time %t ", $time) ;
12331
    end
12332
  `endif
12333
 `else //      set P_BA0
12334
 
12335
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12336
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12337
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12338
    begin
12339
        $display("Write to configuration space failed! Time %t ", $time) ;
12340
    end
12341
 `endif
12342
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12343
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12344
 
12345
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12346
    write_data`WRITE_SEL      = 4'hf ;
12347
    write_data`WRITE_TAG_STIM = 0 ;
12348
    write_data`WRITE_DATA     = data ;
12349
 
12350
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12351
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12352
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12353
    begin
12354
        $display("Write to configuration space failed! Time %t ", $time) ;
12355
    end
12356
 `ifdef PCI_IMAGE2
12357
 
12358
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12359
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12360
 
12361
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12362
    write_data`WRITE_SEL      = 4'hf ;
12363
    write_data`WRITE_TAG_STIM = 0 ;
12364
    write_data`WRITE_DATA     = data ;
12365
 
12366
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12367
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12368
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12369
    begin
12370
        $display("Write to configuration space failed! Time %t ", $time) ;
12371
    end
12372
 `endif
12373
 `ifdef PCI_IMAGE3
12374
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12375
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12376
 
12377
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12378
    write_data`WRITE_SEL      = 4'hf ;
12379
    write_data`WRITE_TAG_STIM = 0 ;
12380
    write_data`WRITE_DATA     = data ;
12381
 
12382
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12383
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12384
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12385
    begin
12386
        $display("Write to configuration space failed! Time %t ", $time) ;
12387
    end
12388
 `endif
12389
 `ifdef PCI_IMAGE4
12390
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12391
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12392
 
12393
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12394
    write_data`WRITE_SEL      = 4'hf ;
12395
    write_data`WRITE_TAG_STIM = 0 ;
12396
    write_data`WRITE_DATA     = data ;
12397
 
12398
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12399
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12400
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12401
    begin
12402
        $display("Write to configuration space failed! Time %t ", $time) ;
12403
    end
12404
 `endif
12405
 `ifdef PCI_IMAGE5
12406
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12407
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12408
 
12409
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12410
    write_data`WRITE_SEL      = 4'hf ;
12411
    write_data`WRITE_TAG_STIM = 0 ;
12412
    write_data`WRITE_DATA     = data ;
12413
 
12414
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12415
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12416
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12417
    begin
12418
        $display("Write to configuration space failed! Time %t ", $time) ;
12419
    end
12420
 `endif
12421
 
12422
`else // GUEST, set Header, set P_BA0
12423
    data            = 32'h0000_0007 ; // enable master & target operation
12424
    byte_enables    = 4'hF ;
12425
    $display(" bridge target - Enabling master and target operation!");
12426 45 mihad
    configuration_cycle_write(0,                        // bus number
12427
                              `TAR0_IDSEL_INDEX - 11,   // device number
12428
                              0,                        // function number
12429
                              1,                        // register number
12430
                              0,                        // type of configuration cycle
12431
                              byte_enables,             // byte enables
12432
                              data                      // data
12433 15 mihad
                             ) ;
12434
 
12435
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12436
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12437
    byte_enables = 4'hf ;
12438 45 mihad
    configuration_cycle_write(0,                        // bus number
12439
                              `TAR0_IDSEL_INDEX - 11,   // device number
12440
                              0,                        // function number
12441
                              4,                        // register number
12442
                              0,                        // type of configuration cycle
12443
                              byte_enables,             // byte enables
12444
                              data                      // data
12445 15 mihad
                             ) ;
12446
 
12447
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12448
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12449
    byte_enables = 4'hf ;
12450 45 mihad
    configuration_cycle_write(0,                        // bus number
12451
                              `TAR0_IDSEL_INDEX - 11,   // device number
12452
                              0,                        // function number
12453
                              5,                        // register number
12454
                              0,                        // type of configuration cycle
12455
                              byte_enables,             // byte enables
12456
                              data                      // data
12457 15 mihad
                             ) ;
12458
 `ifdef PCI_IMAGE2
12459
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12460
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12461
    byte_enables = 4'hf ;
12462 45 mihad
    configuration_cycle_write(0,                        // bus number
12463
                              `TAR0_IDSEL_INDEX - 11,   // device number
12464
                              0,                        // function number
12465
                              6,                        // register number
12466
                              0,                        // type of configuration cycle
12467
                              byte_enables,             // byte enables
12468
                              data                      // data
12469 15 mihad
                             ) ;
12470
 `endif
12471
 `ifdef PCI_IMAGE3
12472
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12473
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12474
    byte_enables = 4'hf ;
12475 45 mihad
    configuration_cycle_write(0,                        // bus number
12476
                              `TAR0_IDSEL_INDEX - 11,   // device number
12477
                              0,                        // function number
12478
                              7,                        // register number
12479
                              0,                        // type of configuration cycle
12480
                              byte_enables,             // byte enables
12481
                              data                      // data
12482 15 mihad
                             ) ;
12483
 `endif
12484
 `ifdef PCI_IMAGE4
12485
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12486
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12487
    byte_enables = 4'hf ;
12488 45 mihad
    configuration_cycle_write(0,                        // bus number
12489
                              `TAR0_IDSEL_INDEX - 11,   // device number
12490
                              0,                        // function number
12491
                              8,                        // register number
12492
                              0,                        // type of configuration cycle
12493
                              byte_enables,             // byte enables
12494
                              data                      // data
12495 15 mihad
                             ) ;
12496
 `endif
12497
 `ifdef PCI_IMAGE5
12498
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12499
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12500
    byte_enables = 4'hf ;
12501 45 mihad
    configuration_cycle_write(0,                        // bus number
12502
                              `TAR0_IDSEL_INDEX - 11,   // device number
12503
                              0,                        // function number
12504
                              9,                        // register number
12505
                              0,                        // type of configuration cycle
12506
                              byte_enables,             // byte enables
12507
                              data                      // data
12508 15 mihad
                             ) ;
12509
 `endif
12510
`endif
12511
end
12512
endtask // configure_bridge_target_base_addresses
12513
 
12514
/*--------------------------------------------------------------------------
12515
Test CASES
12516
--------------------------------------------------------------------------*/
12517
 
12518
// function converts PCI address to WB with the same data as the pci_decoder does
12519
function [31:0] pci_to_wb_addr_convert ;
12520
 
12521
    input [31:0] pci_address ;
12522
    input [31:0] translation_address ;
12523
    input [31:0] translate ;
12524
 
12525
    reg   [31:0] temp_address ;
12526
begin
12527
    if ( translate !== 1 )
12528
    begin
12529
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12530
    end
12531
    else
12532
    begin
12533
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12534
    end
12535
 
12536
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12537
    pci_to_wb_addr_convert = temp_address ;
12538
end
12539
endfunction // pci_to_wb_addr_convert
12540
 
12541
// Test normal write and read to WB slave
12542
task test_normal_wr_rd;
12543
  input  [2:0]  Master_ID;
12544
  input  [PCI_BUS_DATA_RANGE:0] Address;
12545
  input  [PCI_BUS_DATA_RANGE:0] Data;
12546
  input  [3:0]  Be;
12547
  input  [2:0]  Image_num;
12548
  input  [9:0]  Set_size;
12549
  input         Set_addr_translation;
12550
  input         Set_prefetch_enable;
12551
  input  [7:0]  Cache_lsize;
12552
  input         Set_wb_wait_states;
12553
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12554
 
12555
  reg    [31:0] rd_address;
12556
  reg    [31:0] rd_data;
12557
  reg    [3:0]  rd_be;
12558
  reg    [11:0] addr_offset;
12559
  reg    [31:0] read_data;
12560
  reg           continue ;
12561
  reg           ok   ;
12562
  reg    [31:0] expect_address ;
12563
  reg    [31:0] expect_rd_address ;
12564
  reg           expect_we ;
12565
  reg    [9:0]  expect_length_wr ;
12566
  reg    [9:0]  expect_length_rd ;
12567
  reg    [9:0]  expect_length_rd1 ;
12568
  reg    [9:0]  expect_length_rd2 ;
12569
  reg    [3:0]  use_rd_cmd ;
12570
  integer       i ;
12571 35 mihad
  reg           error_monitor_done ;
12572 15 mihad
begin:main
12573
 
12574
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12575
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12576
    $display(" - errors will be reported, but they should not occur!");
12577
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12578
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12579
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12580
    if ( ok !== 1 )
12581
    begin
12582
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12583
        test_fail("write to P_ERR_CS register didn't succeede") ;
12584
        disable main;
12585
    end
12586
 
12587
    `ifdef  ADDR_TRAN_IMPL
12588
 
12589
    // set or clear address translation
12590
    if (Set_addr_translation)
12591
    begin
12592
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12593
        $display(" - address translation will be performed!");
12594
    end
12595
    else
12596
    begin
12597
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12598
        $display(" - address translation will not be performed!");
12599
    end
12600
    // set or clear pre-fetch enable
12601
    if (Set_prefetch_enable)
12602
    begin
12603
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12604
        $display(" - bursts can be performed!");
12605
    end
12606
    else
12607
    begin
12608
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12609
        $display(" - bursts can not be performed!");
12610
    end
12611
 
12612
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12613
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12614
    if ( ok !== 1 )
12615
    begin
12616
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12617
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12618
        disable main;
12619
    end
12620
 
12621
    // predict the address and control signals on WB bus
12622
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12623
    expect_we      = 1'b1 ; // WRITE
12624
 
12625
    `else
12626
 
12627
    // address translation is not implemented
12628
    $display("Address translation is NOT implemented for PCI images!");
12629
    // set or clear pre-fetch enable
12630
    if (Set_prefetch_enable)
12631
    begin
12632
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12633
        $display(" - bursts can be performed!");
12634
    end
12635
    else
12636
    begin
12637
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12638
        $display(" - bursts can not be performed!");
12639
    end
12640
 
12641
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12642
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12643
    if ( ok !== 1 )
12644
    begin
12645
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12646
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12647
        disable main;
12648
    end
12649
 
12650
    // predict the address and control signals on WB bus
12651
    expect_address = Address ;
12652
    expect_we      = 1'b1 ; // WRITE
12653
 
12654
    `endif
12655
 
12656
    // set WB SLAVE parameters
12657
    if (Set_wb_wait_states)
12658
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12659
    else
12660
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12661
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12662
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12663
 
12664
    if ( Set_size > (`PCIW_DEPTH - 2) )
12665
    begin
12666
        expect_length_wr = `PCIW_DEPTH - 2 ;
12667
    end
12668
    else
12669
    begin
12670
        expect_length_wr = Set_size ;
12671
    end
12672
    // write through the PCI bridge to WB slave
12673
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12674
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12675
 
12676
    fork
12677
    begin
12678
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12679
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12680
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12681
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12682
        do_pause( 1 ) ;
12683
    end
12684
    begin
12685
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12686
       if ( ok !== 1 )
12687
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12688
       else
12689
           test_ok ;
12690
    end
12691
    join
12692
 
12693
    // predict the address and control signals on WB bus
12694
    expect_we      = 1'b0 ; // READ
12695
 
12696
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12697
    $display("Memory read through PCI bridge to WB slave!");
12698
 
12699
    if ( expect_length_wr == 1 )
12700
    begin
12701
        if (Set_prefetch_enable)
12702
        begin
12703
            expect_length_rd1 = Cache_lsize ;
12704
            expect_length_rd2 = 0 ;
12705
                // If PCI behavioral master must check received DATA
12706
                master2_check_received_data = 0 ;
12707
                    master1_check_received_data = 0 ;
12708
        end
12709
        else
12710
        begin
12711
            expect_length_rd1 = 1 ;
12712
            expect_length_rd2 = 0 ;
12713
                // If PCI behavioral master must check received DATA
12714
                master2_check_received_data = 1 ;
12715
                    master1_check_received_data = 1 ;
12716
        end
12717
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12718
        expect_length_rd  = expect_length_rd1 ;
12719
    end
12720
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12721
    begin
12722
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12723
        expect_length_rd2 = 0 ;
12724
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12725
        expect_length_rd  = expect_length_rd1 ;
12726
                // If PCI behavioral master must check received DATA
12727
        master2_check_received_data = 1 ;
12728
            master1_check_received_data = 1 ;
12729
    end
12730
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12731
    begin
12732
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12733
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12734
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12735
        expect_length_rd  = expect_length_rd1 ;
12736
                // If PCI behavioral master must check received DATA
12737
                master2_check_received_data = 1 ;
12738
            master1_check_received_data = 1 ;
12739
    end
12740
    else
12741
    begin
12742
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12743
        begin
12744
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12745
            expect_length_rd2 = 0 ;
12746
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12747
            expect_length_rd  = expect_length_rd1 ;
12748
                // If PCI behavioral master must check received DATA
12749
                master2_check_received_data = 0 ;
12750
                    master1_check_received_data = 0 ;
12751
        end
12752
        else
12753
        begin
12754
            if ( expect_length_wr > Cache_lsize )
12755
            begin
12756
                expect_length_rd1 = Cache_lsize ;
12757
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12758
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12759
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12760
                else
12761
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12762
                expect_length_rd  = expect_length_rd1 ;
12763
                        // If PCI behavioral master must check received DATA
12764
                        master2_check_received_data = 1 ;
12765
                            master1_check_received_data = 1 ;
12766
            end
12767
            else
12768
            begin
12769
                expect_length_rd1 = Cache_lsize ;
12770
                expect_length_rd2 = 0 ;
12771
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12772
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12773
                else
12774
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12775
                expect_length_rd  = expect_length_wr ;
12776
                                if ( expect_length_wr == Cache_lsize )
12777
                        begin
12778
                                // If PCI behavioral master must check received DATA
12779
                                master2_check_received_data = 1 ;
12780
                                    master1_check_received_data = 1 ;
12781
                                end
12782
                                else
12783
                                begin
12784
                                // If PCI behavioral master must check received DATA
12785
                                master2_check_received_data = 0 ;
12786
                                    master1_check_received_data = 0 ;
12787
                end
12788
            end
12789
        end
12790
    end
12791
 
12792
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12793
    expect_rd_address = expect_address ;
12794
    rd_data[31:0] = Data[31:0];
12795
    rd_be[3:0] = Be[3:0];
12796
 
12797
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12798
    while (expect_length_rd2 > 0)
12799
    begin
12800
        // do read
12801
        $display("Read %d words!", expect_length_rd);
12802
 
12803
        fork
12804
        begin
12805
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12806
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12807
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12808
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12809
 
12810
            wb_transaction_stop( expect_length_rd - 1) ;
12811
 
12812
            do_pause( 1 ) ;
12813
        end
12814
        begin
12815
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12816
            if ( ok !== 1 )
12817
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12818
 
12819
            repeat( 3 )
12820
                @(posedge pci_clock) ;
12821
 
12822
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12823
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12824
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12825
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12826
 
12827
            do_pause( 1 ) ;
12828
            while ( FRAME === 0 )
12829
                @(posedge pci_clock) ;
12830
 
12831
            while ( IRDY === 0 )
12832
                @(posedge pci_clock) ;
12833
 
12834 35 mihad
            #1 ;
12835
            if ( !error_monitor_done )
12836
                disable monitor_error_event1 ;
12837 15 mihad
        end
12838
        begin:monitor_error_event1
12839 35 mihad
            error_monitor_done = 0 ;
12840 15 mihad
            @(error_event_int) ;
12841
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12842
            ok = 0 ;
12843 35 mihad
            error_monitor_done = 1 ;
12844 15 mihad
        end
12845
        join
12846
 
12847
        // increasing the starting address for PCI master and for WB transaction monitor
12848
        rd_address = rd_address + (4 * expect_length_rd) ;
12849
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12850
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12851
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12852
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12853
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12854
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12855
        for (i=0; i<expect_length_rd; i=i+1)
12856
            rd_be[3:0] = {Be[2:0], Be[3]};
12857
 
12858
        // set parameters for next read
12859
        if ( expect_length_rd2 == 1 )
12860
        begin
12861
                if (Set_prefetch_enable)
12862
                begin
12863
                    expect_length_rd1 = Cache_lsize ;
12864
                    expect_length_rd2 = 0 ;
12865
                        // If PCI behavioral master must check received DATA
12866
                        master2_check_received_data = 0 ;
12867
                            master1_check_received_data = 0 ;
12868
                end
12869
                else
12870
                begin
12871
                    expect_length_rd1 = 1 ;
12872
                    expect_length_rd2 = 0 ;
12873
                        // If PCI behavioral master must check received DATA
12874
                        master2_check_received_data = 1 ;
12875
                            master1_check_received_data = 1 ;
12876
                end
12877
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12878
            expect_length_rd  = expect_length_rd1 ;
12879
        end
12880
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12881
        begin
12882
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12883
            expect_length_rd2 = 0 ;
12884
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12885
            expect_length_rd  = expect_length_rd1 ;
12886
                        // If PCI behavioral master must check received DATA
12887
                        master2_check_received_data = 1 ;
12888
                    master1_check_received_data = 1 ;
12889
        end
12890
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12891
        begin
12892
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12893
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12894
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12895
            expect_length_rd  = expect_length_rd1 ;
12896
                        // If PCI behavioral master must check received DATA
12897
                        master2_check_received_data = 1 ;
12898
                    master1_check_received_data = 1 ;
12899
        end
12900
        else
12901
        begin
12902
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12903
            begin
12904
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12905
                expect_length_rd2 = 0 ;
12906
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12907
                expect_length_rd  = expect_length_rd1 ;
12908
                        // If PCI behavioral master must check received DATA
12909
                        master2_check_received_data = 0 ;
12910
                            master1_check_received_data = 0 ;
12911
            end
12912
            else
12913
            begin
12914
                if ( expect_length_rd2 > Cache_lsize )
12915
                begin
12916
                    expect_length_rd1 = Cache_lsize ;
12917
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12918
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12919
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12920
                    else
12921
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12922
                    expect_length_rd  = expect_length_rd1 ;
12923
                                // If PCI behavioral master must check received DATA
12924
                                master2_check_received_data = 1 ;
12925
                                    master1_check_received_data = 1 ;
12926
                end
12927
                else
12928
                begin
12929
                    expect_length_rd  = expect_length_rd2 ;
12930
                    expect_length_rd1 = Cache_lsize ;
12931
                    expect_length_rd2 = 0 ;
12932
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12933
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12934
                    else
12935
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12936
                                        if ( expect_length_rd2 == Cache_lsize )
12937
                                begin
12938
                                        // If PCI behavioral master must check received DATA
12939
                                        master2_check_received_data = 1 ;
12940
                                            master1_check_received_data = 1 ;
12941
                                        end
12942
                                        else
12943
                                        begin
12944
                                        // If PCI behavioral master must check received DATA
12945
                                        master2_check_received_data = 0 ;
12946
                                            master1_check_received_data = 0 ;
12947
                        end
12948
                end
12949
            end
12950
        end
12951
    end
12952
    // do last read
12953
    $display("Read %d words!", expect_length_rd);
12954
 
12955
    fork
12956
    begin
12957
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12958
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12959
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12960
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12961
 
12962
        wb_transaction_stop(expect_length_rd - 1) ;
12963
        do_pause( 1 ) ;
12964
    end
12965
    begin
12966
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12967
 
12968
        do_pause(3) ;
12969
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12970
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12971
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12972
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12973
        do_pause(1) ;
12974
 
12975
        while ( FRAME === 0 )
12976
            @(posedge pci_clock) ;
12977
 
12978
        while ( IRDY === 0 )
12979
            @(posedge pci_clock) ;
12980
 
12981 35 mihad
        #1 ;
12982
        if ( !error_monitor_done )
12983
            disable monitor_error_event2 ;
12984 15 mihad
    end
12985
    begin:monitor_error_event2
12986 35 mihad
        error_monitor_done = 0 ;
12987 15 mihad
        @(error_event_int) ;
12988
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12989
        ok = 0 ;
12990 35 mihad
        error_monitor_done = 1 ;
12991 15 mihad
    end
12992
    join
12993
 
12994
    if ( ok )
12995
        test_ok ;
12996
 
12997
    // Check that no ERRORs were reported
12998
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12999
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
13000
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13001
    config_read( addr_offset, 4'hF, read_data ) ;
13002
    if ( read_data[8] !== 0 )
13003
    begin
13004
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13005
        test_fail("error status was set even though no errors occured on WB bus") ;
13006
    end
13007
    else
13008
    begin
13009
        $display("No error was signaled, as expected!");
13010
        test_ok ;
13011
    end
13012
 
13013
end // main
13014
endtask // test_normal_wr_rd
13015
 
13016
// Test erroneous write to WB slave
13017
task test_wb_error_wr;
13018
  input  [2:0]  Master_ID;
13019
  input  [PCI_BUS_DATA_RANGE:0] Address;
13020
  input  [PCI_BUS_DATA_RANGE:0] Data;
13021
  input  [3:0]  Be;
13022
  input  [2:0]  Image_num;
13023
  input  [9:0]  Set_size;
13024
  input         Set_err_and_int_report;
13025
  input         Set_wb_wait_states;
13026
  input  [1:0]  Imm_BefLast_Last_error;
13027
 
13028
  reg    [11:0] addr_offset;
13029
  reg    [31:0] read_data;
13030
  reg           continue ;
13031
  reg           ok   ;
13032
  reg    [9:0]  expect_length ;
13033
  reg    [31:0] expect_address ;
13034
  reg    [0:0]  expect_we ;
13035
  reg    [31:0] rd_address;
13036
  reg    [31:0] rd_data;
13037
  reg    [3:0]  rd_be;
13038
  integer       i ;
13039
begin:main
13040
    if (Set_err_and_int_report)
13041
    begin
13042
        // enable ERROR reporting, because error must be reported and interrupt if required!
13043
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13044
        $display(" - errors will be reported when they will occur!");
13045
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13046
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13047
        $display(" - interrupt will be reported when error will occur!");
13048
    end
13049
    else
13050
    begin
13051
        // disable ERROR reporting, because error and interrupt must not be reported!
13052
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13053
        $display(" - errors will NOT be reported when they will occur!");
13054
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13055
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13056
        $display(" - interrupt will NOT be reported when error will occur!");
13057
    end
13058
    // enable/disable ERROR reporting
13059
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13060
 
13061
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13062
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13063
    if ( ok !== 1 )
13064
    begin
13065
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13066
        test_fail("PCI Error Control and Status register could not be written") ;
13067
        disable main;
13068
    end
13069
    // enable/disable INTERRUPT reporting
13070
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13071
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13072
    if ( ok !== 1 )
13073
    begin
13074
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13075
        test_fail("Interrupt Control register could not be written") ;
13076
        disable main;
13077
    end
13078
 
13079
    `ifdef  ADDR_TRAN_IMPL
13080
 
13081
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13082
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13083
    config_read( addr_offset, 4'hF, read_data ) ;
13084
    if ( read_data[2] !== 0 )
13085
    begin
13086
        $display("Address translation is set for PCI image%d!", Image_num);
13087
        // predict the address and control signals on WB bus
13088
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13089
        expect_we      = 1'b1 ; // WRITE
13090
    end
13091
    else
13092
    begin
13093
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13094
        // predict the address and control signals on WB bus
13095
        expect_address = Address ;
13096
        expect_we      = 1'b1 ; // WRITE
13097
    end
13098
 
13099
    `else
13100
 
13101
    // address translation is not implemented
13102
    $display("Address translation is NOT implemented for PCI images!");
13103
    // predict the address and control signals on WB bus
13104
    expect_address = Address ;
13105
    expect_we      = 1'b1 ; // WRITE
13106
 
13107
    `endif
13108
 
13109
    if ( Set_size > (`PCIW_DEPTH - 2) )
13110
    begin
13111
        expect_length = `PCIW_DEPTH - 2 ;
13112
    end
13113
    else
13114
    begin
13115
        expect_length = Set_size ;
13116
    end
13117
 
13118
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13119
    begin
13120
        $display("ERR termination with first data!");
13121
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13122
    end
13123
    else if (Imm_BefLast_Last_error == 1)
13124
    begin
13125
        $display("ERR termination before last data!");
13126
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13127
    end
13128
    else
13129
    begin
13130
        $display("ERR termination with last data!");
13131
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13132
    end
13133
 
13134
    // write through the PCI bridge to WB slave
13135
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13136
    fork
13137
    begin
13138
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13139
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13140
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13141
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13142
        do_pause( 1 ) ;
13143
    end
13144
    begin
13145
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13146
        begin
13147
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13148
            if ( ok !== 1 )
13149
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13150
        end
13151
        else if (Imm_BefLast_Last_error == 1)
13152
        begin
13153
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13154
            if ( ok !== 1 )
13155
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13156
        end
13157
        else
13158
        begin
13159
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13160
            if ( ok !== 1 )
13161
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13162
        end
13163
    end
13164
    begin
13165
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13166
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13167
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13168
        else if (Imm_BefLast_Last_error == 1)
13169
        begin
13170
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13171
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13172
            wb_transaction_stop(expect_length-2) ;
13173
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13174
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13175
        end
13176
        else
13177
        begin
13178
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13179
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13180
            wb_transaction_stop(expect_length-1) ;
13181
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13182
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13183
        end
13184
    end
13185
    join
13186
 
13187
    if ( ok )
13188
        test_ok ;
13189
 
13190
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13191
    begin
13192
        rd_data[31:0] = Data[31:0];
13193
        rd_address[31:0] = expect_address;
13194
        rd_be[3:0] = Be[3:0];
13195
    end
13196
    else if (Imm_BefLast_Last_error == 1)
13197
    begin
13198
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13199
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13200
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13201
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13202
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13203
        rd_be[3:0] = Be[3:0];
13204
        for (i=0; i<(expect_length-2); i=i+1)
13205
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13206
    end
13207
    else
13208
    begin
13209
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13210
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13211
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13212
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13213
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13214
        rd_be[3:0] = Be[3:0];
13215
        for (i=0; i<(expect_length-1); i=i+1)
13216
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13217
    end
13218
 
13219
    master2_check_received_data = 0 ;
13220
    master1_check_received_data = 0 ;
13221
 
13222
    // Check if ERRORs were reported
13223
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13224
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13225
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13226
 
13227
    ok = 1 ;
13228
    config_read( addr_offset, 4'hF, read_data ) ;
13229
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13230
    begin
13231
        $display("Error was signaled and reported, as expected!");
13232
        if (read_data[31:28] === rd_be)
13233
            $display("Byte enables written into P_ERR_CS register are as expected!");
13234
        else
13235
        begin
13236
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13237
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13238
            ok = 0 ;
13239
        end
13240
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13241
            $display("Bus command written into P_ERR_CS register is as expected!");
13242
        else
13243
        begin
13244
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13245
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13246
            ok = 0 ;
13247
        end
13248
 
13249
        if ( ok )
13250
            test_ok ;
13251
 
13252
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13253
 
13254
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13255
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13256
        config_read( addr_offset, 4'hF, read_data ) ;
13257
        if (read_data === rd_data)
13258
        begin
13259
            $display("Data written into P_ERR_DATA register is as expected!");
13260
            test_ok ;
13261
        end
13262
        else
13263
        begin
13264
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13265
            test_fail("PCI Erroneous Data register value was wrong") ;
13266
        end
13267
 
13268
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13269
 
13270
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13271
 
13272
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13273
        config_read( addr_offset, 4'hF, read_data ) ;
13274
        if (read_data === rd_address)
13275
        begin
13276
            $display("Address written into P_ERR_ADDR register is as expected!");
13277
            test_ok ;
13278
        end
13279
        else
13280
        begin
13281
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13282
            test_fail("PCI Erroneous Address register value was wrong") ;
13283
        end
13284
    end
13285
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13286
    begin
13287
        $display("Error was signaled and not reported, as expected!");
13288
        test_ok ;
13289
    end
13290
    else
13291
    begin
13292
        $display("Error was signaled and reported, as NOT expected!");
13293
        test_fail("Error status bit was set event though error reporting was disabled") ;
13294
    end
13295
 
13296
    // Check if Interrupts were reported
13297
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13298
 
13299
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13300
    ok = 1 ;
13301
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13302
    config_read( addr_offset, 4'hF, read_data ) ;
13303
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13304
    begin
13305
        $display("Interrupts was signaled and reported, as expected!");
13306
    end
13307
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13308
    begin
13309
        $display("Interrupts was signaled and not reported, as expected!");
13310
    end
13311
    else
13312
    begin
13313
        $display("Interrupt was signaled and reported, as NOT expected!");
13314
        test_fail("PCI Error Interrupt status was set when not expected") ;
13315
        ok = 0 ;
13316
    end
13317
 
13318
    `ifdef HOST
13319
    repeat( 4 )
13320
        @(posedge wb_clock) ;
13321
 
13322
    if ( INT_O === Set_err_and_int_report )
13323
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13324
    else
13325
    begin
13326
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13327
        test_fail("Interrupt request didn't have expected value") ;
13328
        ok = 0 ;
13329
    end
13330
 
13331
    `else // GUEST
13332
    repeat( 4 )
13333
        @(posedge pci_clock) ;
13334
 
13335
    if ( INTA === !Set_err_and_int_report )
13336
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13337
    else
13338
    begin
13339
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13340
        test_fail("Interrupt request didn't have expected value") ;
13341
        ok = 0 ;
13342
    end
13343
 
13344
    `endif
13345
 
13346
    if ( ok )
13347
        test_ok ;
13348
 
13349
    if (Set_err_and_int_report)
13350
    begin
13351
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13352
        $display("Error and Interrupt must be cleared!");
13353
        // clear  ERROR reporting bit
13354
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13355
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13356
        if ( ok !== 1 )
13357
        begin
13358
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13359
            test_fail("PCI Error Control and Status register could not be written to") ;
13360
            disable main;
13361
        end
13362
 
13363
        // clear INTERRUPT reporting bit
13364
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13365
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13366
        if ( ok !== 1 )
13367
        begin
13368
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13369
            test_fail("Interrupt Status register could not be written to") ;
13370
            disable main;
13371
        end
13372
 
13373
        test_ok ;
13374
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13375
        `ifdef HOST
13376
 
13377
        repeat(4)
13378
            @(posedge wb_clock) ;
13379
        if ( INT_O === 1'b0 )
13380
        begin
13381
            $display("Interrupt pin INT_O was correctly cleared!");
13382
            test_ok ;
13383
        end
13384
        else
13385
        begin
13386
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13387
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13388
            disable main;
13389
        end
13390
 
13391
        `else // GUEST
13392
 
13393
        repeat(4)
13394
            @(posedge pci_clock) ;
13395
        if ( INTA === 1'b1 )
13396
        begin
13397
            $display("Interrupt pin INTA was correctly cleared!");
13398
            test_ok ;
13399
        end
13400
        else
13401
        begin
13402
            $display("Interrupt pin INTA was NOT correctly cleared!");
13403
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13404
            disable main;
13405
        end
13406
 
13407
        `endif
13408
 
13409
    end
13410
    else
13411
    begin
13412
        $display("Error and Interrupt don't need to be cleared!");
13413
    end
13414
end // main
13415
endtask // test_wb_error_wr
13416
 
13417
task test_wb_error_rd;
13418
    reg    [11:0] addr_offset ;
13419
    reg    [11:0] ctrl_offset ;
13420
    reg    [11:0] ba_offset ;
13421
    reg    [11:0] am_offset ;
13422
    reg    [11:0] ta_offset ;
13423
    reg    [31:0] read_data;
13424
    reg           ok   ;
13425
    reg    [9:0]  expect_length ;
13426
    reg    [31:0] expect_address ;
13427
    reg    [0:0]  expect_we ;
13428
    reg    [31:0] rd_address;
13429
    reg    [31:0] rd_data;
13430
    reg    [3:0]  rd_be;
13431
    integer       i ;
13432
    reg           do_mem_aborts ;
13433
    reg           do_io_aborts ;
13434 35 mihad
    reg           error_monitor_done ;
13435 15 mihad
begin:main
13436
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13437
 
13438
    if ( target_mem_image !== -1 )
13439
    begin
13440
        do_mem_aborts = 1 ;
13441
 
13442
        if (target_mem_image === 1)
13443
        begin
13444
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13445
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13446
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13447
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13448
        end
13449
        else if (target_mem_image === 2)
13450
        begin
13451
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13452
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13453
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13454
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13455
        end
13456
        else if (target_mem_image === 3)
13457
        begin
13458
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13459
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13460
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13461
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13462
        end
13463
        else if (target_mem_image === 4)
13464
        begin
13465
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13466
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13467
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13468
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13469
        end
13470
        else if (target_mem_image === 5)
13471
        begin
13472
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13473
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13474
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13475
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13476
        end
13477
    end
13478
    else
13479
        do_mem_aborts = 0 ;
13480
 
13481
    if ( do_mem_aborts )
13482
    begin
13483
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13484
 
13485
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13486
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13487
        if ( ok !== 1 )
13488
        begin
13489
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13490
            test_fail("PCI Error Control and Status register could not be written") ;
13491
            disable main;
13492
        end
13493
 
13494
        // enable INTERRUPT reporting
13495
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13496
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13497
        if ( ok !== 1 )
13498
        begin
13499
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13500
            test_fail("Interrupt Control register could not be written") ;
13501
            disable main;
13502
        end
13503
 
13504
        addr_offset = 12'h010 + (4*target_mem_image) ;
13505
 
13506
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13507
        if ( ok !== 1 )
13508
        begin
13509
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13510
            test_fail("PCI Base Address register could not be written") ;
13511
            disable main;
13512
        end
13513
 
13514
        // disable address translation and enable prefetch so read bursts can be performed
13515
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13516
        if ( ok !== 1 )
13517
        begin
13518
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13519
            test_fail("PCI Image Control register could not be written") ;
13520
            disable main;
13521
        end
13522
 
13523
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13524
        if ( ok !== 1 )
13525
        begin
13526
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13527
            test_fail("PCI Address Mask register could not be written") ;
13528
            disable main;
13529
        end
13530
 
13531
        addr_offset = 12'h00C ;
13532
 
13533
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13534
        if ( ok !== 1 )
13535
        begin
13536
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13537
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13538
            disable main;
13539
        end
13540
 
13541
        // disable PCI master data checking
13542
        master1_check_received_data = 0 ;
13543
 
13544
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13545
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13546
 
13547
 
13548
        // do a single read error terminated on WB bus
13549
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13550
 
13551
        fork
13552
        begin
13553
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13554
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13555
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13556
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13557
 
13558
            do_pause( 1 ) ;
13559
        end
13560
        begin
13561
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13562
 
13563
            if ( ok !== 1 )
13564
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13565
 
13566
            do_pause(3) ;
13567
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13568
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13569
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13570
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13571
            do_pause(1) ;
13572
 
13573
            while ( FRAME === 0 )
13574
                @(posedge pci_clock) ;
13575
 
13576
            while ( IRDY === 0 )
13577
                @(posedge pci_clock) ;
13578
 
13579 35 mihad
            #1 ;
13580
            if ( !error_monitor_done )
13581
                disable monitor_error_event1 ;
13582 15 mihad
        end
13583
        begin:monitor_error_event1
13584 35 mihad
            error_monitor_done = 0 ;
13585 15 mihad
            @(error_event_int) ;
13586
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13587
            ok = 0 ;
13588 35 mihad
            error_monitor_done = 1 ;
13589 15 mihad
        end
13590
        join
13591
 
13592
        if ( ok )
13593
            test_ok ;
13594 26 mihad
 
13595
        @(posedge pci_clock) ;
13596
        @(posedge pci_clock) ;
13597
        @(posedge wb_clock) ;
13598
        @(posedge wb_clock) ;
13599 15 mihad
 
13600
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13601
        addr_offset = 12'h004 ;
13602
        config_read(addr_offset, 4'hF, read_data) ;
13603
        ok = 1 ;
13604
        if ( read_data[27] !== 1 )
13605
        begin
13606
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13607
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13608
            ok = 0 ;
13609
        end
13610
        if ( read_data[28] !== 0 )
13611
        begin
13612
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13613
            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") ;
13614
            ok = 0 ;
13615
        end
13616
        if ( read_data[29] !== 0 )
13617
        begin
13618
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13619
            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") ;
13620
            ok = 0 ;
13621
        end
13622
 
13623
        // clear statuses
13624
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13625
        if ( !ok )
13626
        begin
13627
            test_fail("write to PCI Device Status register failed") ;
13628
            $display("Couldn't write PCI Device Status register") ;
13629
            disable main ;
13630
        end
13631
 
13632
        if ( ok )
13633
            test_ok ;
13634
 
13635
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13636
 
13637
        ok = 1 ;
13638
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13639
 
13640
        config_read(addr_offset, 4'hF, read_data) ;
13641
        if (read_data[8] !== 0)
13642
        begin
13643
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13644
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13645
            ok = 0 ;
13646
        end
13647
        else
13648
            test_ok ;
13649
 
13650
        if ( ok !== 1 )
13651
        begin
13652
            config_write(addr_offset, read_data, 4'hF, ok) ;
13653
            if ( !ok )
13654
            begin
13655
                test_fail("PCI Error Control and Status register could not be written") ;
13656
                disable main ;
13657
            end
13658
        end
13659
 
13660
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13661
        fork
13662
        begin
13663
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13664
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13665
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13666
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13667
 
13668
            do_pause( 1 ) ;
13669
        end
13670
        begin
13671
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13672
 
13673
            if ( ok !== 1 )
13674
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13675
 
13676
            do_pause(3) ;
13677
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13678
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13679
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13680
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13681
            do_pause(1) ;
13682
 
13683
            while ( FRAME === 0 )
13684
                @(posedge pci_clock) ;
13685
 
13686
            while ( IRDY === 0 )
13687
                @(posedge pci_clock) ;
13688
 
13689 35 mihad
            #1 ;
13690
            if ( !error_monitor_done )
13691
                disable monitor_error_event2 ;
13692 15 mihad
        end
13693
        begin:monitor_error_event2
13694 35 mihad
            error_monitor_done = 0 ;
13695 15 mihad
            @(error_event_int) ;
13696
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13697
            ok = 0 ;
13698 35 mihad
            error_monitor_done = 1 ;
13699 15 mihad
        end
13700
        join
13701
 
13702
        if ( ok )
13703
            test_ok ;
13704
 
13705 26 mihad
        @(posedge pci_clock) ;
13706
        @(posedge pci_clock) ;
13707
        @(posedge wb_clock) ;
13708
        @(posedge wb_clock) ;
13709
 
13710 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13711
        addr_offset = 12'h004 ;
13712
        config_read(addr_offset, 4'hF, read_data) ;
13713
        ok = 1 ;
13714
        if ( read_data[27] !== 1 )
13715
        begin
13716
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13717
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13718
            ok = 0 ;
13719
        end
13720
        if ( read_data[28] !== 0 )
13721
        begin
13722
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13723
            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") ;
13724
            ok = 0 ;
13725
        end
13726
        if ( read_data[29] !== 0 )
13727
        begin
13728
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13729
            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") ;
13730
            ok = 0 ;
13731
        end
13732
 
13733
        // clear statuses
13734
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13735
        if ( !ok )
13736
        begin
13737
            test_fail("write to PCI Device Status register failed") ;
13738
            $display("Couldn't write PCI Device Status register") ;
13739
            disable main ;
13740
        end
13741
 
13742
        if ( ok )
13743
            test_ok ;
13744
 
13745
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13746
 
13747
        ok = 1 ;
13748
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13749
 
13750
        config_read(addr_offset, 4'hF, read_data) ;
13751
        if (read_data[8] !== 0)
13752
        begin
13753
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13754
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13755
            ok = 0 ;
13756
        end
13757
        else
13758
            test_ok ;
13759
 
13760
        if ( ok !== 1 )
13761
        begin
13762
            config_write(addr_offset, read_data, 4'hF, ok) ;
13763
            if ( !ok )
13764
            begin
13765
                test_fail("PCI Error Control and Status register could not be written") ;
13766
                disable main ;
13767
            end
13768
        end
13769
 
13770
        // do a single read error terminated on WB bus
13771
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13772
 
13773
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13774
 
13775
        fork
13776
        begin
13777
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13778
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13779
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13780
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13781
 
13782
            do_pause( 1 ) ;
13783
        end
13784
        begin
13785
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13786
 
13787
            if ( ok !== 1 )
13788
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13789
 
13790
            do_pause(3) ;
13791
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13792
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13793
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13794
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13795
            do_pause(1) ;
13796
 
13797
            while ( FRAME === 0 )
13798
                @(posedge pci_clock) ;
13799
 
13800
            while ( IRDY === 0 )
13801
                @(posedge pci_clock) ;
13802
 
13803 35 mihad
            if ( !error_monitor_done )
13804
                disable monitor_error_event3 ;
13805 15 mihad
        end
13806
        begin:monitor_error_event3
13807 35 mihad
            error_monitor_done = 0 ;
13808 15 mihad
            @(error_event_int) ;
13809
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13810
            ok = 0 ;
13811 35 mihad
            error_monitor_done = 1 ;
13812 15 mihad
        end
13813
        join
13814
 
13815
        if ( ok )
13816
            test_ok ;
13817
 
13818 26 mihad
        @(posedge pci_clock) ;
13819
        @(posedge pci_clock) ;
13820
        @(posedge wb_clock) ;
13821
        @(posedge wb_clock) ;
13822
 
13823 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13824
        addr_offset = 12'h004 ;
13825
        config_read(addr_offset, 4'hF, read_data) ;
13826
        ok = 1 ;
13827
        if ( read_data[27] !== 1 )
13828
        begin
13829
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13830
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13831
            ok = 0 ;
13832
        end
13833
        if ( read_data[28] !== 0 )
13834
        begin
13835
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13836
            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") ;
13837
            ok = 0 ;
13838
        end
13839
        if ( read_data[29] !== 0 )
13840
        begin
13841
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13842
            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") ;
13843
            ok = 0 ;
13844
        end
13845
 
13846
        // clear statuses
13847
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13848
        if ( !ok )
13849
        begin
13850
            test_fail("write to PCI Device Status register failed") ;
13851
            $display("Couldn't write PCI Device Status register") ;
13852
            disable main ;
13853
        end
13854
 
13855
        if ( ok )
13856
            test_ok ;
13857
 
13858
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13859
 
13860
        ok = 1 ;
13861
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13862
 
13863
        config_read(addr_offset, 4'hF, read_data) ;
13864
        if (read_data[8] !== 0)
13865
        begin
13866
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13867
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13868
            ok = 0 ;
13869
        end
13870
        else
13871
            test_ok ;
13872
 
13873
        if ( ok !== 1 )
13874
        begin
13875
            config_write(addr_offset, read_data, 4'hF, ok) ;
13876
            if ( !ok )
13877
            begin
13878
                test_fail("PCI Error Control and Status register could not be written") ;
13879
                disable main ;
13880
            end
13881
        end
13882
 
13883
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13884
 
13885
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13886
 
13887
        fork
13888
        begin
13889
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13890
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13891
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13892
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13893
 
13894
            do_pause( 1 ) ;
13895
        end
13896
        begin
13897
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13898
 
13899
            if ( ok !== 1 )
13900
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13901
 
13902
            do_pause(3) ;
13903
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13904
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13905
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13906
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13907
            do_pause(1) ;
13908
 
13909
            while ( FRAME === 0 )
13910
                @(posedge pci_clock) ;
13911
 
13912
            while ( IRDY === 0 )
13913
                @(posedge pci_clock) ;
13914
 
13915 35 mihad
            #1 ;
13916
            if ( !error_monitor_done )
13917
                disable monitor_error_event4 ;
13918 15 mihad
        end
13919
        begin:monitor_error_event4
13920 35 mihad
            error_monitor_done = 0 ;
13921 15 mihad
            @(error_event_int) ;
13922
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13923
            ok = 0 ;
13924 35 mihad
            error_monitor_done = 1 ;
13925 15 mihad
        end
13926
        begin
13927
            wb_transaction_stop( 1 ) ;
13928
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13929
        end
13930
        join
13931
 
13932
        if ( ok )
13933
            test_ok ;
13934
 
13935 26 mihad
        @(posedge pci_clock) ;
13936
        @(posedge pci_clock) ;
13937
        @(posedge wb_clock) ;
13938
        @(posedge wb_clock) ;
13939
 
13940 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13941
        addr_offset = 12'h004 ;
13942
        config_read(addr_offset, 4'hF, read_data) ;
13943
        ok = 1 ;
13944
        if ( read_data[27] !== 1 )
13945
        begin
13946
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13947
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13948
            ok = 0 ;
13949
        end
13950
        if ( read_data[28] !== 0 )
13951
        begin
13952
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13953
            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") ;
13954
            ok = 0 ;
13955
        end
13956
        if ( read_data[29] !== 0 )
13957
        begin
13958
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13959
            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") ;
13960
            ok = 0 ;
13961
        end
13962
 
13963
        // clear statuses
13964
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13965
        if ( !ok )
13966
        begin
13967
            test_fail("write to PCI Device Status register failed") ;
13968
            $display("Couldn't write PCI Device Status register") ;
13969
            disable main ;
13970
        end
13971
 
13972
        if ( ok )
13973
            test_ok ;
13974
 
13975
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13976
 
13977
        ok = 1 ;
13978
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13979
 
13980
        config_read(addr_offset, 4'hF, read_data) ;
13981
        if (read_data[8] !== 0)
13982
        begin
13983
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13984
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13985
            ok = 0 ;
13986
        end
13987
        else
13988
            test_ok ;
13989
 
13990
        if ( ok !== 1 )
13991
        begin
13992
            config_write(addr_offset, read_data, 4'hF, ok) ;
13993
            if ( !ok )
13994
            begin
13995
                test_fail("PCI Error Control and Status register could not be written") ;
13996
                disable main ;
13997
            end
13998
        end
13999
 
14000
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14001
 
14002
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14003
 
14004
        fork
14005
        begin
14006
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14007
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14008
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14009
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14010
 
14011
            do_pause( 1 ) ;
14012
        end
14013
        begin
14014
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14015
 
14016
            if ( ok !== 1 )
14017
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14018
 
14019
            do_pause(3) ;
14020
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14021
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14022
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14023
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14024
            do_pause(1) ;
14025
 
14026
            while ( FRAME === 0 )
14027
                @(posedge pci_clock) ;
14028
 
14029
            while ( IRDY === 0 )
14030
                @(posedge pci_clock) ;
14031
 
14032 35 mihad
            #1 ;
14033
            if ( !error_monitor_done )
14034
                disable monitor_error_event5 ;
14035 15 mihad
        end
14036
        begin:monitor_error_event5
14037 35 mihad
            error_monitor_done = 0 ;
14038 15 mihad
            @(error_event_int) ;
14039
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14040
            ok = 0 ;
14041 35 mihad
            error_monitor_done = 1 ;
14042 15 mihad
        end
14043
        begin
14044
            wb_transaction_stop( 3 ) ;
14045
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14046
        end
14047
        join
14048
 
14049
        if ( ok )
14050
            test_ok ;
14051
 
14052 26 mihad
        @(posedge pci_clock) ;
14053
        @(posedge pci_clock) ;
14054
        @(posedge wb_clock) ;
14055
        @(posedge wb_clock) ;
14056
 
14057 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14058
        addr_offset = 12'h004 ;
14059
        config_read(addr_offset, 4'hF, read_data) ;
14060
        ok = 1 ;
14061
        if ( read_data[27] !== 1 )
14062
        begin
14063
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14064
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14065
            ok = 0 ;
14066
        end
14067
        if ( read_data[28] !== 0 )
14068
        begin
14069
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14070
            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") ;
14071
            ok = 0 ;
14072
        end
14073
        if ( read_data[29] !== 0 )
14074
        begin
14075
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14076
            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") ;
14077
            ok = 0 ;
14078
        end
14079
 
14080
        // clear statuses
14081
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14082
        if ( !ok )
14083
        begin
14084
            test_fail("write to PCI Device Status register failed") ;
14085
            $display("Couldn't write PCI Device Status register") ;
14086
            disable main ;
14087
        end
14088
 
14089
        if ( ok )
14090
            test_ok ;
14091
 
14092
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14093
 
14094
        ok = 1 ;
14095
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14096
 
14097
        config_read(addr_offset, 4'hF, read_data) ;
14098
        if (read_data[8] !== 0)
14099
        begin
14100
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14101
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14102
            ok = 0 ;
14103
        end
14104
        else
14105
            test_ok ;
14106
 
14107
        if ( ok !== 1 )
14108
        begin
14109
            config_write(addr_offset, read_data, 4'hF, ok) ;
14110
            if ( !ok )
14111
            begin
14112
                test_fail("PCI Error Control and Status register could not be written") ;
14113
                disable main ;
14114
            end
14115
        end
14116
 
14117
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14118
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14119
        fork
14120
        begin
14121
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14122
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14123
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14124
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14125
 
14126
            do_pause( 1 ) ;
14127
        end
14128
        begin
14129
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14130
 
14131
            if ( ok !== 1 )
14132
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14133
 
14134
            do_pause(3) ;
14135
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14136
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14137
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14138
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14139
            do_pause(1) ;
14140
 
14141
            while ( FRAME === 0 )
14142
                @(posedge pci_clock) ;
14143
 
14144
            while ( IRDY === 0 )
14145
                @(posedge pci_clock) ;
14146
 
14147 35 mihad
            #1 ;
14148
            if ( !error_monitor_done )
14149
                disable monitor_error_event6 ;
14150 15 mihad
        end
14151
        begin:monitor_error_event6
14152 35 mihad
            error_monitor_done = 0 ;
14153 15 mihad
            @(error_event_int) ;
14154
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14155
            ok = 0 ;
14156 35 mihad
            error_monitor_done = 1 ;
14157 15 mihad
        end
14158
        begin
14159
            wb_transaction_stop( 3 ) ;
14160
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14161
        end
14162
        join
14163
 
14164
        if ( ok )
14165
            test_ok ;
14166
 
14167 26 mihad
        @(posedge pci_clock) ;
14168
        @(posedge pci_clock) ;
14169
        @(posedge wb_clock) ;
14170
        @(posedge wb_clock) ;
14171
 
14172 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14173
        addr_offset = 12'h004 ;
14174
        config_read(addr_offset, 4'hF, read_data) ;
14175
        ok = 1 ;
14176
        if ( read_data[27] !== 1 )
14177
        begin
14178
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14179
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14180
            ok = 0 ;
14181
        end
14182
        if ( read_data[28] !== 0 )
14183
        begin
14184
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14185
            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") ;
14186
            ok = 0 ;
14187
        end
14188
        if ( read_data[29] !== 0 )
14189
        begin
14190
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14191
            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") ;
14192
            ok = 0 ;
14193
        end
14194
 
14195
        // clear statuses
14196
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14197
        if ( !ok )
14198
        begin
14199
            test_fail("write to PCI Device Status register failed") ;
14200
            $display("Couldn't write PCI Device Status register") ;
14201
            disable main ;
14202
        end
14203
 
14204
        if ( ok )
14205
            test_ok ;
14206
 
14207
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14208
 
14209
        ok = 1 ;
14210
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14211
 
14212
        config_read(addr_offset, 4'hF, read_data) ;
14213
        if (read_data[8] !== 0)
14214
        begin
14215
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14216
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14217
            ok = 0 ;
14218
        end
14219
        else
14220
            test_ok ;
14221
 
14222
        if ( ok !== 1 )
14223
        begin
14224
            config_write(addr_offset, read_data, 4'hF, ok) ;
14225
            if ( !ok )
14226
            begin
14227
                test_fail("PCI Error Control and Status register could not be written") ;
14228
                disable main ;
14229
            end
14230
        end
14231
 
14232
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14233
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14234
        fork
14235
        begin
14236
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14237
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14238
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14239
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14240
 
14241
            do_pause( 1 ) ;
14242
        end
14243
        begin
14244
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14245
 
14246
            if ( ok !== 1 )
14247
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14248
 
14249
            do_pause(3) ;
14250
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14251
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14252
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14253
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14254
            do_pause(1) ;
14255
 
14256
            while ( FRAME === 0 )
14257
                @(posedge pci_clock) ;
14258
 
14259
            while ( IRDY === 0 )
14260
                @(posedge pci_clock) ;
14261
 
14262 35 mihad
            #1 ;
14263
            if ( !error_monitor_done )
14264
                disable monitor_error_event7 ;
14265 15 mihad
        end
14266
        begin:monitor_error_event7
14267 35 mihad
            error_monitor_done = 0 ;
14268 15 mihad
            @(error_event_int) ;
14269
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14270
            ok = 0 ;
14271 35 mihad
            error_monitor_done = 1 ;
14272 15 mihad
        end
14273
        begin
14274
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14275
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14276
        end
14277
        join
14278
 
14279
        if ( ok )
14280
            test_ok ;
14281
 
14282 26 mihad
        @(posedge pci_clock) ;
14283
        @(posedge pci_clock) ;
14284
        @(posedge wb_clock) ;
14285
        @(posedge wb_clock) ;
14286
 
14287 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14288
        addr_offset = 12'h004 ;
14289
        config_read(addr_offset, 4'hF, read_data) ;
14290
        ok = 1 ;
14291
        if ( read_data[27] !== 1 )
14292
        begin
14293
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14294
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14295
            ok = 0 ;
14296
        end
14297
        if ( read_data[28] !== 0 )
14298
        begin
14299
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14300
            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") ;
14301
            ok = 0 ;
14302
        end
14303
        if ( read_data[29] !== 0 )
14304
        begin
14305
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14306
            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") ;
14307
            ok = 0 ;
14308
        end
14309
 
14310
        // clear statuses
14311
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14312
        if ( !ok )
14313
        begin
14314
            test_fail("write to PCI Device Status register failed") ;
14315
            $display("Couldn't write PCI Device Status register") ;
14316
            disable main ;
14317
        end
14318
 
14319
        if ( ok )
14320
            test_ok ;
14321
 
14322
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14323
 
14324
        ok = 1 ;
14325
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14326
 
14327
        config_read(addr_offset, 4'hF, read_data) ;
14328
        if (read_data[8] !== 0)
14329
        begin
14330
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14331
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14332
            ok = 0 ;
14333
        end
14334
        else
14335
            test_ok ;
14336
 
14337
        if ( ok !== 1 )
14338
        begin
14339
            config_write(addr_offset, read_data, 4'hF, ok) ;
14340
            if ( !ok )
14341
            begin
14342
                test_fail("PCI Error Control and Status register could not be written") ;
14343
                disable main ;
14344
            end
14345
        end
14346
 
14347
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14348
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14349
        fork
14350
        begin
14351
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14352
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14353
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14354
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14355
 
14356
            do_pause( 1 ) ;
14357
        end
14358
        begin
14359
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14360
 
14361
            if ( ok !== 1 )
14362
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14363
 
14364
            do_pause(3) ;
14365
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14366
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14367
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14368
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14369
            do_pause(1) ;
14370
 
14371
            while ( FRAME === 0 )
14372
                @(posedge pci_clock) ;
14373
 
14374
            while ( IRDY === 0 )
14375
                @(posedge pci_clock) ;
14376
 
14377 35 mihad
            #1 ;
14378
            if ( !error_monitor_done )
14379
                disable monitor_error_event8 ;
14380 15 mihad
        end
14381
        begin:monitor_error_event8
14382 35 mihad
            error_monitor_done = 0 ;
14383 15 mihad
            @(error_event_int) ;
14384
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14385
            ok = 0 ;
14386 35 mihad
            error_monitor_done = 1 ;
14387 15 mihad
        end
14388
        begin
14389
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14390
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14391
        end
14392
        join
14393
 
14394
        if ( ok )
14395
            test_ok ;
14396
 
14397 26 mihad
        @(posedge pci_clock) ;
14398
        @(posedge pci_clock) ;
14399
        @(posedge wb_clock) ;
14400
        @(posedge wb_clock) ;
14401
 
14402 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14403
 
14404
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14405
        addr_offset = 12'h004 ;
14406
        config_read(addr_offset, 4'hF, read_data) ;
14407
        ok = 1 ;
14408
        if ( read_data[27] !== 1 )
14409
        begin
14410
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14411
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14412
            ok = 0 ;
14413
        end
14414
        if ( read_data[28] !== 0 )
14415
        begin
14416
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14417
            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") ;
14418
            ok = 0 ;
14419
        end
14420
        if ( read_data[29] !== 0 )
14421
        begin
14422
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14423
            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") ;
14424
            ok = 0 ;
14425
        end
14426
 
14427
        // clear statuses
14428
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14429
        if ( !ok )
14430
        begin
14431
            test_fail("write to PCI Device Status register failed") ;
14432
            $display("Couldn't write PCI Device Status register") ;
14433
            disable main ;
14434
        end
14435
 
14436
        if ( ok )
14437
            test_ok ;
14438
 
14439
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14440
 
14441
        ok = 1 ;
14442
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14443
 
14444
        config_read(addr_offset, 4'hF, read_data) ;
14445
        if (read_data[8] !== 0)
14446
        begin
14447
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14448
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14449
            ok = 0 ;
14450
        end
14451
        else
14452
            test_ok ;
14453
 
14454
        if ( ok !== 1 )
14455
        begin
14456
            config_write(addr_offset, read_data, 4'hF, ok) ;
14457
            if ( !ok )
14458
            begin
14459
                test_fail("PCI Error Control and Status register could not be written") ;
14460
                disable main ;
14461
            end
14462
        end
14463
 
14464
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14465
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14466
        fork
14467
        begin
14468
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14469
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14470
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14471
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14472
 
14473
            do_pause( 1 ) ;
14474
        end
14475
        begin
14476
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14477
 
14478
            if ( ok !== 1 )
14479
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14480
 
14481
            do_pause(3) ;
14482
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14483
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14484
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14485
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14486
            do_pause(1) ;
14487
 
14488
            while ( FRAME === 0 )
14489
                @(posedge pci_clock) ;
14490
 
14491
            while ( IRDY === 0 )
14492
                @(posedge pci_clock) ;
14493
 
14494 35 mihad
            #1 ;
14495
            if ( !error_monitor_done )
14496
                disable monitor_error_event9 ;
14497 15 mihad
        end
14498
        begin:monitor_error_event9
14499 35 mihad
            error_monitor_done = 0 ;
14500 15 mihad
            @(error_event_int) ;
14501
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14502
            ok = 0 ;
14503 35 mihad
            error_monitor_done = 1 ;
14504 15 mihad
        end
14505
        begin
14506
            wb_transaction_stop( 3 ) ;
14507
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14508
        end
14509
        join
14510
 
14511
        if ( ok )
14512
            test_ok ;
14513
 
14514
        // now check all other statuses too
14515
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14516
        ok = 1 ;
14517
 
14518
        addr_offset = 12'h004 ;
14519
        config_read(addr_offset, 4'hF, read_data) ;
14520
        if (read_data[31] !== 0)
14521
        begin
14522
            $display("Detected Parity Error bit set for no reason") ;
14523
            test_fail("Detected Parity Error bit was set for no reason") ;
14524
            ok = 0 ;
14525
        end
14526
 
14527
        if (read_data[30] !== 0)
14528
        begin
14529
            $display("Signaled System Error bit set for no reason") ;
14530
            test_fail("Signaled System Error bit was set for no reason") ;
14531
            ok = 0 ;
14532
        end
14533
 
14534
        if (read_data[29] !== 0)
14535
        begin
14536
            $display("Received Master Abort bit set for no reason") ;
14537
            test_fail("Received Master Abort bit was set for no reason") ;
14538
            ok = 0 ;
14539
        end
14540
 
14541
        if (read_data[28] !== 0)
14542
        begin
14543
            $display("Received Target Abort bit set for no reason");
14544
            test_fail("Received Target Abort bit was set for no reason") ;
14545
            ok = 0 ;
14546
        end
14547
 
14548
        if (read_data[27] !== 0)
14549
        begin
14550
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14551
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14552
            ok = 0 ;
14553
        end
14554
 
14555
        if (read_data[24] !== 0)
14556
        begin
14557
            $display("Master Data Parity Error bit set for no reason") ;
14558
            test_fail("Master Data Parity Error bit was set for no reason") ;
14559
            ok = 0 ;
14560
        end
14561
 
14562
        if ( ok )
14563
            test_ok ;
14564
 
14565
        test_name = "DISABLE IMAGE" ;
14566 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14567 15 mihad
        if ( ok !== 1 )
14568
        begin
14569
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14570
            test_fail("PCI Address Mask register could not be written") ;
14571
            disable main;
14572
        end
14573
    end
14574
 
14575
    if ( target_io_image !== -1 )
14576
    begin
14577
        do_io_aborts = 1 ;
14578
 
14579
        if (target_io_image === 1)
14580
        begin
14581
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14582
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14583
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14584
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14585
        end
14586
        else if (target_io_image === 2)
14587
        begin
14588
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14589
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14590
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14591
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14592
        end
14593
        else if (target_io_image === 3)
14594
        begin
14595
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14596
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14597
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14598
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14599
        end
14600
        else if (target_io_image === 4)
14601
        begin
14602
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14603
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14604
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14605
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14606
        end
14607
        else if (target_io_image === 5)
14608
        begin
14609
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14610
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14611
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14612
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14613
        end
14614
    end
14615
    else
14616
        do_io_aborts = 0 ;
14617
 
14618
    if ( do_io_aborts )
14619
    begin
14620
 
14621
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14622
 
14623
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14624
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14625
        if ( ok !== 1 )
14626
        begin
14627
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14628
            test_fail("PCI Error Control and Status register could not be written") ;
14629
            disable main;
14630
        end
14631
 
14632
        // enable INTERRUPT reporting
14633
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14634
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14635
        if ( ok !== 1 )
14636
        begin
14637
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14638
            test_fail("Interrupt Control register could not be written") ;
14639
            disable main;
14640
        end
14641
 
14642
        addr_offset = 12'h010 + (4*target_io_image) ;
14643
 
14644
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14645
        if ( ok !== 1 )
14646
        begin
14647
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14648
            test_fail("PCI Base Address register could not be written") ;
14649
            disable main;
14650
        end
14651
 
14652
        // disable address translation and enable prefetch so read bursts can be performed
14653
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14654
        if ( ok !== 1 )
14655
        begin
14656
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14657
            test_fail("PCI Image Control register could not be written") ;
14658
            disable main;
14659
        end
14660
 
14661
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14662
        if ( ok !== 1 )
14663
        begin
14664
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14665
            test_fail("PCI Address Mask register could not be written") ;
14666
            disable main;
14667
        end
14668
 
14669
        addr_offset = 12'h00C ;
14670
 
14671
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14672
        if ( ok !== 1 )
14673
        begin
14674
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14675
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14676
            disable main;
14677
        end
14678
 
14679
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14680
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14681
 
14682
        // do a single read error terminated on WB bus
14683
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14684
 
14685
        fork
14686
        begin
14687
            PCIU_IO_READ
14688
             (
14689
                `Test_Master_1,
14690
                Target_Base_Addr_R[target_io_image],
14691
                32'hAAAA_5555,
14692
                4'h0,
14693
                1,
14694
                `Test_Target_Retry_On
14695
             );
14696
 
14697
            do_pause( 1 ) ;
14698
        end
14699
        begin
14700
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14701
 
14702
            if ( ok !== 1 )
14703
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14704
 
14705
            do_pause(3) ;
14706
 
14707
            PCIU_IO_READ
14708
             (
14709
                `Test_Master_1,
14710
                Target_Base_Addr_R[target_io_image],
14711
                32'hAAAA_5555,
14712
                4'h0,
14713
                1,
14714
                `Test_Target_Abort_On
14715
             );
14716
 
14717
            do_pause( 1 ) ;
14718
 
14719
            while ( FRAME === 0 )
14720
                @(posedge pci_clock) ;
14721
 
14722
            while ( IRDY === 0 )
14723
                @(posedge pci_clock) ;
14724
 
14725 35 mihad
            #1 ;
14726
            if ( !error_monitor_done )
14727
                disable monitor_error_event10 ;
14728 15 mihad
        end
14729
        begin:monitor_error_event10
14730 35 mihad
            error_monitor_done = 0 ;
14731 15 mihad
            @(error_event_int) ;
14732
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14733
            ok = 0 ;
14734 35 mihad
            error_monitor_done = 1 ;
14735 15 mihad
        end
14736
        join
14737
 
14738
        if ( ok )
14739
            test_ok ;
14740
 
14741 26 mihad
        @(posedge pci_clock) ;
14742
        @(posedge pci_clock) ;
14743
        @(posedge wb_clock) ;
14744
        @(posedge wb_clock) ;
14745
 
14746 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14747
        addr_offset = 12'h004 ;
14748
        config_read(addr_offset, 4'hF, read_data) ;
14749
        ok = 1 ;
14750
        if ( read_data[27] !== 1 )
14751
        begin
14752
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14753
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14754
            ok = 0 ;
14755
        end
14756
        if ( read_data[28] !== 0 )
14757
        begin
14758
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14759
            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") ;
14760
            ok = 0 ;
14761
        end
14762
        if ( read_data[29] !== 0 )
14763
        begin
14764
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14765
            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") ;
14766
            ok = 0 ;
14767
        end
14768
 
14769
        // clear statuses
14770
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14771
        if ( !ok )
14772
        begin
14773
            test_fail("write to PCI Device Status register failed") ;
14774
            $display("Couldn't write PCI Device Status register") ;
14775
            disable main ;
14776
        end
14777
 
14778
        if ( ok )
14779
            test_ok ;
14780
 
14781
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14782
 
14783
        ok = 1 ;
14784
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14785
 
14786
        config_read(addr_offset, 4'hF, read_data) ;
14787
        if (read_data[8] !== 0)
14788
        begin
14789
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14790
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14791
            ok = 0 ;
14792
        end
14793
        else
14794
            test_ok ;
14795
 
14796
        if ( ok !== 1 )
14797
        begin
14798
            config_write(addr_offset, read_data, 4'hF, ok) ;
14799
            if ( !ok )
14800
            begin
14801
                test_fail("PCI Error Control and Status register could not be written") ;
14802
                disable main ;
14803
            end
14804
        end
14805
 
14806
        test_name = "DISABLE IMAGE" ;
14807 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14808 15 mihad
        if ( ok !== 1 )
14809
        begin
14810
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14811
            test_fail("PCI Address Mask register could not be written") ;
14812
            disable main;
14813
        end
14814
 
14815
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14816
 
14817
    end
14818
end // main
14819
endtask // test_wb_error_rd
14820
 
14821
task test_target_abort ;
14822
    input [2:0]  image_num ;
14823
    reg   [11:0] pci_ctrl_offset ;
14824
    reg   [11:0] ctrl_offset ;
14825
    reg   [11:0] ba_offset ;
14826
    reg   [11:0] am_offset ;
14827
    reg   [11:0] ta_offset ;
14828
    reg   [31:0] pci_address ;
14829
    reg   [3:0]  byte_enables ;
14830
    reg          ok ;
14831 35 mihad
    reg          error_monitor_done ;
14832 15 mihad
begin:main
14833
    pci_ctrl_offset = 12'h4 ;
14834
    if (image_num === 0)
14835
    begin
14836
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14837
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14838
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14839
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14840
    end
14841
    else if (image_num === 1)
14842
    begin
14843
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14844
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14845
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14846
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14847
    end
14848
    else if (image_num === 2)
14849
    begin
14850
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14851
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14852
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14853
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14854
    end
14855
    else if (image_num === 3)
14856
    begin
14857
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14858
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14859
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14860
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14861
    end
14862
    else if (image_num === 4)
14863
    begin
14864
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14865
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14866
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14867
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14868
    end
14869
    else if (image_num === 5)
14870
    begin
14871
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14872
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14873
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14874
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14875
    end
14876
 
14877
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14878
 
14879
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14880
    if ( ok !== 1 )
14881
    begin
14882
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14883
        test_fail("PCI Base Address register could not be written") ;
14884
        disable main ;
14885
    end
14886
 
14887
    // Set Address Mask of IMAGE
14888
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14889
    if ( ok !== 1 )
14890
    begin
14891
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14892
        test_fail("PCI Address Mask register could not be written") ;
14893
        disable main ;
14894
    end
14895
 
14896
    // Set Translation Address of IMAGE
14897
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14898
    if ( ok !== 1 )
14899
    begin
14900
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14901
        test_fail("PCI Translation Address Register could not be written") ;
14902
        disable main ;
14903
    end
14904
 
14905
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14906
    if ( ok !== 1 )
14907
    begin
14908
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14909
        test_fail("PCI Image Control register could not be written") ;
14910
        disable main ;
14911
    end
14912
 
14913
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14914
 
14915
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14916
 
14917
    pci_address  = Target_Base_Addr_R[image_num] ;
14918
    byte_enables = 4'b0001 ;
14919
 
14920
    fork
14921
    begin
14922
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14923
        do_pause ( 1 ) ;
14924
    end
14925
    begin:monitor_error_event1
14926 35 mihad
        error_monitor_done = 0 ;
14927 15 mihad
        @(error_event_int) ;
14928
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14929
        ok = 0 ;
14930 35 mihad
        error_monitor_done = 1 ;
14931 15 mihad
    end
14932
    begin
14933
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14934
        @(posedge pci_clock) ;
14935 35 mihad
        #1 ;
14936
        if ( !error_monitor_done )
14937
            disable monitor_error_event1 ;
14938 15 mihad
    end
14939
    join
14940
 
14941
    if ( ok )
14942
        test_ok ;
14943
 
14944
    ok = 1 ;
14945
 
14946
    fork
14947
    begin
14948
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14949
        do_pause ( 1 ) ;
14950
    end
14951
    begin:monitor_error_event2
14952 35 mihad
        error_monitor_done = 0 ;
14953 15 mihad
        @(error_event_int) ;
14954
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14955
        ok = 0 ;
14956 35 mihad
        error_monitor_done = 1 ;
14957 15 mihad
    end
14958
    begin
14959
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14960
        @(posedge pci_clock) ;
14961 35 mihad
        #1 ;
14962
        if ( !error_monitor_done )
14963
            disable monitor_error_event2 ;
14964 15 mihad
    end
14965
    join
14966
 
14967
    if ( ok )
14968
        test_ok ;
14969
 
14970
    ok = 1 ;
14971
 
14972
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14973
    byte_enables = 4'b0011 ;
14974
 
14975
    fork
14976
    begin
14977
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14978
        do_pause ( 1 ) ;
14979
    end
14980
    begin:monitor_error_event3
14981 35 mihad
        error_monitor_done = 0 ;
14982 15 mihad
        @(error_event_int) ;
14983
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14984
        ok = 0 ;
14985 35 mihad
        error_monitor_done = 1 ;
14986 15 mihad
    end
14987
    begin
14988
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14989
        @(posedge pci_clock) ;
14990 35 mihad
        if ( !error_monitor_done )
14991
            disable monitor_error_event3 ;
14992 15 mihad
    end
14993
    join
14994
 
14995
    if ( ok )
14996
        test_ok ;
14997
 
14998
    ok = 1 ;
14999
 
15000
    byte_enables = 4'b0000 ;
15001
 
15002
    fork
15003
    begin
15004
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15005
        do_pause ( 1 ) ;
15006
    end
15007
    begin:monitor_error_event4
15008 35 mihad
        error_monitor_done = 0 ;
15009 15 mihad
        @(error_event_int) ;
15010
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15011
        ok = 0 ;
15012 35 mihad
        error_monitor_done = 1 ;
15013 15 mihad
    end
15014
    begin
15015
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15016
        @(posedge pci_clock) ;
15017 35 mihad
        #1 ;
15018
        if ( !error_monitor_done )
15019
            disable monitor_error_event4 ;
15020 15 mihad
    end
15021
    join
15022
 
15023
    if ( ok )
15024
        test_ok ;
15025
 
15026
    ok = 1 ;
15027
 
15028
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15029
    byte_enables = 4'b0111 ;
15030
 
15031
    fork
15032
    begin
15033
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15034
        do_pause ( 1 ) ;
15035
    end
15036
    begin:monitor_error_event5
15037 35 mihad
        error_monitor_done = 0 ;
15038 15 mihad
        @(error_event_int) ;
15039
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15040
        ok = 0 ;
15041 35 mihad
        error_monitor_done = 1 ;
15042 15 mihad
    end
15043
    begin
15044
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15045
        @(posedge pci_clock) ;
15046 35 mihad
        #1 ;
15047
        if ( !error_monitor_done )
15048
            disable monitor_error_event5 ;
15049 15 mihad
    end
15050
    join
15051
 
15052
    if ( ok )
15053
        test_ok ;
15054
 
15055
    ok = 1 ;
15056
 
15057
    byte_enables = 4'b0010 ;
15058
 
15059
    fork
15060
    begin
15061
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15062
        do_pause ( 1 ) ;
15063
    end
15064
    begin:monitor_error_event6
15065 35 mihad
        error_monitor_done = 0 ;
15066 15 mihad
        @(error_event_int) ;
15067
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15068
        ok = 0 ;
15069 35 mihad
        error_monitor_done = 1 ;
15070 15 mihad
    end
15071
    begin
15072
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15073
        @(posedge pci_clock) ;
15074 35 mihad
        #1 ;
15075
        if ( !error_monitor_done )
15076
            disable monitor_error_event6 ;
15077 15 mihad
    end
15078
    join
15079
 
15080
    if ( ok )
15081
        test_ok ;
15082
 
15083
    ok = 1 ;
15084
    byte_enables = 4'b0001 ;
15085
 
15086
    fork
15087
    begin
15088
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15089
        do_pause ( 1 ) ;
15090
    end
15091
    begin:monitor_error_event7
15092 35 mihad
        error_monitor_done = 0 ;
15093 15 mihad
        @(error_event_int) ;
15094
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15095
        ok = 0 ;
15096 35 mihad
        error_monitor_done = 1 ;
15097 15 mihad
    end
15098
    begin
15099
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15100
        @(posedge pci_clock) ;
15101 35 mihad
        #1 ;
15102
        if ( !error_monitor_done )
15103
            disable monitor_error_event7 ;
15104 15 mihad
    end
15105
    join
15106
 
15107
    if ( ok )
15108
        test_ok ;
15109
 
15110
    ok = 1 ;
15111
    byte_enables = 4'b0000 ;
15112
 
15113
    fork
15114
    begin
15115
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15116
        do_pause ( 1 ) ;
15117
    end
15118
    begin:monitor_error_event8
15119 35 mihad
        error_monitor_done = 0 ;
15120 15 mihad
        @(error_event_int) ;
15121
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15122
        ok = 0 ;
15123 35 mihad
        error_monitor_done = 1 ;
15124 15 mihad
    end
15125
    begin
15126
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15127
        @(posedge pci_clock) ;
15128 35 mihad
        #1 ;
15129
        if ( !error_monitor_done )
15130
            disable monitor_error_event8 ;
15131 15 mihad
    end
15132
    join
15133
 
15134
    if ( ok )
15135
        test_ok ;
15136
 
15137
    ok = 1 ;
15138
 
15139
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15140
    byte_enables = 4'b0110 ;
15141
 
15142
    fork
15143
    begin
15144
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15145
        do_pause ( 1 ) ;
15146
    end
15147
    begin:monitor_error_event9
15148 35 mihad
        error_monitor_done = 0 ;
15149 15 mihad
        @(error_event_int) ;
15150
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15151
        ok = 0 ;
15152 35 mihad
        error_monitor_done = 1 ;
15153 15 mihad
    end
15154
    begin
15155
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15156
        @(posedge pci_clock) ;
15157 35 mihad
        #1 ;
15158
        if ( !error_monitor_done )
15159
            disable monitor_error_event9 ;
15160 15 mihad
    end
15161
    join
15162
 
15163
    if ( ok )
15164
        test_ok ;
15165
 
15166
    ok = 1 ;
15167
    fork
15168
    begin
15169
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15170
        do_pause ( 1 ) ;
15171
    end
15172
    begin:monitor_error_event10
15173 35 mihad
        error_monitor_done = 0 ;
15174 15 mihad
        @(error_event_int) ;
15175
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15176
        ok = 0 ;
15177 35 mihad
        error_monitor_done = 1 ;
15178 15 mihad
    end
15179
    begin
15180
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15181
        @(posedge pci_clock) ;
15182 35 mihad
 
15183
        #1 ;
15184
        if ( !error_monitor_done )
15185
            disable monitor_error_event10 ;
15186 15 mihad
    end
15187
    join
15188
 
15189
    if ( ok )
15190
        test_ok ;
15191
 
15192
    ok = 1 ;
15193
 
15194
    byte_enables = 4'b0001 ;
15195
 
15196
    fork
15197
    begin
15198
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15199
        do_pause ( 1 ) ;
15200
    end
15201
    begin:monitor_error_event11
15202 35 mihad
        error_monitor_done = 0 ;
15203 15 mihad
        @(error_event_int) ;
15204
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15205
        ok = 0 ;
15206 35 mihad
        error_monitor_done = 1 ;
15207 15 mihad
    end
15208
    begin
15209
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15210
        @(posedge pci_clock) ;
15211 35 mihad
        #1 ;
15212
        if ( !error_monitor_done )
15213
            disable monitor_error_event11 ;
15214 15 mihad
    end
15215
    join
15216
 
15217
    if ( ok )
15218
        test_ok ;
15219
 
15220
    ok = 1 ;
15221
 
15222
    byte_enables = 4'b0101 ;
15223
 
15224
    fork
15225
    begin
15226
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15227
        do_pause ( 1 ) ;
15228
    end
15229
    begin:monitor_error_event12
15230 35 mihad
        error_monitor_done = 0 ;
15231 15 mihad
        @(error_event_int) ;
15232
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15233
        ok = 0 ;
15234 35 mihad
        error_monitor_done = 1 ;
15235 15 mihad
    end
15236
    begin
15237
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15238
        @(posedge pci_clock) ;
15239 35 mihad
        #1 ;
15240
        if ( !error_monitor_done )
15241
            disable monitor_error_event12 ;
15242 15 mihad
    end
15243
    join
15244
 
15245
    if ( ok )
15246
        test_ok ;
15247
 
15248
    ok = 1 ;
15249
 
15250
    byte_enables = 4'b0011 ;
15251
 
15252
    fork
15253
    begin
15254
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15255
        do_pause ( 1 ) ;
15256
    end
15257
    begin:monitor_error_event13
15258 35 mihad
        error_monitor_done = 0 ;
15259 15 mihad
        @(error_event_int) ;
15260
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15261
        ok = 0 ;
15262 35 mihad
        error_monitor_done = 1 ;
15263 15 mihad
    end
15264
    begin
15265
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15266
        @(posedge pci_clock) ;
15267 35 mihad
        #1 ;
15268
        if ( !error_monitor_done )
15269
            disable monitor_error_event13 ;
15270 15 mihad
    end
15271
    join
15272
 
15273
    if ( ok )
15274
        test_ok ;
15275
 
15276
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15277
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15278
    ok = 1 ;
15279
    if ( pci_address[27] !== 1 )
15280
    begin
15281
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15282
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15283
        ok = 0 ;
15284
    end
15285
    if ( pci_address[28] !== 0 )
15286
    begin
15287
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15288
        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") ;
15289
        ok = 0 ;
15290
    end
15291
    if ( pci_address[29] !== 0 )
15292
    begin
15293
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15294
        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") ;
15295
        ok = 0 ;
15296
    end
15297
 
15298
    // clear statuses
15299
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15300
    if ( !ok )
15301
    begin
15302
        test_fail("write to PCI Device Status register failed") ;
15303
        $display("Couldn't write PCI Device Status register") ;
15304
        disable main ;
15305
    end
15306
 
15307
    if ( ok )
15308
        test_ok ;
15309
 
15310
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15311
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15312
    if ( pci_address[8] !== 0 )
15313
    begin
15314
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15315
    end
15316
    else
15317
        test_ok ;
15318
 
15319
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15320
 
15321
    test_name = "DISABLE IMAGE" ;
15322
 
15323 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15324 15 mihad
    if ( ok !== 1 )
15325
    begin
15326
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15327
        test_fail("PCI Address Mask register could not be written") ;
15328
        disable main ;
15329
    end
15330
end
15331
endtask // test_target_abort
15332
 
15333
task test_target_io_wr_rd ;
15334
    input [2:0]  image_num ;
15335
    input        translate_address ;
15336
    input [11:0] img_ctrl_offset ;
15337
    reg   [31:0] expect_address ;
15338
    reg   [31:0] pci_address ;
15339
    reg          translation ;
15340
    reg   [31:0] read_data ;
15341
    reg   [3:0]  byte_enables ;
15342
    reg          ok ;
15343
    reg          pci_ok ;
15344
    reg          wb_ok ;
15345
    integer      i ;
15346 35 mihad
    reg          error_monitor_done ;
15347 15 mihad
begin:main
15348
    `ifdef ADDR_TRAN_IMPL
15349
        translation = translate_address ;
15350
    `else
15351
        translation = 0 ;
15352
    `endif
15353
 
15354
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15355
 
15356
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15357
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15358
    if ( translation )
15359
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15360
    else
15361
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15362
 
15363
    if ( !ok )
15364
    begin
15365
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15366
        test_fail("PCI Image Control register could not be written") ;
15367
    end
15368
 
15369
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15370
    pci_address  = Target_Base_Addr_R[image_num] ;
15371
    byte_enables = 4'b0000 ;
15372
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15373
 
15374
    fork
15375
    begin
15376
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15377
        do_pause ( 1 ) ;
15378
    end
15379
    begin
15380
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15381
        if ( wb_ok !== 1 )
15382
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15383
 
15384 35 mihad
        #1 ;
15385
        if ( !error_monitor_done )
15386
            disable monitor_pci_error_1 ;
15387 15 mihad
    end
15388
    begin:monitor_pci_error_1
15389 35 mihad
        error_monitor_done = 0 ;
15390 15 mihad
        pci_ok = 1 ;
15391
        @(error_event_int) ;
15392
        pci_ok = 0 ;
15393
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15394 35 mihad
        error_monitor_done = 1 ;
15395 15 mihad
    end
15396
    join
15397
 
15398
    byte_enables = 4'b1111 ;
15399
    for ( i = 0 ; i < 4 ; i = i + 1 )
15400
    begin:loop_1
15401
        byte_enables[i] = 0 ;
15402
        if ( i > 0 )
15403
            byte_enables[i - 1] = 1 ;
15404
        fork
15405
        begin
15406
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15407
            do_pause ( 1 ) ;
15408
        end
15409
        begin
15410
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15411
            if ( wb_ok !== 1 )
15412
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15413
 
15414 35 mihad
            #1 ;
15415
            if ( !error_monitor_done )
15416
                disable monitor_pci_error_2 ;
15417 15 mihad
        end
15418
        begin:monitor_pci_error_2
15419 35 mihad
            error_monitor_done = 0 ;
15420 15 mihad
            pci_ok = 1 ;
15421
            @(error_event_int) ;
15422
            pci_ok = 0 ;
15423
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15424 35 mihad
            error_monitor_done = 1 ;
15425 15 mihad
        end
15426
        join
15427
 
15428
        if ( !pci_ok || !wb_ok )
15429
            disable loop_1 ;
15430
 
15431
        pci_address = pci_address + 1 ;
15432
        expect_address = expect_address + 1 ;
15433
    end
15434
 
15435
    if ( pci_ok && wb_ok )
15436
        test_ok ;
15437
 
15438
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15439
    pci_address  = Target_Base_Addr_R[image_num] ;
15440
    byte_enables = 4'b1100 ;
15441
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15442
 
15443
    master1_check_received_data = 1 ;
15444
    fork
15445
    begin
15446
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15447
        do_pause( 1 ) ;
15448
    end
15449
    begin
15450
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15451
        if ( wb_ok !== 1 )
15452
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15453
 
15454
        do_pause ( 2 ) ;
15455
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15456
        do_pause ( 16 ) ;
15457
 
15458 35 mihad
        #1 ;
15459
        if ( !error_monitor_done )
15460
            disable monitor_pci_error_3 ;
15461 15 mihad
    end
15462
    begin:monitor_pci_error_3
15463 35 mihad
        error_monitor_done = 0 ;
15464 15 mihad
        pci_ok = 1 ;
15465
        @(error_event_int) ;
15466
        pci_ok = 0 ;
15467
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15468 35 mihad
        error_monitor_done = 1 ;
15469 15 mihad
    end
15470
    join
15471
 
15472
    if ( !pci_ok || !wb_ok )
15473
    begin
15474
        disable main ;
15475
    end
15476
 
15477
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15478
    byte_enables = 4'b0011 ;
15479
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15480
 
15481
    master1_check_received_data = 1 ;
15482
    fork
15483
    begin
15484
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15485
        do_pause( 1 ) ;
15486
    end
15487
    begin
15488
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15489
        if ( wb_ok !== 1 )
15490
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15491
 
15492
        do_pause ( 2 ) ;
15493
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15494
        do_pause ( 16 ) ;
15495
 
15496 35 mihad
        #1 ;
15497
        if ( !error_monitor_done )
15498
            disable monitor_pci_error_4 ;
15499 15 mihad
    end
15500
    begin:monitor_pci_error_4
15501 35 mihad
        error_monitor_done = 0 ;
15502 15 mihad
        pci_ok = 1 ;
15503
        @(error_event_int) ;
15504
        pci_ok = 0 ;
15505
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15506 35 mihad
        error_monitor_done = 1 ;
15507 15 mihad
    end
15508
    join
15509
 
15510
    if ( !pci_ok || !wb_ok )
15511
    begin
15512
        disable main ;
15513
    end
15514
 
15515
    pci_address  = Target_Base_Addr_R[image_num] ;
15516
    byte_enables = 4'b0000 ;
15517
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15518
 
15519
    master1_check_received_data = 1 ;
15520
    fork
15521
    begin
15522
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15523
        do_pause( 1 ) ;
15524
    end
15525
    begin
15526
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15527
        if ( wb_ok !== 1 )
15528
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15529
 
15530
        do_pause ( 2 ) ;
15531
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15532
        do_pause ( 16 ) ;
15533
 
15534 35 mihad
        #1 ;
15535
        if ( !error_monitor_done )
15536
            disable monitor_pci_error_5 ;
15537 15 mihad
    end
15538
    begin:monitor_pci_error_5
15539 35 mihad
        error_monitor_done = 0 ;
15540 15 mihad
        pci_ok = 1 ;
15541
        @(error_event_int) ;
15542
        pci_ok = 0 ;
15543
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15544 35 mihad
        error_monitor_done = 1 ;
15545 15 mihad
    end
15546
    join
15547
 
15548
    if ( pci_ok && wb_ok )
15549
        test_ok ;
15550
end
15551
endtask // test_target_io_wr_rd
15552
 
15553
task test_target_io_err_wr ;
15554
    input [2:0]  image_num ;
15555
    input        translate_address ;
15556
    input [11:0] img_ctrl_offset ;
15557
    input        enable_error_report ;
15558
    input        enable_error_interrupt ;
15559
 
15560
    reg   [31:0] expect_address ;
15561
    reg   [31:0] pci_address ;
15562
    reg          translation ;
15563
    reg   [31:0] read_data ;
15564
    reg   [3:0]  byte_enables ;
15565
    reg          ok ;
15566
    reg          pci_ok ;
15567
    reg          wb_ok ;
15568
    integer      i ;
15569
    reg   [11:0] offset ;
15570 35 mihad
    reg          error_monitor_done ;
15571 15 mihad
begin:main
15572
    `ifdef ADDR_TRAN_IMPL
15573
        translation = translate_address ;
15574
    `else
15575
        translation = 0 ;
15576
    `endif
15577
 
15578
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15579
 
15580
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15581
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15582
    if ( translation )
15583
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15584
    else
15585
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15586
 
15587
    if ( !ok )
15588
    begin
15589
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15590
        test_fail("PCI Image Control register could not be written") ;
15591
    end
15592
 
15593
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15594
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15595
    if ( enable_error_report )
15596
    begin
15597
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15598
        if ( !ok )
15599
        begin
15600
            test_fail("PCI Error Control and Status register could not be written") ;
15601
            disable main ;
15602
        end
15603
    end
15604
    else
15605
    begin
15606
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15607
        if ( !ok )
15608
        begin
15609
            test_fail("PCI Error Control and Status register could not be written") ;
15610
            disable main ;
15611
        end
15612
    end
15613
 
15614
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15615
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15616
    if ( enable_error_interrupt )
15617
    begin
15618
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15619
        if ( !ok )
15620
        begin
15621
            test_fail("Interrupt Control register could not be written") ;
15622
            disable main ;
15623
        end
15624
    end
15625
    else
15626
    begin
15627
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15628
        if ( !ok )
15629
        begin
15630
            test_fail("Interrupt Control register could not be written") ;
15631
            disable main ;
15632
        end
15633
    end
15634
 
15635
    pci_address  = Target_Base_Addr_R[image_num] ;
15636
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15637
 
15638
    byte_enables = 4'b1111 ;
15639
 
15640
    for ( i = 0 ; i < 4 ; i = i + 1 )
15641
    begin:loop_1
15642
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15643
        byte_enables[i] = 0 ;
15644
        if ( i > 0 )
15645
            byte_enables[i - 1] = 1 ;
15646
 
15647
        fork
15648
        begin
15649
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15650
            do_pause ( 1 ) ;
15651
        end
15652
        begin
15653
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15654
            if ( wb_ok !== 1 )
15655
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15656
 
15657 35 mihad
            #1 ;
15658
            if ( !error_monitor_done )
15659
                disable monitor_pci_error_2 ;
15660 15 mihad
        end
15661
        begin:monitor_pci_error_2
15662 35 mihad
            error_monitor_done = 0 ;
15663 15 mihad
            pci_ok = 1 ;
15664
            @(error_event_int) ;
15665
            pci_ok = 0 ;
15666
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15667 35 mihad
            error_monitor_done = 1 ;
15668 15 mihad
        end
15669
        join
15670
 
15671
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15672
        `ifdef HOST
15673
 
15674
            repeat ( 4 )
15675
                @( posedge wb_clock ) ;
15676
 
15677
            if ( enable_error_interrupt && enable_error_report )
15678
            begin
15679
                if ( INT_O !== 1 )
15680
                begin
15681
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15682
                end
15683
            end
15684
            else
15685
            begin
15686
                if ( INT_O !== 0 )
15687
                begin
15688
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15689
                end
15690
            end
15691
        `else
15692
            repeat ( 4 )
15693
                @( posedge pci_clock ) ;
15694
 
15695
            if ( enable_error_interrupt && enable_error_report )
15696
            begin
15697
                if ( INTA !== 0 )
15698
                begin
15699
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15700
                end
15701
            end
15702
            else
15703
            begin
15704
                if ( INTA !== 1 )
15705
                begin
15706
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15707
                end
15708
            end
15709
        `endif
15710
 
15711
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15712
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15713
        config_read( offset, 4'hF, read_data ) ;
15714
        ok = 1 ;
15715
        if ( enable_error_report )
15716
        begin
15717
            if ( read_data[8] !== 1 )
15718
            begin
15719
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15720
                ok = 0 ;
15721
            end
15722
 
15723
            if ( read_data[9] !== 0 )
15724
            begin
15725
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15726
                ok = 0 ;
15727
            end
15728
 
15729
            if ( read_data[31:28] !== byte_enables )
15730
            begin
15731
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15732
                ok = 0 ;
15733
            end
15734
 
15735
            if ( read_data[27:24] !== `BC_IO_WRITE )
15736
            begin
15737
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15738
                ok = 0 ;
15739
            end
15740
 
15741
            if ( ok )
15742
                test_ok ;
15743
 
15744
            test_name = "CLEAR ERROR STATUS" ;
15745
            config_write( offset, read_data, 4'hF, ok ) ;
15746
            if ( !ok )
15747
                test_fail("PCI Error Control and Status register could not be written") ;
15748
 
15749
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15750
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15751
            config_read ( offset, 4'hf, read_data ) ;
15752
 
15753
            if ( read_data !== expect_address )
15754
            begin
15755
                test_fail("value in Erroneous Address register was incorrect") ;
15756
                ok = 0 ;
15757
            end
15758
 
15759
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15760
            config_read ( offset, 4'hf, read_data ) ;
15761
 
15762
            if ( read_data !== 32'hAAAA_AAAA )
15763
            begin
15764
                test_fail("value in Erroneous Data register was incorrect") ;
15765
                ok = 0 ;
15766
            end
15767
 
15768
            if ( ok )
15769
                test_ok ;
15770
 
15771
        end
15772
        else
15773
        begin
15774
            if ( read_data[8] !== 0 )
15775
            begin
15776
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15777
                ok = 0 ;
15778
            end
15779
            else
15780
                test_ok ;
15781
        end
15782
 
15783
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15784
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15785
        ok = 1 ;
15786
 
15787
        config_read ( offset, 4'hF, read_data ) ;
15788
        if ( enable_error_report && enable_error_interrupt )
15789
        begin
15790
            if ( read_data[2] !== 1 )
15791
            begin
15792
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15793
                ok = 0 ;
15794
            end
15795
 
15796
            test_name = "CLEARING INTERRUPT STATUS" ;
15797
            config_write( offset, read_data, 4'hF, ok ) ;
15798
            if ( !ok )
15799
                test_fail("Interrupt Status register could not be written") ;
15800
        end
15801
        else
15802
        begin
15803
            if ( read_data[2] !== 0 )
15804
            begin
15805
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15806
                ok = 0 ;
15807
            end
15808
        end
15809
 
15810
        if ( ok )
15811
            test_ok ;
15812
 
15813
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15814
        `ifdef HOST
15815
 
15816
            repeat ( 4 )
15817
                @( posedge wb_clock ) ;
15818
 
15819
            if ( INT_O !== 0 )
15820
            begin
15821
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15822
            end
15823
            else
15824
                test_ok ;
15825
 
15826
        `else
15827
            repeat ( 4 )
15828
                @( posedge pci_clock ) ;
15829
 
15830
            if ( INTA !== 1 )
15831
            begin
15832
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15833
            end
15834
            else
15835
                test_ok ;
15836
 
15837
        `endif
15838
 
15839
        pci_address = pci_address + 1 ;
15840
        expect_address = expect_address + 1 ;
15841
    end
15842
 
15843
end
15844
endtask // test_target_io_err_wr
15845
 
15846
task test_pci_image ;
15847
    input [2:0]  image_num ;
15848
    reg   [11:0] pci_ctrl_offset ;
15849
    reg   [11:0] ctrl_offset ;
15850
    reg   [11:0] ba_offset ;
15851
    reg   [11:0] am_offset ;
15852
    reg   [11:0] ta_offset ;
15853
    reg   [7:0]  cache_lsize ;
15854
    reg          ok ;
15855
    reg          test_io ;
15856
    reg          test_mem ;
15857
begin
15858
    pci_ctrl_offset = 12'h4 ;
15859
    if (image_num === 0)
15860
    begin
15861
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15862
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15863
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15864
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15865
    end
15866
    else if (image_num === 1)
15867
    begin
15868
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15869
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15870
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15871
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15872
    end
15873
    else if (image_num === 2)
15874
    begin
15875
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15876
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15877
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15878
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15879
    end
15880
    else if (image_num === 3)
15881
    begin
15882
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15883
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15884
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15885
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15886
    end
15887
    else if (image_num === 4)
15888
    begin
15889
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15890
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15891
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15892
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15893
    end
15894
    else if (image_num === 5)
15895
    begin
15896
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15897
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15898
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15899
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15900
    end
15901
 
15902
    `ifdef HOST
15903
        test_io  = 1 ;
15904
        test_mem = 1 ;
15905
    `else
15906
        if (image_num == 1)
15907
            test_io = `PCI_BA1_MEM_IO ;
15908
        else if ( image_num == 2 )
15909
            test_io = `PCI_BA2_MEM_IO ;
15910
        else if ( image_num == 3 )
15911
            test_io = `PCI_BA3_MEM_IO ;
15912
        else if ( image_num == 4 )
15913
            test_io = `PCI_BA4_MEM_IO ;
15914
        else if ( image_num == 5 )
15915
            test_io = `PCI_BA5_MEM_IO ;
15916
 
15917
        test_mem = !test_io ;
15918
    `endif
15919
 
15920
    $display(" ");
15921
    $display("########################################################################") ;
15922
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15923
    test_name = "PCI IMAGE SETTINGS" ;
15924
 
15925
    // Set Base Address of IMAGE
15926
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15927
    if ( ok !== 1 )
15928
    begin
15929
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15930
        test_fail("PCI Base Address register could not be written") ;
15931
    end
15932
 
15933
    // Set Address Mask of IMAGE
15934
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15935
    if ( ok !== 1 )
15936
    begin
15937
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15938
        test_fail("PCI Address Mask register could not be written") ;
15939
    end
15940
 
15941
    // Set Translation Address of IMAGE
15942
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15943
    if ( ok !== 1 )
15944
    begin
15945
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15946
        test_fail("PCI Translation Address register could not be written") ;
15947
    end
15948
 
15949
// Following are defines for byte enable signals !
15950
//      Byte Masks
15951
//      `Test_Byte_0                            (4'b1110)
15952
//      `Test_Byte_1                            (4'b1101)
15953
//      `Test_Byte_2                            (4'b1011)
15954
//      `Test_Byte_3                            (4'b0111)
15955
//      `Test_Half_0                            (4'b1100)
15956
//      `Test_Half_1                            (4'b0011)
15957
//      `Test_All_Bytes                         (4'b0000)
15958
 
15959
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15960
    // Set Cache Line Size
15961
    cache_lsize = 8'h4 ;
15962
 
15963
    $display(" ");
15964
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15965
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15966
    if ( ok !== 1 )
15967
    begin
15968
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15969
        test_fail("PCI Device Control and Status register could not be written") ;
15970
    end
15971
 
15972
    if (test_mem)
15973
    begin
15974
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15975
        // Task test_normal_wr_rd has the following parameters:
15976
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15977
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15978
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15979
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15980
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15981
 
15982
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15983
        // Set Cache Line Size
15984
        cache_lsize = 8'h4 ;
15985
 
15986
        $display(" ");
15987
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15988
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15989
        if ( ok !== 1 )
15990
        begin
15991
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15992
            test_fail("Cache Line Size register could not be written" ) ;
15993
        end
15994
 
15995
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15996
        // Task test_normal_wr_rd has the following parameters:
15997
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15998
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15999
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16000
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
16001
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
16002
 
16003
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16004
        // Set Cache Line Size
16005
        cache_lsize = 8'h8 ;
16006
 
16007
        $display(" ");
16008
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16009
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16010
        if ( ok !== 1 )
16011
        begin
16012
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16013
            test_fail("Cache Line Size register could not be written" ) ;
16014
        end
16015
 
16016
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16017
        // Task test_normal_wr_rd has the following parameters:
16018
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16019
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16020
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16021
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16022
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16023
 
16024
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16025
        // Set Cache Line Size
16026
        cache_lsize = 8'h4 ;
16027
 
16028
        $display(" ");
16029
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16030
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16031
        if ( ok !== 1 )
16032
        begin
16033
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16034
            test_fail("Cache Line Size register could not be written" ) ;
16035
        end
16036
 
16037
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16038
        // Task test_normal_wr_rd has the following parameters:
16039
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16040
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16041
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16042
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16043
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16044
 
16045
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16046
        $display(" ");
16047
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16048
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16049
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16050
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16051
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16052
 
16053
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16054
        $display(" ");
16055
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16056
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16057
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16058
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16059
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16060
 
16061
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16062
        $display(" ");
16063
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16064
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16065
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16066
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16067
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16068
 
16069
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16070
        $display(" ");
16071
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16072
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16073
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16074
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16075
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16076
    end
16077
 
16078
    if ( test_io )
16079
    begin
16080
        test_name = "PCI IMAGE SETTINGS" ;
16081
 
16082
        // Set Base Address of IMAGE
16083
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16084
        if ( ok !== 1 )
16085
        begin
16086
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16087
            test_fail("PCI Base Address register could not be written") ;
16088
        end
16089
 
16090
        // Set Address Mask of IMAGE
16091
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16092
        if ( ok !== 1 )
16093
        begin
16094
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16095
            test_fail("PCI Address Mask register could not be written") ;
16096
        end
16097
 
16098
        // Set Translation Address of IMAGE
16099
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16100
        if ( ok !== 1 )
16101
        begin
16102
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16103
            test_fail("PCI Translation Address register could not be written") ;
16104
        end
16105
 
16106
        // Set Cache Line Size
16107
        cache_lsize = 8'h4 ;
16108
 
16109
        $display(" ");
16110
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16111
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16112
        if ( ok !== 1 )
16113
        begin
16114
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16115
            test_fail("Cache Line Size register could not be written" ) ;
16116
        end
16117
 
16118
        test_target_io_wr_rd
16119
        (
16120
            image_num,    // image number
16121
            0,            // test with address translation
16122
            ctrl_offset   // image control register offset
16123
        ) ;
16124
 
16125
        test_target_io_wr_rd
16126
        (
16127
            image_num,    // image number
16128
            1,            // test with address translation
16129
            ctrl_offset   // image control register offset
16130
        ) ;
16131
 
16132
        test_target_io_err_wr
16133
        (
16134
            image_num,      // image number
16135
            0,              // address translation on/off
16136
            ctrl_offset,    // image control register offset
16137
            0,              // enable error reporting
16138
 
16139
        ) ;
16140
 
16141
        test_target_io_err_wr
16142
        (
16143
            image_num,      // image number
16144
            1,              // address translation on/off
16145
            ctrl_offset,    // image control register offset
16146
            0,              // enable error reporting
16147
            1               // enable error interrupts
16148
        ) ;
16149
 
16150
        test_target_io_err_wr
16151
        (
16152
            image_num,      // image number
16153
            0,              // address translation on/off
16154
            ctrl_offset,    // image control register offset
16155
            1,              // enable error reporting
16156
 
16157
        ) ;
16158
 
16159
        test_target_io_err_wr
16160
        (
16161
            image_num,      // image number
16162
            1,              // address translation on/off
16163
            ctrl_offset,    // image control register offset
16164
            1,              // enable error reporting
16165
            1               // enable error interrupts
16166
        ) ;
16167
    end
16168
 
16169
    // Test master abort with NON supported commands
16170
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16171
 
16172
    // disable the image
16173 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16174 15 mihad
end
16175
endtask //test_pci_image
16176
 
16177
task target_fast_back_to_back ;
16178
    reg   [11:0] pci_ctrl_offset ;
16179
    reg   [11:0] ctrl_offset ;
16180
    reg   [11:0] ba_offset ;
16181
    reg   [11:0] am_offset ;
16182
    reg   [11:0] ta_offset ;
16183
    reg   [11:0] cls_offset ;
16184
    reg          do_mem_fb2b ;
16185
    reg          do_io_fb2b ;
16186
    reg          ok ;
16187
begin:main
16188
 
16189
    if ( target_mem_image !== -1 )
16190
    begin
16191
        do_mem_fb2b = 1 ;
16192
 
16193
        if (target_mem_image === 1)
16194
        begin
16195
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16196
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16197
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16198
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16199
        end
16200
        else if (target_mem_image === 2)
16201
        begin
16202
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16203
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16204
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16205
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16206
        end
16207
        else if (target_mem_image === 3)
16208
        begin
16209
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16210
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16211
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16212
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16213
        end
16214
        else if (target_mem_image === 4)
16215
        begin
16216
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16217
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16218
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16219
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16220
        end
16221
        else if (target_mem_image === 5)
16222
        begin
16223
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16224
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16225
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16226
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16227
        end
16228
    end
16229
    else
16230
        do_mem_fb2b = 0 ;
16231
 
16232
    pci_ctrl_offset = 12'h4 ;
16233
    cls_offset      = 12'h00C ;
16234
 
16235
    if ( do_mem_fb2b )
16236
    begin
16237
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16238
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16239
        if ( ok !== 1 )
16240
        begin
16241
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16242
            test_fail("PCI Base Address register could not be written") ;
16243
            disable main ;
16244
        end
16245
 
16246
        // Set Address Mask of IMAGE
16247
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16248
        if ( ok !== 1 )
16249
        begin
16250
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16251
            test_fail("PCI Address Mask register could not be written") ;
16252
            disable main ;
16253
        end
16254
 
16255
        // Set Translation Address of IMAGE
16256
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16257
        if ( ok !== 1 )
16258
        begin
16259
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16260
            test_fail("PCI Translation Address Register could not be written") ;
16261
            disable main ;
16262
        end
16263
 
16264
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16265
        if ( ok !== 1 )
16266
        begin
16267
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16268
            test_fail("PCI Image Control register could not be written") ;
16269
            disable main ;
16270
        end
16271
 
16272
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16273
        if ( ok !== 1 )
16274
        begin
16275
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16276
            test_fail("Cache Line Size register could not be written") ;
16277
            disable main ;
16278
        end
16279
 
16280
        // enable master 1 fast_b2b
16281 45 mihad
        configuration_cycle_write(0,                        // bus number
16282
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16283
                                  0,                        // function number
16284
                                  1,                        // register number
16285
                                  0,                        // type of configuration cycle
16286
                                  4'b1111,                  // byte enables
16287
                                  32'hFFFF_FFFF             // data
16288 15 mihad
                                 ) ;
16289
 
16290
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16291
 
16292
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16293
        fork
16294
        begin
16295
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16296
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16297
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16298
                  0, `Test_One_Zero_Target_WS,
16299
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16300
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16301
 
16302
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16303
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16304
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16305
                  0, `Test_One_Zero_Target_WS,
16306
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16307
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16308
            do_pause(5) ;
16309
 
16310
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16311
        end
16312
        begin:wb_monitor1
16313
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16314
            if ( ok !== 1 )
16315
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16316
 
16317
            disable monitor_error_event1 ;
16318
        end
16319
        begin:monitor_error_event1
16320
            @(error_event_int) ;
16321
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16322
            ok = 0 ;
16323
            disable wb_monitor1 ;
16324
        end
16325
        join
16326
 
16327
        if ( ok )
16328
            test_ok ;
16329
 
16330
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16331
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16332
        fork
16333
        begin
16334
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16335
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16336
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16337
                  0, `Test_One_Zero_Target_WS,
16338
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16339
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16340
 
16341
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16342
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16343
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16344
                  0, `Test_One_Zero_Target_WS,
16345
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16346
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16347
            do_pause(5) ;
16348
 
16349
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16350
 
16351
        end
16352
        begin:wb_monitor2
16353
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16354
            if ( ok !== 1 )
16355
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16356
            else
16357
            begin
16358
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16359
                if ( ok !== 1 )
16360
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16361
            end
16362
 
16363
            disable monitor_error_event2 ;
16364
        end
16365
        begin:monitor_error_event2
16366
            @(error_event_int) ;
16367
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16368
            ok = 0 ;
16369
            disable wb_monitor2 ;
16370
        end
16371
        join
16372
 
16373
        if ( ok )
16374
            test_ok ;
16375
 
16376
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16377
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16378
        fork
16379
        begin
16380
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16381
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16382
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16383
                  0, `Test_One_Zero_Target_WS,
16384
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16385
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16386
 
16387
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16388
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16389
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16390
                  0, `Test_One_Zero_Target_WS,
16391
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16392
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16393
            do_pause(5) ;
16394
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16395
 
16396
        end
16397
        begin:wb_monitor3
16398
            fork
16399
            begin
16400
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16401
                if ( ok !== 1 )
16402
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16403
            end
16404
            begin
16405
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16406
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16407
                if ( ok !== 1 )
16408
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16409
            end
16410
            join
16411
 
16412
            if ( ok )
16413
            begin
16414
                fork
16415
                begin
16416
                    do_pause(3) ;
16417
 
16418
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16419
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16420
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16421
                        0, `Test_One_Zero_Target_WS,
16422
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16423
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16424
 
16425
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16426
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16427
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16428
                            0, `Test_One_Zero_Target_WS,
16429
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16430
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16431
 
16432
                    do_pause(1) ;
16433
                end
16434
                begin
16435
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16436
                    if ( ok !== 1 )
16437
                    begin
16438
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16439
                        disable monitor_error_event3 ;
16440
                    end
16441
                    else
16442
                    begin
16443
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16444
                        if ( ok !== 1 )
16445
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16446
                    end
16447
                end
16448 26 mihad
                begin
16449
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16450
                        if ( ok !== 1 )
16451
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16452
                end
16453 15 mihad
                join
16454
            end
16455
            disable monitor_error_event3 ;
16456
        end
16457
        begin:monitor_error_event3
16458
            @(error_event_int) ;
16459
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16460
            ok = 0 ;
16461
            disable wb_monitor3 ;
16462
        end
16463
        join
16464
 
16465
        if ( ok )
16466
            test_ok ;
16467
 
16468
        test_name = "DISABLING MEM IMAGE" ;
16469 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16470 15 mihad
        if ( ok !== 1 )
16471
        begin
16472
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16473
            test_fail("PCI Address Mask register could not be written") ;
16474
            disable main ;
16475
        end
16476
    end
16477
 
16478
    if ( target_io_image !== -1 )
16479
    begin
16480
        do_io_fb2b = 1 ;
16481
 
16482
        if (target_io_image === 1)
16483
        begin
16484
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16485
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16486
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16487
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16488
        end
16489
        else if (target_io_image === 2)
16490
        begin
16491
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16492
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16493
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16494
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16495
        end
16496
        else if (target_io_image === 3)
16497
        begin
16498
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16499
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16500
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16501
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16502
        end
16503
        else if (target_io_image === 4)
16504
        begin
16505
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16506
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16507
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16508
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16509
        end
16510
        else if (target_io_image === 5)
16511
        begin
16512
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16513
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16514
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16515
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16516
        end
16517
    end
16518
    else
16519
        do_io_fb2b = 0 ;
16520
 
16521
    if ( do_io_fb2b )
16522
    begin
16523
 
16524
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16525
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16526
        if ( ok !== 1 )
16527
        begin
16528
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16529
            test_fail("PCI Base Address register could not be written") ;
16530
            disable main ;
16531
        end
16532
 
16533
        // Set Address Mask of IMAGE
16534
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16535
        if ( ok !== 1 )
16536
        begin
16537
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16538
            test_fail("PCI Address Mask register could not be written") ;
16539
            disable main ;
16540
        end
16541
 
16542
        // Set Translation Address of IMAGE
16543
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16544
        if ( ok !== 1 )
16545
        begin
16546
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16547
            test_fail("PCI Translation Address Register could not be written") ;
16548
            disable main ;
16549
        end
16550
 
16551
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16552
        if ( ok !== 1 )
16553
        begin
16554
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16555
            test_fail("PCI Image Control register could not be written") ;
16556
            disable main ;
16557
        end
16558
 
16559
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16560
        if ( ok !== 1 )
16561
        begin
16562
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16563
            test_fail("Cache Line Size register could not be written") ;
16564
            disable main ;
16565
        end
16566
 
16567
        // enable master 1 fast_b2b
16568 45 mihad
        configuration_cycle_write(0,                        // bus number
16569
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16570
                                  0,                        // function number
16571
                                  1,                        // register number
16572
                                  0,                        // type of configuration cycle
16573
                                  4'b1111,                  // byte enables
16574
                                  32'hFFFF_FFFF             // data
16575 15 mihad
                                 ) ;
16576
 
16577
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16578
 
16579
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16580
        fork
16581
        begin
16582
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16583
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 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_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16590
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16591
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16592
                  0, `Test_One_Zero_Target_WS,
16593
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16594
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16595
            do_pause(5) ;
16596
 
16597
        end
16598
        begin:wb_monitor4
16599
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16600
            if ( ok !== 1 )
16601
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16602
 
16603
            if ( ok )
16604
            begin
16605
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16606
                if ( ok !== 1 )
16607
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16608
            end
16609
 
16610
            disable monitor_error_event4 ;
16611
        end
16612
        begin:monitor_error_event4
16613
            @(error_event_int) ;
16614
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16615
            ok = 0 ;
16616
            disable wb_monitor4 ;
16617
        end
16618
        join
16619
 
16620
        if ( ok )
16621
            test_ok ;
16622
 
16623
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16624
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16625
        fork
16626
        begin
16627
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16628
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16629
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16630
                  0, `Test_One_Zero_Target_WS,
16631
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16632
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16633
 
16634
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16635
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16636
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16637
                  0, `Test_One_Zero_Target_WS,
16638
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16639
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16640
            do_pause(5) ;
16641
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16642
        end
16643
        begin:wb_monitor5
16644
            fork
16645
            begin
16646
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16647
                if ( ok !== 1 )
16648
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16649
            end
16650
            begin
16651
                wb_transaction_stop( 1 ) ;
16652
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16653
                if ( ok !== 1 )
16654
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16655
            end
16656
            join
16657
 
16658
            if ( ok )
16659
            begin
16660
                fork
16661
                begin
16662
                    do_pause(3) ;
16663
 
16664
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16665
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16666
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16667
                            0, `Test_One_Zero_Target_WS,
16668
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16669
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16670
 
16671
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16672
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16673
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16674
                            0, `Test_One_Zero_Target_WS,
16675
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16676
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16677
 
16678
                    do_pause(1) ;
16679
                end
16680
                begin
16681
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16682
                    if ( ok !== 1 )
16683
                    begin
16684
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16685
                        disable monitor_error_event5 ;
16686
                    end
16687
                    else
16688
                    begin
16689
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16690
                        if ( ok !== 1 )
16691
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16692
                    end
16693
                end
16694
                join
16695
            end
16696
            disable monitor_error_event5 ;
16697
        end
16698
        begin:monitor_error_event5
16699
            @(error_event_int) ;
16700
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16701
            ok = 0 ;
16702
            disable wb_monitor5 ;
16703
        end
16704
        join
16705
 
16706
        if ( ok )
16707
            test_ok ;
16708
 
16709
        test_name = "DISABLING IO IMAGE" ;
16710 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16711 15 mihad
        if ( ok !== 1 )
16712
        begin
16713
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16714
            test_fail("PCI Address Mask register could not be written") ;
16715
            disable main ;
16716
        end
16717
    end
16718
 
16719
end
16720
endtask //target_fast_back_to_back
16721
 
16722
task target_disconnects ;
16723
    reg   [11:0] pci_ctrl_offset ;
16724
    reg   [11:0] ctrl_offset ;
16725
    reg   [11:0] ba_offset ;
16726
    reg   [11:0] am_offset ;
16727
    reg   [11:0] ta_offset ;
16728
    reg   [11:0] cls_offset ;
16729
    reg          pci_ok ;
16730
    reg          wb_ok ;
16731
    reg          ok ;
16732
    reg   [31:0] pci_address ;
16733
    reg   [31:0] data ;
16734
    reg   [3:0]  byte_enables ;
16735
    reg   [9:0]  expect_length ;
16736
 
16737
    reg          do_mem_disconnects ;
16738
    reg          do_io_disconnects ;
16739 35 mihad
    reg          error_monitor_done ;
16740 15 mihad
begin:main
16741
    if ( target_mem_image !== -1 )
16742
    begin
16743
        do_mem_disconnects = 1 ;
16744
 
16745
        if (target_mem_image === 1)
16746
        begin
16747
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16748
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16749
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16750
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16751
        end
16752
        else if (target_mem_image === 2)
16753
        begin
16754
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16755
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16756
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16757
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16758
        end
16759
        else if (target_mem_image === 3)
16760
        begin
16761
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16762
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16763
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16764
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16765
        end
16766
        else if (target_mem_image === 4)
16767
        begin
16768
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16769
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16770
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16771
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16772
        end
16773
        else if (target_mem_image === 5)
16774
        begin
16775
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16776
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16777
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16778
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16779
        end
16780
    end
16781
    else
16782
        do_mem_disconnects = 0 ;
16783
 
16784
    pci_ctrl_offset = 12'h4 ;
16785
    cls_offset = 12'h00C ;
16786
 
16787
    master1_check_received_data = 0 ;
16788
    master2_check_received_data = 0 ;
16789
 
16790
    `ifdef HOST
16791
        `ifdef NO_CNF_IMAGE
16792
        `else
16793
            `define TEST_BURST_CONFIG_READ
16794
        `endif
16795
    `else
16796
        `define TEST_BURST_CONFIG_READ
16797
        `define TEST_BURST_CONFIG_WRITE
16798
    `endif
16799
 
16800
    `ifdef TEST_BURST_CONFIG_WRITE
16801
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16802
 
16803
        data = 32'h0000_08_08 ;
16804
 
16805 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16806 15 mihad
        byte_enables = 4'b0000 ;
16807
 
16808
        fork
16809
        begin
16810
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16811
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16812
                    byte_enables,
16813
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16814
                    8'h0_0, `Test_One_Zero_Target_WS,
16815
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16816
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16817
 
16818
            data = 32'h0000_04_04 ;
16819
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16820
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16821
                    byte_enables,
16822
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16823
                    8'h0_0, `Test_One_Zero_Target_WS,
16824
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16825
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16826
            do_pause( 1 ) ;
16827
            while ( FRAME !== 1 || IRDY !== 1 )
16828
                @(posedge pci_clock) ;
16829
 
16830 35 mihad
            #1 ;
16831
            if ( !error_monitor_done )
16832
                disable monitor_error_event1 ;
16833 15 mihad
        end
16834
        begin:monitor_error_event1
16835 35 mihad
            error_monitor_done = 0 ;
16836 15 mihad
            ok = 1 ;
16837
            @(error_event_int) ;
16838
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16839
            ok = 0 ;
16840 35 mihad
            error_monitor_done = 1 ;
16841 15 mihad
        end
16842
        join
16843
 
16844
        config_read(pci_address, 4'hF, data) ;
16845
        if ( data [15:0] !== 16'h04_04 )
16846
        begin
16847
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16848
        end
16849
        else if ( ok )
16850
            test_ok ;
16851
 
16852 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16853
 
16854
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16855 15 mihad
        data         = 32'h0000_0808 ;
16856
        byte_enables = 4'h0 ;
16857
        fork
16858
        begin
16859
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16860
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16861
                    byte_enables,
16862
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16863
                    8'h0_0, `Test_One_Zero_Target_WS,
16864
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16865
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16866
 
16867
            data = 32'h0000_04_04 ;
16868
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16869
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16870
                    byte_enables,
16871
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16872
                    8'h0_0, `Test_One_Zero_Target_WS,
16873
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16874
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16875
 
16876
            do_pause( 1 ) ;
16877
            while ( FRAME !== 1 || IRDY !== 1 )
16878
                @(posedge pci_clock) ;
16879
 
16880 35 mihad
            #1 ;
16881
            if ( !error_monitor_done )
16882
                disable monitor_error_event2 ;
16883 15 mihad
        end
16884
        begin:monitor_error_event2
16885 35 mihad
            error_monitor_done = 0 ;
16886 15 mihad
            ok = 1 ;
16887
            @(error_event_int) ;
16888
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16889
            ok = 0 ;
16890 35 mihad
            error_monitor_done = 1 ;
16891 15 mihad
        end
16892
        join
16893
 
16894
        config_read(pci_address, 4'hF, data) ;
16895
        if ( data [15:0] !== 16'h04_04 )
16896
        begin
16897
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16898
        end
16899
        else if ( ok )
16900
            test_ok ;
16901
    `endif
16902
 
16903
    `ifdef TEST_BURST_CONFIG_READ
16904
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16905
 
16906
        data = 32'h0000_04_04 ;
16907
 
16908 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16909 15 mihad
        byte_enables = 4'b0000 ;
16910
 
16911
        fork
16912
        begin
16913
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16914
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16915
                    byte_enables,
16916
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16917
                    8'h0_0, `Test_One_Zero_Target_WS,
16918
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16919
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16920
            do_pause( 1 ) ;
16921
 
16922
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16923
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16924
                    byte_enables,
16925
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16926
                    8'h0_0, `Test_One_Zero_Target_WS,
16927
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16928
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16929
            do_pause( 1 ) ;
16930
 
16931
            while ( FRAME !== 1 || IRDY !== 1 )
16932
                @(posedge pci_clock) ;
16933
 
16934 35 mihad
            if ( !error_monitor_done )
16935
                disable monitor_error_event3 ;
16936 15 mihad
        end
16937
        begin:monitor_error_event3
16938 35 mihad
            error_monitor_done = 0 ;
16939 15 mihad
            ok = 1 ;
16940
            @(error_event_int) ;
16941
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16942
            ok = 0 ;
16943 35 mihad
            error_monitor_done = 1 ;
16944 15 mihad
        end
16945
        join
16946
 
16947
        if ( ok )
16948
            test_ok ;
16949
 
16950 45 mihad
 
16951
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16952
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16953 15 mihad
        fork
16954
        begin
16955
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16956
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16957
                    byte_enables,
16958
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16959
                    8'h0_0, `Test_One_Zero_Target_WS,
16960
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16961
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16962
            do_pause( 1 ) ;
16963
 
16964
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16965
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16966
                    byte_enables,
16967
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16968
                    8'h0_0, `Test_One_Zero_Target_WS,
16969
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16970
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16971
            do_pause( 1 ) ;
16972
 
16973
            while ( FRAME !== 1 || IRDY !== 1 )
16974
                @(posedge pci_clock) ;
16975
 
16976 35 mihad
            #1 ;
16977
            if ( !error_monitor_done )
16978
                disable monitor_error_event4 ;
16979 15 mihad
        end
16980
        begin:monitor_error_event4
16981 35 mihad
            error_monitor_done = 0 ;
16982 15 mihad
            ok = 1 ;
16983
            @(error_event_int) ;
16984
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16985
            ok = 0 ;
16986 35 mihad
            error_monitor_done = 1 ;
16987 15 mihad
        end
16988
        join
16989
 
16990
        if ( ok )
16991
            test_ok ;
16992
    `endif
16993
 
16994
    `ifdef TEST_BURST_CONFIG_READ
16995
        `undef TEST_BURST_CONFIG_READ
16996
    `endif
16997
 
16998
    `ifdef TEST_BURST_CONFIG_WRITE
16999
        `undef TEST_BURST_CONFIG_WRITE
17000
    `endif
17001
 
17002
    master1_check_received_data = 1 ;
17003
    master2_check_received_data = 1 ;
17004
 
17005
    if ( do_mem_disconnects )
17006
    begin
17007
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17008
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17009
        if ( ok !== 1 )
17010
        begin
17011
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17012
            test_fail("PCI Base Address register could not be written") ;
17013
            disable main ;
17014
        end
17015
 
17016
        // Set Address Mask of IMAGE
17017
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17018
        if ( ok !== 1 )
17019
        begin
17020
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17021
            test_fail("PCI Address Mask register could not be written") ;
17022
            disable main ;
17023
        end
17024
 
17025
        // Set Translation Address of IMAGE
17026
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17027
        if ( ok !== 1 )
17028
        begin
17029
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17030
            test_fail("PCI Translation Address Register could not be written") ;
17031
            disable main ;
17032
        end
17033
 
17034
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17035
        if ( ok !== 1 )
17036
        begin
17037
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17038
            test_fail("PCI Image Control register could not be written") ;
17039
            disable main ;
17040
        end
17041
 
17042
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17043
        if ( ok !== 1 )
17044
        begin
17045
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17046
            test_fail("Cache Line Size register could not be written") ;
17047
            disable main ;
17048
        end
17049
 
17050
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17051
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17052
        data = 32'hAAAA_AAAA ;
17053
        byte_enables = 4'h0 ;
17054
        expect_length = `PCIW_DEPTH - 2 ;
17055
 
17056
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17057
        fork
17058
        begin
17059
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17060
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17061
                        byte_enables,
17062
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
17063
                        8'h0_0, `Test_One_Zero_Target_WS,
17064
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17065
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17066
            do_pause( 3 ) ;
17067
 
17068
            while ( FRAME !== 1 || IRDY !== 1 )
17069
                @(posedge pci_clock) ;
17070
 
17071 35 mihad
            #1 ;
17072
            if ( !error_monitor_done )
17073
                disable monitor_error_event5 ;
17074 15 mihad
        end
17075
        begin:monitor_error_event5
17076 35 mihad
            error_monitor_done = 0 ;
17077 15 mihad
            pci_ok = 1 ;
17078
            @(error_event_int) ;
17079
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17080
            pci_ok = 0 ;
17081 35 mihad
            error_monitor_done = 1 ;
17082 15 mihad
        end
17083
        begin
17084
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17085
            if ( wb_ok !== 1 )
17086
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17087
        end
17088
        join
17089
 
17090
        if ( wb_ok && pci_ok )
17091
            test_ok ;
17092
 
17093
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17094
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17095
        data = 32'hAAAA_AAAA ;
17096
        byte_enables = 4'h0 ;
17097
        expect_length = `PCIW_DEPTH - 2 ;
17098
 
17099
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17100
        fork
17101
        begin
17102
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17103
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17104
                        byte_enables,
17105
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
17106
                        8'h0_0, `Test_One_Zero_Target_WS,
17107
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17108
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17109
            do_pause( 3 ) ;
17110
 
17111
            while ( FRAME !== 1 || IRDY !== 1 )
17112
                @(posedge pci_clock) ;
17113
 
17114 35 mihad
            #1 ;
17115
            if ( !error_monitor_done )
17116
                disable monitor_error_event6 ;
17117 15 mihad
        end
17118
        begin:monitor_error_event6
17119 35 mihad
            error_monitor_done = 0 ;
17120 15 mihad
            pci_ok = 1 ;
17121
            @(error_event_int) ;
17122
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17123
            pci_ok = 0 ;
17124 35 mihad
            error_monitor_done = 1 ;
17125 15 mihad
        end
17126
        begin
17127
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17128
            if ( wb_ok !== 1 )
17129
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17130
        end
17131
        join
17132
 
17133
        if ( wb_ok && pci_ok )
17134
            test_ok ;
17135
 
17136
        master1_check_received_data = 1 ;
17137
//        master2_check_received_data = 0 ;
17138
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17139
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17140
        data = 32'hAAAA_AAAA ;
17141
        byte_enables = 4'h0 ;
17142
        expect_length = 4 ;
17143
 
17144
        fork
17145
        begin
17146
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17147
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17148
                        byte_enables,
17149
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17150
                        8'h0_0, `Test_One_Zero_Target_WS,
17151
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17152
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17153
            do_pause( 1 ) ;
17154
 
17155
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17156
            if ( wb_ok !== 1 )
17157
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17158
 
17159
            do_pause(2) ;
17160
 
17161
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17162
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17163
                        byte_enables,
17164
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17165
                        8'h0_0, `Test_One_Zero_Target_WS,
17166
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17167
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17168
            do_pause( 3 ) ;
17169
 
17170
            while ( FRAME !== 1 || IRDY !== 1 )
17171
                @(posedge pci_clock) ;
17172
 
17173 35 mihad
            #1 ;
17174
            if ( !error_monitor_done )
17175
                disable monitor_error_event7 ;
17176 15 mihad
        end
17177
        begin:monitor_error_event7
17178 35 mihad
            error_monitor_done = 0 ;
17179 15 mihad
            pci_ok = 1 ;
17180
            @(error_event_int) ;
17181
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17182
            pci_ok = 0 ;
17183 35 mihad
            error_monitor_done = 1 ;
17184 15 mihad
        end
17185
        join
17186
 
17187
        if ( wb_ok && pci_ok )
17188
            test_ok ;
17189
 
17190
        master1_check_received_data = 1 ;
17191
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17192
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17193
        data = 32'hAAAA_AAAA ;
17194
        byte_enables = 4'h0 ;
17195
        expect_length = 4 ;
17196
 
17197
        fork
17198
        begin
17199
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17200
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17201
                        byte_enables,
17202
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17203
                        8'h0_0, `Test_One_Zero_Target_WS,
17204
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17205
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17206
            do_pause( 1 ) ;
17207
 
17208
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17209
            if ( wb_ok !== 1 )
17210
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17211
 
17212
            do_pause(2) ;
17213
 
17214
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17215
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17216
                        byte_enables,
17217
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17218
                        8'h0_0, `Test_One_Zero_Target_WS,
17219
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17220
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17221
            do_pause( 3 ) ;
17222
 
17223
            while ( FRAME !== 1 || IRDY !== 1 )
17224
                @(posedge pci_clock) ;
17225
 
17226 35 mihad
            #1 ;
17227
            if ( !error_monitor_done )
17228
                disable monitor_error_event8 ;
17229 15 mihad
        end
17230
        begin:monitor_error_event8
17231 35 mihad
            error_monitor_done = 0 ;
17232 15 mihad
            pci_ok = 1 ;
17233
            @(error_event_int) ;
17234
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17235
            pci_ok = 0 ;
17236 35 mihad
            error_monitor_done = 1 ;
17237 15 mihad
        end
17238
        join
17239
 
17240
        if ( wb_ok && pci_ok )
17241
            test_ok ;
17242
 
17243
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17244
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17245
        data = 32'hDEAF_BEAF ;
17246
        byte_enables = 4'h0 ;
17247
        expect_length = 1 ;
17248
 
17249
        fork
17250
        begin
17251
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17252
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17253
                        byte_enables,
17254
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17255
                        8'h0_0, `Test_One_Zero_Target_WS,
17256
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17257
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17258
            do_pause( 3 ) ;
17259
 
17260
            while ( FRAME !== 1 || IRDY !== 1 )
17261
                @(posedge pci_clock) ;
17262
 
17263 35 mihad
            #1 ;
17264
            if ( !error_monitor_done )
17265
                disable monitor_error_event9 ;
17266 15 mihad
        end
17267
        begin:monitor_error_event9
17268 35 mihad
            error_monitor_done = 0 ;
17269 15 mihad
            pci_ok = 1 ;
17270
            @(error_event_int) ;
17271
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17272
            pci_ok = 0 ;
17273 35 mihad
            error_monitor_done = 1 ;
17274 15 mihad
        end
17275
        begin
17276
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17277
            if ( wb_ok !== 1 )
17278
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17279
        end
17280
        join
17281
 
17282
        if ( wb_ok && pci_ok )
17283
            test_ok ;
17284
 
17285
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17286
        data = 32'hDEAD_BEAF ;
17287
        byte_enables = 4'h0 ;
17288
        expect_length = 1 ;
17289
 
17290
        fork
17291
        begin
17292
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17293
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17294
                        byte_enables,
17295
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17296
                        8'h0_0, `Test_One_Zero_Target_WS,
17297
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17298
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17299
            do_pause( 3 ) ;
17300
 
17301
            while ( FRAME !== 1 || IRDY !== 1 )
17302
                @(posedge pci_clock) ;
17303
 
17304 35 mihad
            #1 ;
17305
            if ( !error_monitor_done )
17306
                disable monitor_error_event10 ;
17307 15 mihad
        end
17308
        begin:monitor_error_event10
17309 35 mihad
            error_monitor_done = 0 ;
17310 15 mihad
            pci_ok = 1 ;
17311
            @(error_event_int) ;
17312
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17313
            pci_ok = 0 ;
17314 35 mihad
            error_monitor_done = 1 ;
17315 15 mihad
        end
17316
        begin
17317
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17318
            if ( wb_ok !== 1 )
17319
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17320
        end
17321
        join
17322
 
17323
        if ( wb_ok && pci_ok )
17324
            test_ok ;
17325
 
17326
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17327
        data = 32'hAAAA_AAAA ;
17328
        byte_enables = 4'h0 ;
17329
        expect_length = 1 ;
17330
 
17331
        fork
17332
        begin
17333
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17334
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17335
                        byte_enables,
17336
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17337
                        8'h0_0, `Test_One_Zero_Target_WS,
17338
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17339
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17340
            do_pause( 3 ) ;
17341
 
17342
            while ( FRAME !== 1 || IRDY !== 1 )
17343
                @(posedge pci_clock) ;
17344
 
17345 35 mihad
            #1 ;
17346
            if ( !error_monitor_done )
17347
                disable monitor_error_event11 ;
17348 15 mihad
        end
17349
        begin:monitor_error_event11
17350 35 mihad
            error_monitor_done = 0 ;
17351 15 mihad
            pci_ok = 1 ;
17352
            @(error_event_int) ;
17353
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17354
            pci_ok = 0 ;
17355 35 mihad
            error_monitor_done = 1 ;
17356 15 mihad
        end
17357
        begin
17358
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17359
            if ( wb_ok !== 1 )
17360
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17361
        end
17362
        join
17363
 
17364
        if ( wb_ok && pci_ok )
17365
            test_ok ;
17366
 
17367
        master1_check_received_data = 1 ;
17368
 
17369
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17370
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17371
        data = 32'hDEAF_BEAF ;
17372
        byte_enables = 4'h0 ;
17373
        expect_length = 1 ;
17374
 
17375
        fork
17376
        begin
17377
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17378
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17379
                        byte_enables,
17380
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17381
                        8'h0_0, `Test_One_Zero_Target_WS,
17382
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17383
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17384
            do_pause( 1 ) ;
17385
 
17386
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17387
            if ( wb_ok !== 1 )
17388
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17389
 
17390
            do_pause(3) ;
17391
 
17392
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17393
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17394
                        byte_enables,
17395
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17396
                        8'h0_0, `Test_One_Zero_Target_WS,
17397
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17398
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17399
            do_pause( 3 ) ;
17400
 
17401
            while ( FRAME !== 1 || IRDY !== 1 )
17402
                @(posedge pci_clock) ;
17403
 
17404 35 mihad
            #1 ;
17405
            if ( !error_monitor_done )
17406
                disable monitor_error_event12 ;
17407 15 mihad
        end
17408
        begin:monitor_error_event12
17409 35 mihad
            error_monitor_done = 0 ;
17410 15 mihad
            pci_ok = 1 ;
17411
            @(error_event_int) ;
17412
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17413
            pci_ok = 0 ;
17414 35 mihad
            error_monitor_done = 1 ;
17415 15 mihad
        end
17416
        join
17417
 
17418
        if ( wb_ok && pci_ok )
17419
            test_ok ;
17420
 
17421
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17422
        data = 32'hDEAD_BEAF ;
17423
        byte_enables = 4'h0 ;
17424
        expect_length = 1 ;
17425
 
17426
        fork
17427
        begin
17428
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17429
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17430
                        byte_enables,
17431
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17432
                        8'h0_0, `Test_One_Zero_Target_WS,
17433
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17434
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17435
            do_pause( 1 ) ;
17436
 
17437
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17438
            if ( wb_ok !== 1 )
17439
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17440
 
17441
            do_pause(3) ;
17442
 
17443
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17444
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17445
                        byte_enables,
17446
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17447
                        8'h0_0, `Test_One_Zero_Target_WS,
17448
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17449
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17450
            do_pause( 3 ) ;
17451
 
17452
            while ( FRAME !== 1 || IRDY !== 1 )
17453
                @(posedge pci_clock) ;
17454
 
17455 35 mihad
            #1 ;
17456
            if ( !error_monitor_done )
17457
                disable monitor_error_event13 ;
17458 15 mihad
        end
17459
        begin:monitor_error_event13
17460 35 mihad
            error_monitor_done = 0 ;
17461 15 mihad
            pci_ok = 1 ;
17462
            @(error_event_int) ;
17463
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17464
            pci_ok = 0 ;
17465 35 mihad
            error_monitor_done = 1 ;
17466 15 mihad
        end
17467
        join
17468
 
17469
        if ( wb_ok && pci_ok )
17470
            test_ok ;
17471
 
17472
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17473
        data = 32'hAAAA_AAAA ;
17474
        byte_enables = 4'h0 ;
17475
        expect_length = 1 ;
17476
 
17477
        fork
17478
        begin
17479
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17480
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17481
                        byte_enables,
17482
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17483
                        8'h0_0, `Test_One_Zero_Target_WS,
17484
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17485
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17486
            do_pause( 1 ) ;
17487
 
17488
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17489
            if ( wb_ok !== 1 )
17490
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17491
 
17492
            do_pause(3) ;
17493
 
17494
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17495
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17496
                        byte_enables,
17497
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17498
                        8'h0_0, `Test_One_Zero_Target_WS,
17499
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17500
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17501
            do_pause( 3 ) ;
17502
 
17503
            while ( FRAME !== 1 || IRDY !== 1 )
17504
                @(posedge pci_clock) ;
17505
 
17506 35 mihad
            #1 ;
17507
            if ( !error_monitor_done )
17508
                disable monitor_error_event14 ;
17509 15 mihad
        end
17510
        begin:monitor_error_event14
17511 35 mihad
            error_monitor_done = 0 ;
17512 15 mihad
            pci_ok = 1 ;
17513
            @(error_event_int) ;
17514
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17515
            pci_ok = 0 ;
17516 35 mihad
            error_monitor_done = 1 ;
17517 15 mihad
        end
17518
        join
17519
 
17520
        if ( wb_ok && pci_ok )
17521
            test_ok ;
17522
 
17523
        // disable the image
17524
        test_name = "DISABLING MEMORY IMAGE" ;
17525 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17526 15 mihad
        if ( ok !== 1 )
17527
        begin
17528
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17529
            test_fail("PCI Address Mask register could not be written") ;
17530
            disable main ;
17531
        end
17532
    end
17533
//*
17534
    if ( target_io_image !== -1 )
17535
    begin
17536
        do_io_disconnects = 1 ;
17537
 
17538
        if (target_io_image === 1)
17539
        begin
17540
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17541
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17542
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17543
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17544
        end
17545
        else if (target_io_image === 2)
17546
        begin
17547
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17548
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17549
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17550
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17551
        end
17552
        else if (target_io_image === 3)
17553
        begin
17554
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17555
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17556
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17557
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17558
        end
17559
        else if (target_io_image === 4)
17560
        begin
17561
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17562
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17563
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17564
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17565
        end
17566
        else if (target_io_image === 5)
17567
        begin
17568
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17569
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17570
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17571
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17572
        end
17573
    end
17574
    else
17575
        do_io_disconnects = 0 ;
17576
 
17577
    if ( do_io_disconnects )
17578
    begin
17579
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17580
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17581
        if ( ok !== 1 )
17582
        begin
17583
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17584
            test_fail("PCI Base Address register could not be written") ;
17585
            disable main ;
17586
        end
17587
 
17588
        // Set Address Mask of IMAGE
17589
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17590
        if ( ok !== 1 )
17591
        begin
17592
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17593
            test_fail("PCI Address Mask register could not be written") ;
17594
            disable main ;
17595
        end
17596
 
17597
        // Set Translation Address of IMAGE
17598
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17599
        if ( ok !== 1 )
17600
        begin
17601
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17602
            test_fail("PCI Translation Address Register could not be written") ;
17603
            disable main ;
17604
        end
17605
 
17606
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17607
        if ( ok !== 1 )
17608
        begin
17609
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17610
            test_fail("PCI Image Control register could not be written") ;
17611
            disable main ;
17612
        end
17613
 
17614
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17615
        if ( ok !== 1 )
17616
        begin
17617
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17618
            test_fail("Cache Line Size register could not be written") ;
17619
            disable main ;
17620
        end
17621
 
17622
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17623
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17624
        data = 32'h5555_5555 ;
17625
        byte_enables = 4'h0 ;
17626
        expect_length = 1 ;
17627
 
17628
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17629
 
17630
        fork
17631
        begin
17632
            PCIU_IO_WRITE
17633
            (
17634
                `Test_Master_1,             // which master
17635
                pci_address,                // to what address
17636
                data,                       // data
17637
                byte_enables,               // byte enable
17638
                expect_length + 1,          // length to request
17639
                `Test_Target_Retry_On       // expected target termination
17640
            ) ;
17641
 
17642
            do_pause( 3 ) ;
17643
 
17644
            while ( FRAME !== 1 || IRDY !== 1 )
17645
                @(posedge pci_clock) ;
17646
 
17647 35 mihad
            #1 ;
17648
            if ( !error_monitor_done )
17649
                disable monitor_error_event15 ;
17650 15 mihad
        end
17651
        begin:monitor_error_event15
17652 35 mihad
            error_monitor_done = 0 ;
17653 15 mihad
            pci_ok = 1 ;
17654
            @(error_event_int) ;
17655
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17656
            pci_ok = 0 ;
17657 35 mihad
            error_monitor_done = 1 ;
17658 15 mihad
        end
17659
        begin
17660
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17661
            if ( wb_ok !== 1 )
17662
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17663
        end
17664
        join
17665
 
17666
        if ( wb_ok && pci_ok )
17667
            test_ok ;
17668
 
17669
        data = 32'hAAAA_AAAA ;
17670
        fork
17671
        begin
17672
            PCIU_IO_WRITE
17673
            (
17674
                `Test_Master_1,             // which master
17675
                pci_address,                // to what address
17676
                data,                       // data
17677
                byte_enables,               // byte enable
17678
                expect_length + 2,          // length to request
17679
                `Test_Target_Retry_Before   // expected target termination
17680
            ) ;
17681
 
17682
            do_pause( 3 ) ;
17683
 
17684
            while ( FRAME !== 1 || IRDY !== 1 )
17685
                @(posedge pci_clock) ;
17686
 
17687 35 mihad
            #1 ;
17688
            if ( !error_monitor_done )
17689
                disable monitor_error_event16 ;
17690 15 mihad
        end
17691
        begin:monitor_error_event16
17692 35 mihad
            error_monitor_done = 0 ;
17693 15 mihad
            pci_ok = 1 ;
17694
            @(error_event_int) ;
17695
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17696
            pci_ok = 0 ;
17697 35 mihad
            error_monitor_done = 1 ;
17698 15 mihad
        end
17699
        begin
17700
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17701
            if ( wb_ok !== 1 )
17702
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17703
        end
17704
        join
17705
 
17706
        if ( wb_ok && pci_ok )
17707
            test_ok ;
17708
 
17709
        master2_check_received_data = 1 ;
17710
 
17711
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17712
 
17713
        fork
17714
        begin
17715
 
17716
             PCIU_IO_READ
17717
             (
17718
                `Test_Master_2,
17719
                pci_address[PCI_BUS_DATA_RANGE:0],
17720
                data,
17721
                byte_enables,
17722
                2,
17723
                `Test_Target_Retry_Before
17724
             );
17725
 
17726
            do_pause( 1 ) ;
17727
 
17728
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17729
            if ( wb_ok !== 1 )
17730
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17731
 
17732
            do_pause(3) ;
17733
 
17734
            PCIU_IO_READ
17735
             (
17736
                `Test_Master_2,
17737
                pci_address[PCI_BUS_DATA_RANGE:0],
17738
                data,
17739
                byte_enables,
17740
                expect_length + 1,
17741
                `Test_Target_Retry_On
17742
             );
17743
 
17744
            do_pause( 3 ) ;
17745
 
17746
            while ( FRAME !== 1 || IRDY !== 1 )
17747
                @(posedge pci_clock) ;
17748
 
17749 35 mihad
            #1 ;
17750
            if ( !error_monitor_done )
17751
                disable monitor_error_event17 ;
17752 15 mihad
        end
17753
        begin:monitor_error_event17
17754 35 mihad
            error_monitor_done = 0 ;
17755 15 mihad
            pci_ok = 1 ;
17756
            @(error_event_int) ;
17757
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17758
            pci_ok = 0 ;
17759 35 mihad
            error_monitor_done = 1 ;
17760 15 mihad
        end
17761
        join
17762
 
17763
        if ( wb_ok && pci_ok )
17764
            test_ok ;
17765
 
17766
        fork
17767
        begin
17768
 
17769
             PCIU_IO_READ
17770
             (
17771
                `Test_Master_2,
17772
                pci_address[PCI_BUS_DATA_RANGE:0],
17773
                data,
17774
                byte_enables,
17775
                2,
17776
                `Test_Target_Retry_Before
17777
             );
17778
 
17779
            do_pause( 1 ) ;
17780
 
17781
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17782
            if ( wb_ok !== 1 )
17783
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17784
 
17785
            do_pause(3) ;
17786
 
17787
            PCIU_IO_READ
17788
             (
17789
                `Test_Master_2,
17790
                pci_address[PCI_BUS_DATA_RANGE:0],
17791
                data,
17792
                byte_enables,
17793
                expect_length + 2,
17794
                `Test_Target_Retry_Before
17795
             );
17796
 
17797
            do_pause( 3 ) ;
17798
 
17799
            while ( FRAME !== 1 || IRDY !== 1 )
17800
                @(posedge pci_clock) ;
17801
 
17802 35 mihad
            #1 ;
17803
            if ( !error_monitor_done )
17804
                disable monitor_error_event18 ;
17805 15 mihad
        end
17806
        begin:monitor_error_event18
17807 35 mihad
            error_monitor_done = 0 ;
17808 15 mihad
            pci_ok = 1 ;
17809
            @(error_event_int) ;
17810
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17811
            pci_ok = 0 ;
17812 35 mihad
            error_monitor_done = 1 ;
17813 15 mihad
        end
17814
        join
17815
 
17816
        if ( wb_ok && pci_ok )
17817
            test_ok ;
17818
 
17819
        test_name = "DISABLING IO IMAGE" ;
17820 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17821 15 mihad
        if ( ok !== 1 )
17822
        begin
17823
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17824
            test_fail("PCI Address Mask register could not be written") ;
17825
            disable main ;
17826
        end
17827
    end
17828
//*/
17829
end
17830
endtask // target_disconnects
17831
 
17832
task target_unsupported_cmds ;
17833
        input [31:0] Address;
17834
        input [2:0]  image_num ;
17835
    reg          ok ;
17836
begin:main
17837
 
17838
    $display("  ") ;
17839
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17840
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17841 45 mihad
 
17842
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17843
    configuration_cycle_write
17844
    (
17845
        0,                        // bus number
17846
        `TAR1_IDSEL_INDEX - 11,   // device number
17847
        0,                        // function number
17848
        1,                        // register number
17849
        0,                        // type of configuration cycle
17850
        4'b0001,                  // byte enables
17851
        32'h0000_0044             // data
17852
    ) ;
17853
 
17854
    configuration_cycle_write
17855
    (
17856
        0,                        // bus number
17857
        `TAR2_IDSEL_INDEX - 11,   // device number
17858
        0,                        // function number
17859
        1,                        // register number
17860
        0,                        // type of configuration cycle
17861
        4'b0001,                  // byte enables
17862
        32'h0000_0044             // data
17863
    ) ;
17864
 
17865 15 mihad
    ipci_unsupported_commands_master.master_reference
17866
    (
17867
        Address,                // first part of address in dual address cycle
17868
        Address,                // second part of address in dual address cycle
17869
        `BC_IACK,                       // dual address cycle command
17870
        `BC_IACK,               // normal command
17871
        4'h0,               // byte enables
17872
        32'h1234_5678,      // data
17873
        1'b0,               // make address parity error on first phase of dual address
17874
        1'b0,               // make address parity error on second phase of dual address
17875
        ok                  // result of operation
17876
    ) ;
17877
    if ( ok )
17878
        test_ok ;
17879
    else
17880
    begin
17881
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17882
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17883
    end
17884
 
17885
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17886
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17887
    ipci_unsupported_commands_master.master_reference
17888
    (
17889
        Address,                // first part of address in dual address cycle
17890
        Address,                // second part of address in dual address cycle
17891
        `BC_SPECIAL,            // dual address cycle command
17892
        `BC_SPECIAL,            // normal command
17893
        4'h0,               // byte enables
17894
        32'h1234_5678,      // data
17895
        1'b0,               // make address parity error on first phase of dual address
17896
        1'b0,               // make address parity error on second phase of dual address
17897
        ok                  // result of operation
17898
    ) ;
17899
    if ( ok )
17900
        test_ok ;
17901
    else
17902
    begin
17903
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17904
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17905
    end
17906
 
17907
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17908
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17909
    ipci_unsupported_commands_master.master_reference
17910
    (
17911
        Address,                // first part of address in dual address cycle
17912
        Address,                // second part of address in dual address cycle
17913
        `BC_RESERVED0,          // dual address cycle command
17914
        `BC_RESERVED0,      // normal command
17915
        4'h0,               // byte enables
17916
        32'h1234_5678,      // data
17917
        1'b0,               // make address parity error on first phase of dual address
17918
        1'b0,               // make address parity error on second phase of dual address
17919
        ok                  // result of operation
17920
    ) ;
17921
    if ( ok )
17922
        test_ok ;
17923
    else
17924
    begin
17925
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17926
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17927
    end
17928
 
17929
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17930
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17931
    ipci_unsupported_commands_master.master_reference
17932
    (
17933
        Address,                // first part of address in dual address cycle
17934
        Address,                // second part of address in dual address cycle
17935
        `BC_RESERVED1,          // dual address cycle command
17936
        `BC_RESERVED1,      // normal command
17937
        4'h0,               // byte enables
17938
        32'h1234_5678,      // data
17939
        1'b0,               // make address parity error on first phase of dual address
17940
        1'b0,               // make address parity error on second phase of dual address
17941
        ok                  // result of operation
17942
    ) ;
17943
    if ( ok )
17944
        test_ok ;
17945
    else
17946
    begin
17947
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17948
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17949
    end
17950
 
17951
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17952
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17953
    ipci_unsupported_commands_master.master_reference
17954
    (
17955
        Address,                // first part of address in dual address cycle
17956
        Address,                // second part of address in dual address cycle
17957
        `BC_RESERVED2,          // dual address cycle command
17958
        `BC_RESERVED2,      // normal command
17959
        4'h0,               // byte enables
17960
        32'h1234_5678,      // data
17961
        1'b0,               // make address parity error on first phase of dual address
17962
        1'b0,               // make address parity error on second phase of dual address
17963
        ok                  // result of operation
17964
    ) ;
17965
    if ( ok )
17966
        test_ok ;
17967
    else
17968
    begin
17969
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17970
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17971
    end
17972
 
17973
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17974
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17975
    ipci_unsupported_commands_master.master_reference
17976
    (
17977
        Address,                // first part of address in dual address cycle
17978
        Address,                // second part of address in dual address cycle
17979
        `BC_RESERVED3,          // dual address cycle command
17980
        `BC_RESERVED3,      // normal command
17981
        4'h0,               // byte enables
17982
        32'h1234_5678,      // data
17983
        1'b0,               // make address parity error on first phase of dual address
17984
        1'b0,               // make address parity error on second phase of dual address
17985
        ok                  // result of operation
17986
    ) ;
17987
    if ( ok )
17988
        test_ok ;
17989
    else
17990
    begin
17991
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17992
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17993
    end
17994
 
17995
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17996
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17997
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17998
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17999
    ipci_unsupported_commands_master.master_reference
18000
    (
18001
        Address,                // first part of address in dual address cycle
18002
        Address,                // second part of address in dual address cycle
18003
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18004
        `BC_MEM_WRITE,      // normal command
18005
        4'h0,               // byte enables;
18006
        32'h1234_5678,      // data
18007
        1'b0,               // make address parity error on first phase of dual address
18008
        1'b0,               // make address parity error on second phase of dual address
18009
        ok                  // result of operation
18010
    ) ;
18011
    if ( ok )
18012
        test_ok ;
18013
    else
18014
    begin
18015
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18016
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18017
    end
18018
 
18019 45 mihad
    // enable pci blue behavioral targets 1 and 2
18020
    configuration_cycle_write
18021
    (
18022
        0,                        // bus number
18023
        `TAR1_IDSEL_INDEX - 11,   // device number
18024
        0,                        // function number
18025
        1,                        // register number
18026
        0,                        // type of configuration cycle
18027
        4'b0001,                  // byte enables
18028
        32'h0000_0047             // data
18029
    ) ;
18030
 
18031
    configuration_cycle_write
18032
    (
18033
        0,                        // bus number
18034
        `TAR2_IDSEL_INDEX - 11,   // device number
18035
        0,                        // function number
18036
        1,                        // register number
18037
        0,                        // type of configuration cycle
18038
        4'b0001,                  // byte enables
18039
        32'h0000_0047             // data
18040
    ) ;
18041 15 mihad
end
18042
endtask // target_unsupported_cmds
18043
 
18044 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18045
`else
18046 15 mihad
task target_completion_expiration ;
18047
    reg   [11:0] pci_ctrl_offset ;
18048
    reg   [11:0] pci_ba_offset ;
18049
    reg   [11:0] pci_am_offset ;
18050
    reg   [11:0] pci_device_ctrl_offset ;
18051
    reg   [11:0] pci_err_cs_offset ;
18052
    reg   [11:0] icr_offset ;
18053
    reg   [11:0] isr_offset ;
18054
    reg   [11:0] lat_tim_cls_offset ;
18055
 
18056
    reg [31:0] temp_val1 ;
18057
    reg [31:0] temp_val2 ;
18058
    reg        ok   ;
18059 33 mihad
    reg        ok_wb ;
18060
    reg        ok_pci ;
18061 15 mihad
 
18062
    reg [31:0] pci_image_base ;
18063
    integer i ;
18064 33 mihad
    integer clocks_after_completion ;
18065
    reg     error_monitor_done ;
18066
    reg     test_mem ;
18067 15 mihad
 
18068
begin:main
18069
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18070
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18071
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18072
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18073
 
18074
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18075
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18076
    lat_tim_cls_offset = 12'hC ;
18077
    pci_device_ctrl_offset    = 12'h4 ;
18078
 
18079 33 mihad
    `ifdef HOST
18080
        test_mem = 1'b1 ;
18081
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18082
    `else
18083
        test_mem = !`PCI_BA1_MEM_IO ;
18084
        pci_image_base = Target_Base_Addr_R[1] ;
18085
    `endif
18086 15 mihad
 
18087
    // enable master & target operation
18088
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18089
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18090
    if ( ok !== 1 )
18091
    begin
18092
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18093
        test_fail("write to PCI Device Control register failed") ;
18094
        disable main ;
18095
    end
18096
 
18097
    // prepare image control register
18098 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18099 15 mihad
    if ( ok !== 1 )
18100
    begin
18101
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18102
        test_fail("write to PCI Image Control register failed") ;
18103
        disable main ;
18104
    end
18105
 
18106
    // prepare base address register
18107
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18108
    if ( ok !== 1 )
18109
    begin
18110
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18111
        test_fail("write to PCI Base Address register failed") ;
18112
        disable main ;
18113
    end
18114
 
18115
    // write address mask register
18116
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18117
    if ( ok !== 1 )
18118
    begin
18119
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18120
        test_fail("write to PCI Address Mask register failed") ;
18121
        disable main ;
18122
    end
18123
 
18124
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18125
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18126
    if ( ok !== 1 )
18127
    begin
18128
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18129
        test_fail("write to PCI Error Control and Status register failed") ;
18130
        disable main ;
18131
    end
18132
 
18133 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18134 15 mihad
    if ( ok !== 1 )
18135
    begin
18136
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18137
        test_fail("write to Interrupt Control register failed") ;
18138
        disable main ;
18139
    end
18140
 
18141
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18142
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18143
    if ( ok !== 1 )
18144
    begin
18145
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18146
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18147
        disable main ;
18148
    end
18149
 
18150
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18151
 
18152
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18153 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18154
    master1_check_received_data = 0 ;
18155 15 mihad
 
18156 33 mihad
    ok_pci = 1 ;
18157
    // start a delayed read request
18158
    fork
18159
    begin
18160
        if ( test_mem )
18161
 
18162
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18163
                          pci_image_base, 32'h1234_5678,
18164
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18165
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18166
        else
18167
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18168
 
18169
        do_pause( 1 ) ;
18170
    end
18171
    begin:error_monitor1
18172 35 mihad
        error_monitor_done = 0 ;
18173 33 mihad
        @(error_event_int) ;
18174
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18175
        ok_pci = 0 ;
18176 35 mihad
        error_monitor_done = 1 ;
18177 33 mihad
    end
18178
    begin
18179
        if ( test_mem )
18180
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18181
        else
18182
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18183 15 mihad
 
18184 33 mihad
        if ( ok_wb !== 1 )
18185
        begin
18186
            test_fail("Bridge failed to process Target Memory read correctly") ;
18187
            disable main ;
18188
        end
18189
 
18190 35 mihad
        #1 ;
18191
        if ( !error_monitor_done )
18192 33 mihad
            disable error_monitor1 ;
18193
    end
18194
    join
18195
 
18196
    clocks_after_completion = 0 ;
18197
    // now do another - different transaction
18198
    fork
18199
    begin
18200
        if ( test_mem )
18201
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18202
                          pci_image_base + 4, 32'h1234_5678,
18203
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18204
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18205
        else
18206
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18207
 
18208
        while ( clocks_after_completion < 32'h0000_FFF0 )
18209
        begin
18210
            @(posedge pci_clock) ;
18211
            clocks_after_completion = clocks_after_completion + 1 ;
18212
        end
18213
 
18214
        do_pause('hFF) ;
18215
 
18216
        if ( test_mem )
18217
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18218
                          pci_image_base + 4, 32'h1234_5678,
18219
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18220
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18221
        else
18222
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18223
 
18224
        do_pause( 1 ) ;
18225
    end
18226
    begin:error_monitor2
18227 35 mihad
        error_monitor_done = 0 ;
18228 33 mihad
        @(error_event_int) ;
18229
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18230
        ok_pci = 0 ;
18231 35 mihad
        error_monitor_done = 1 ;
18232 33 mihad
    end
18233
    begin
18234
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18235
        repeat( 'hFF )
18236
            @(posedge pci_clock) ;
18237
 
18238
        if ( test_mem )
18239
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18240
        else
18241
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18242
 
18243
        if ( ok_wb !== 1 )
18244
        begin
18245
            test_fail("Bridge failed to process Target Memory read correctly") ;
18246
            disable main ;
18247
        end
18248
 
18249
        repeat(4)
18250
            @(posedge pci_clock) ;
18251
 
18252
        fork
18253
        begin
18254
            if ( test_mem )
18255
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18256
                              pci_image_base + 4, 32'h1234_5678,
18257
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18258
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18259
            else
18260
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18261
 
18262
            do_pause(1) ;
18263
        end
18264
        begin
18265
           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 ) ;
18266 35 mihad
           #1 ;
18267
           if ( !error_monitor_done )
18268 33 mihad
               disable error_monitor2 ;
18269
        end
18270
        join
18271
    end
18272
    join
18273
 
18274
    if ( ok && ok_pci && ok_wb )
18275
        test_ok ;
18276
 
18277
    if ( ok !== 1 )
18278
    begin
18279
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18280
        test_fail("write to PCI Address Mask register failed") ;
18281
        disable main ;
18282
    end
18283
 
18284
    // check statuses after this situation - none should be set
18285
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18286
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18287
    if ( ok !== 1 )
18288
    begin
18289
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18290
        test_fail("read from pci device status register failed") ;
18291
        disable main ;
18292
    end
18293
 
18294
    if ( temp_val1[31] )
18295
    begin
18296
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18297
        test_fail("detected parity error bit was set for no reason") ;
18298
    end
18299
 
18300
    if ( temp_val1[30] )
18301
    begin
18302
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18303
        test_fail("signaled system error bit was set for no reason") ;
18304
    end
18305
 
18306
    if ( temp_val1[29] )
18307
    begin
18308
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18309
        test_fail("received master abort bit was set for no reason") ;
18310
    end
18311
 
18312
    if ( temp_val1[28] )
18313
    begin
18314
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18315
        test_fail("received target abort bit was set for no reason") ;
18316
    end
18317
 
18318
    if ( temp_val1[27] )
18319
    begin
18320
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18321
        test_fail("signaled target abort bit was set for no reason") ;
18322
    end
18323
 
18324
    if ( temp_val1[24] )
18325
    begin
18326
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18327
        test_fail("Master Data parity error bit was set for no reason") ;
18328
    end
18329
 
18330
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18331
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18332
    if ( temp_val1[8] !== 0 )
18333
    begin
18334
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18335
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18336
    end
18337
    // test target retry counter expiration
18338
    // set wb slave to retry response
18339
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18340
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18341
    ok_pci = 1 ;
18342
 
18343
    fork
18344
    begin
18345
        if ( test_mem == 1 )
18346
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18347
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18348
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18349
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18350
        else
18351
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18352
 
18353
        do_pause(1) ;
18354
 
18355
        // do another write with same address and different data
18356
        if ( test_mem == 1 )
18357
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18358
                        pci_image_base, 32'h8765_4321, 4'h0,
18359
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18360
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18361
        else
18362
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18363
 
18364
        do_pause(1) ;
18365
    end
18366
    begin
18367
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18368
        begin
18369
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18370
            if ( ok_wb !== 1 )
18371
            begin
18372
                $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) ;
18373
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18374
                disable main ;
18375
            end
18376
        end
18377
 
18378
        // set WB slave to normal completion
18379
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18380
 
18381
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18382
        if ( ok_wb !== 1 )
18383
        begin
18384
            $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) ;
18385
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18386
            disable main ;
18387
        end
18388
 
18389 35 mihad
        #1 ;
18390
        if ( !error_monitor_done )
18391 33 mihad
            disable error_monitor3 ;
18392
    end
18393
    begin:error_monitor3
18394 35 mihad
        error_monitor_done = 0 ;
18395 33 mihad
        @(error_event_int) ;
18396
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18397
        ok_pci = 0 ;
18398 35 mihad
        error_monitor_done = 1 ;
18399 33 mihad
    end
18400
    join
18401
 
18402
    if ( ok_wb && ok_pci )
18403
    begin
18404
        test_ok ;
18405
    end
18406
 
18407
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18408
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18409
    if ( temp_val1[8] !== 1'b1 )
18410
    begin
18411
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18412
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18413
    end
18414
 
18415
    if ( temp_val1[9] !== 1 )
18416
    begin
18417
        $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) ;
18418
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18419
    end
18420
 
18421
    if ( temp_val1[10] !== 1 )
18422
    begin
18423
        $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) ;
18424
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18425
    end
18426
 
18427
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18428
    begin
18429
        $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) ;
18430
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18431
    end
18432
 
18433
    if ( temp_val1[31:28] !== 4'hA )
18434
    begin
18435
        $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) ;
18436
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18437
    end
18438
 
18439
    // clear error status register
18440
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18441
 
18442
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18443
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18444
    if ( temp_val1 !== pci_image_base )
18445
    begin
18446
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18447
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18448
    end
18449
 
18450
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18451
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18452
    if ( temp_val1 !== 32'hDEAD_BEAF )
18453
    begin
18454
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18455
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18456
    end
18457
 
18458
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18459
    ok_pci = 1 ;
18460
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18461
 
18462
    i = 0 ;
18463
    fork
18464
    begin
18465
        if ( test_mem )
18466
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18467
                          pci_image_base + 4, 32'h1234_5678,
18468
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18469
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18470
        else
18471
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18472
 
18473
        do_pause( 1 ) ;
18474
 
18475
    end
18476
    begin
18477
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18478
        begin
18479
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18480
            if ( ok_wb !== 1 )
18481
            begin
18482
                $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) ;
18483
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18484
                disable main ;
18485
            end
18486
        end
18487
 
18488
        // set WB slave to normal completion
18489
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18490
 
18491
        fork
18492
        begin
18493
            repeat(4)
18494
                @(posedge pci_clock) ;
18495
 
18496
            if ( test_mem )
18497
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18498
                              pci_image_base, 32'h8765_4321,
18499
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18500
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18501
            else
18502
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18503
 
18504
            do_pause(1) ;
18505
        end
18506
        begin
18507
 
18508
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18509
            if ( ok_wb !== 1 )
18510
            begin
18511
                $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) ;
18512
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18513
                disable main ;
18514
            end
18515
        end
18516
        join
18517
 
18518
        repeat( 4 )
18519
            @(posedge pci_clock) ;
18520
 
18521
        if ( test_mem )
18522
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18523
                          pci_image_base, 32'h8765_4321,
18524
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18525
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18526
        else
18527
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18528
 
18529
        do_pause(1) ;
18530
 
18531 35 mihad
        #1 ;
18532
        if ( !error_monitor_done )
18533 33 mihad
            disable error_monitor4 ;
18534
    end
18535
    begin:error_monitor4
18536 35 mihad
        error_monitor_done = 0 ;
18537 33 mihad
        @(error_event_int) ;
18538
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18539
        ok_pci = 0 ;
18540 35 mihad
        error_monitor_done = 1 ;
18541 33 mihad
    end
18542
    join
18543
 
18544
    if ( ok_wb && ok_pci )
18545
        test_ok ;
18546
 
18547
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18548
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18549
    if ( temp_val1[8] !== 1'b0 )
18550
    begin
18551
        $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) ;
18552
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18553
    end
18554
 
18555
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18556 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18557
    $fdisplay(pciu_mon_log_file_desc,
18558
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18559 33 mihad
    ok_pci = 1 ;
18560
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18561
 
18562
    fork
18563
    begin
18564
        if ( test_mem )
18565
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18566
                          pci_image_base + 4, 32'h1234_5678,
18567
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18568
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18569
        else
18570
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18571
 
18572
        do_pause( 1 ) ;
18573
 
18574
    end
18575
    begin
18576
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18577
        if ( ok_wb !== 1 )
18578
        begin
18579
            $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) ;
18580
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18581
            disable main ;
18582
        end
18583
 
18584
        repeat(4)
18585
            @(posedge pci_clock) ;
18586
 
18587
        fork
18588
        begin
18589
 
18590
            if ( test_mem )
18591
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18592
                              pci_image_base + 4, 32'h8765_4321,
18593
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18594
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18595
            else
18596
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18597
 
18598
            do_pause(1) ;
18599
 
18600
        end
18601
        begin
18602
 
18603
            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 ) ;
18604
            if ( ok !== 1 )
18605
            begin
18606
                $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) ;
18607
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18608
                disable main ;
18609
            end
18610
        end
18611
        join
18612
 
18613 35 mihad
        #1 ;
18614
        if ( !error_monitor_done )
18615 33 mihad
            disable error_monitor5 ;
18616
    end
18617
    begin:error_monitor5
18618 35 mihad
        error_monitor_done = 0 ;
18619 33 mihad
        @(error_event_int) ;
18620
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18621
        ok_pci = 0 ;
18622 35 mihad
        error_monitor_done = 1 ;
18623 33 mihad
    end
18624
    join
18625
 
18626
    if ( ok_wb && ok_pci )
18627
        test_ok ;
18628
 
18629
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18630
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18631
    if ( temp_val1[8] !== 1'b0 )
18632
    begin
18633
        $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) ;
18634
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18635
    end
18636
 
18637
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18638
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18639
    if ( temp_val1[25] !== 1'b1 )
18640
    begin
18641
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18642
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18643
    end
18644
 
18645
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18646
 
18647
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18648
    ok_pci = 1 ;
18649
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18650
 
18651
    fork
18652
    begin
18653
        if ( test_mem == 1 )
18654
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18655
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18656
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18657
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18658
        else
18659
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18660
 
18661
        do_pause(1) ;
18662
 
18663
        // do another write with same address and different data
18664
        if ( test_mem == 1 )
18665
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18666
                        pci_image_base, 32'h8765_6789, 4'h0,
18667
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18668
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18669
        else
18670
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18671
 
18672
        do_pause(1) ;
18673
    end
18674
    begin
18675
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18676
        if ( ok_wb !== 1 )
18677
        begin
18678
            $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) ;
18679
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18680
            disable main ;
18681
        end
18682
 
18683
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18684
 
18685
        if ( test_mem )
18686
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18687
        else
18688
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18689
 
18690
        if ( ok_wb !== 1 )
18691
        begin
18692
            $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) ;
18693
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18694
            disable main ;
18695
        end
18696
 
18697 35 mihad
        #1 ;
18698
        if ( !error_monitor_done )
18699 33 mihad
            disable error_monitor6 ;
18700
    end
18701
    begin:error_monitor6
18702 35 mihad
        error_monitor_done = 0 ;
18703 33 mihad
        @(error_event_int) ;
18704
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18705
        ok_pci = 0 ;
18706 35 mihad
        error_monitor_done = 1 ;
18707 33 mihad
    end
18708
    join
18709
 
18710
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18711
    $fdisplay(pciu_mon_log_file_desc,
18712
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18713
 
18714
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18715
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18716
    if ( temp_val1[8] !== 1'b1 )
18717
    begin
18718
        $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) ;
18719
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18720
    end
18721
 
18722
    if ( temp_val1[9] !== 0 )
18723
    begin
18724
        $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) ;
18725
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18726
    end
18727
 
18728
    if ( temp_val1[10] !== 1 )
18729
    begin
18730
        $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) ;
18731
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18732
    end
18733
 
18734
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18735
    begin
18736
        $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) ;
18737
        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") ;
18738
    end
18739
 
18740
    if ( temp_val1[31:28] !== 4'h0 )
18741
    begin
18742
        $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) ;
18743
        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") ;
18744
    end
18745
 
18746
    // clear error status register
18747
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18748
 
18749
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18750
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18751
    if ( temp_val1 !== pci_image_base )
18752
    begin
18753
        $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) ;
18754
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18755
    end
18756
 
18757
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18758
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18759
    if ( temp_val1 !== 32'hBEAF_DEAD )
18760
    begin
18761
        $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) ;
18762
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18763
    end
18764
 
18765
    // disable current image - write address mask register
18766 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18767 15 mihad
end
18768 57 mihad
endtask // target_completion_expiration
18769 15 mihad
 
18770 57 mihad
task master_completion_expiration ;
18771
    reg   [11:0] ctrl_offset ;
18772
    reg   [11:0] ba_offset ;
18773
    reg   [11:0] am_offset ;
18774
    reg `WRITE_STIM_TYPE write_data ;
18775
    reg `READ_STIM_TYPE  read_data ;
18776
    reg `READ_RETURN_TYPE read_status ;
18777
 
18778
    reg `WRITE_RETURN_TYPE write_status ;
18779
    reg `WB_TRANSFER_FLAGS write_flags ;
18780
    reg        ok   ;
18781
    reg [11:0] pci_ctrl_offset ;
18782
    reg [31:0] image_base ;
18783
    reg [31:0] target_address ;
18784
begin:main
18785
    pci_ctrl_offset = 12'h4 ;
18786
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18787
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18788
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18789
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18790
 
18791
    target_address  = `BEH_TAR1_MEM_START ;
18792
    image_base      = 0 ;
18793
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18794
 
18795
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18796
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18797
    write_flags                      = 0 ;
18798
    write_flags`INIT_WAITS           = tb_init_waits ;
18799
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18800
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18801
 
18802
    // enable master & target operation
18803
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18804
    if ( ok !== 1 )
18805
    begin
18806
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18807
        test_fail("write to PCI Device Control register didn't succeede");
18808
        disable main ;
18809
    end
18810
 
18811
    // prepare image control register
18812
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18813
    if ( ok !== 1 )
18814
    begin
18815
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18816
        test_fail("write to WB Image Control register didn't succeede");
18817
        disable main ;
18818
    end
18819
 
18820
    // prepare base address register
18821
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18822
    if ( ok !== 1 )
18823
    begin
18824
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18825
        test_fail("write to WB Base Address register didn't succeede");
18826
        disable main ;
18827
    end
18828
 
18829
    // write address mask register
18830
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18831
    if ( ok !== 1 )
18832
    begin
18833
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18834
        test_fail("write to WB Address Mask register didn't succeede");
18835
        disable main ;
18836
    end
18837
 
18838
    fork
18839
    begin
18840
        // do not handle retries
18841
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18842
 
18843
        // initiate a read request
18844
        read_data`READ_ADDRESS  = target_address ;
18845
        read_data`READ_SEL      = 4'hF ;
18846
        read_data`READ_TAG_STIM = 0 ;
18847
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18848
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18849
        begin
18850
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18851
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18852
            disable main ;
18853
        end
18854
 
18855
        // handle retries from now on
18856
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18857
 
18858
        write_data`WRITE_ADDRESS = target_address + 4 ;
18859
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18860
        write_data`WRITE_SEL     = 4'hF ;
18861
 
18862
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18863
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18864
        begin
18865
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18866
            test_fail("WB Slave state machine failed to post single memory write");
18867
            disable main ;
18868
        end
18869
 
18870
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 100
18871
        repeat('h1_0000 - 100)
18872
            @(posedge wb_clock) ;
18873
 
18874
        // now perform a read
18875
        read_data`READ_ADDRESS  = target_address + 4 ;
18876
        read_data`READ_SEL      = 4'hF ;
18877
        read_data`READ_TAG_STIM = 0 ;
18878
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18879
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18880
        begin
18881
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18882
            test_fail("PCI bridge didn't process the read as expected");
18883
            disable main ;
18884
        end
18885
 
18886
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18887
        begin
18888
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18889
            test_fail("PCI bridge returned unexpected Read Data");
18890
        end
18891
        else if (ok === 1'b1)
18892
            test_ok ;
18893
    end
18894
    begin:monitors
18895
        // monitor first read, which will expire
18896
        pci_transaction_progress_monitor
18897
        (
18898
            target_address, // expected address
18899
            `BC_MEM_READ,   // expected bus command
18900
            1,              // expected number of transfers
18901
            0,              // expected number of cycles
18902
            1,              // check number of transfers true/false
18903
            0,              // check number of cycles true/false
18904
            0,              // is this fast B2B true/false
18905
            ok              // return 1 if as expected, anything else on error
18906
        ) ;
18907
 
18908
        if ( ok !== 1 )
18909
        begin
18910
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18911
            #1 disable monitors ;
18912
        end
18913
 
18914
        // monitor normal single write
18915
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18916
        if ( ok !== 1 )
18917
        begin
18918
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18919
            #1 disable monitors ;
18920
        end
18921
 
18922
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18923
        repeat('h1_0000 - 50)
18924
            @(posedge wb_clock) ;
18925
 
18926
        // monitor normal single memory read
18927
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18928
        if ( ok !== 1 )
18929
        begin
18930
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18931
        end
18932
    end
18933
    join
18934
 
18935
    // disable the image
18936
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18937
    if ( ok !== 1 )
18938
    begin
18939
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18940
        test_fail("write to WB Address Mask register didn't succeede");
18941
    end
18942
end
18943
endtask // master_completion_expiration
18944 63 mihad
`endif
18945 57 mihad
 
18946 15 mihad
task config_write ;
18947
    input [11:0] offset ;
18948
    input [31:0] data ;
18949
    input [3:0]  byte_enable ;
18950
    output       ok ;
18951
    `ifdef HOST
18952
    reg   `WRITE_STIM_TYPE   write_data ;
18953
    reg   `WB_TRANSFER_FLAGS write_flags ;
18954
    reg   `WRITE_RETURN_TYPE write_status ;
18955
    `else
18956
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18957
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18958
    `endif
18959
    reg in_use ;
18960
    reg [31:0] temp_var ;
18961
begin
18962
    if ( in_use === 1 )
18963
    begin
18964
        $display("config_read task re-entered! Time %t ", $time) ;
18965
        ok = 0 ;
18966
        #20 $stop ;
18967
    end
18968
    else
18969
    begin
18970
        ok = 1 ;
18971
        in_use = 1 ;
18972
    end
18973
    `ifdef HOST
18974
    write_flags                    = 0 ;
18975
    write_flags`INIT_WAITS         = tb_init_waits ;
18976
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18977
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18978
 
18979
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18980
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18981
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18982
    write_data`WRITE_SEL                         = byte_enable ;
18983
    write_data`WRITE_TAG_STIM                    = 0 ;
18984
    write_data`WRITE_DATA                        = data ;
18985
 
18986
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18987
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18988
    begin
18989
        $display("Write to configuration space failed! Time %t ", $time) ;
18990
        ok = 0 ;
18991
    end
18992
 
18993
    @(posedge wb_clock) ;
18994
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18995
    // here we just wait for two guest cycles for conf space bits to synchronize
18996
    repeat( 2 )
18997
        @(posedge pci_clock) ;
18998
 
18999
    `else // GUEST
19000
    byte_enables_l = ~byte_enable ;
19001
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19002
 
19003
    fork
19004
    begin
19005
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19006
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19007
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19008
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19009
              8'h0_0, `Test_One_Zero_Target_WS,
19010
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19011
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19012
    do_pause( 1 ) ;
19013
    end
19014
    begin
19015
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19016
        @(posedge pci_clock) ;
19017
    end
19018
    join
19019
 
19020
     repeat( 2 )
19021
         @(posedge wb_clock) ;
19022
 
19023
    `endif
19024
    in_use = 0 ;
19025
end
19026
endtask // config_write
19027
 
19028
task config_read ;
19029
    input [11:0] offset ;
19030
    input [3:0]  byte_enable ;
19031
    output [31:0] data ;
19032
 
19033
    reg `READ_STIM_TYPE    read_data ;
19034
    reg `WB_TRANSFER_FLAGS read_flags ;
19035
    reg `READ_RETURN_TYPE  read_status ;
19036
 
19037
    reg [31:0] pci_address ;
19038
    reg [3:0] byte_enables_l ;
19039
 
19040
    reg master_check_data_prev ;
19041
    reg in_use ;
19042
    reg [31:0] temp_var ;
19043
begin:main
19044
    if ( in_use === 1 )
19045
    begin
19046
        $display("config_read task re-entered! Time %t ", $time) ;
19047
        data = 32'hxxxx_xxxx ;
19048
        disable main ;
19049
    end
19050
 
19051
    in_use = 1 ;
19052
 
19053
`ifdef HOST
19054 26 mihad
    repeat(4)
19055
        @(posedge pci_clock) ;
19056
    repeat(4)
19057
        @(posedge wb_clock) ;
19058 15 mihad
    read_flags                    = 0 ;
19059
    read_flags`INIT_WAITS         = tb_init_waits ;
19060
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19061
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19062
 
19063
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19064
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19065
 
19066
    read_data`READ_ADDRESS  = temp_var + offset ;
19067
    read_data`READ_SEL      = byte_enable ;
19068
    read_data`READ_TAG_STIM = 0 ;
19069
 
19070
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19071
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19072
    begin
19073
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19074
        #20 $stop ;
19075
    end
19076
    data = read_status`READ_DATA ;
19077
`else
19078
  `ifdef GUEST
19079 26 mihad
    repeat(4)
19080
        @(posedge wb_clock) ;
19081
    repeat(4)
19082
        @(posedge pci_clock) ;
19083 15 mihad
    master_check_data_prev = master2_check_received_data ;
19084
    master2_check_received_data = 0 ;
19085
 
19086
    byte_enables_l = ~byte_enable ;
19087
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19088
 
19089
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19090
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19091
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19092
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19093
             8'h4_0, `Test_One_Zero_Target_WS,
19094
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19095
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19096
    do_pause( 1 ) ;
19097
 
19098
    @(master2_received_data_valid) ;
19099
    data = master2_received_data ;
19100
 
19101
    master2_check_received_data = master_check_data_prev ;
19102
  `endif
19103
`endif
19104
    in_use = 0 ;
19105
end
19106
endtask //config_read
19107
 
19108 62 mihad
`ifdef PCI_BIST
19109
`ifdef WB_RAM_DONT_SHARE
19110
    `ifdef PCI_RAM_DONT_SHARE
19111
        parameter bist_chain_length = 8 ;
19112
    `else
19113
        parameter bist_chain_length = 6 ;
19114
    `endif
19115
`else
19116
    `ifdef PCI_RAM_DONT_SHARE
19117
        bist_chain_length = 6 ;
19118
    `else
19119
        bist_chain_length = 4 ;
19120
    `endif
19121
`endif
19122
 
19123
task run_bist_test ;
19124
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19125
    integer count ;
19126
    integer deadlock_count ;
19127
begin
19128
 
19129
    test_name = "BIST FOR RAMS RUN" ;
19130
 
19131
    SI          = 0 ;
19132
    shift_DR    = 0 ;
19133
    capture_DR  = 0 ;
19134
    extest      = 0 ;
19135
    tck         = 0 ;
19136
 
19137
    fork
19138
    begin
19139
        repeat(2)
19140
            @(posedge wb_clock) ;
19141
    end
19142
    begin
19143
        repeat(2)
19144
            @(posedge pci_clock) ;
19145
    end
19146
    join
19147
 
19148
    // test is run with forcing extest high
19149
    extest <= 1'b1 ;
19150
 
19151
    bist_result_vector = 0 ;
19152
 
19153
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19154
    fork
19155
    begin:scan
19156
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19157
        begin
19158
            @(negedge tck) ;
19159
            capture_DR <= #1 1'b1 ;
19160
            @(negedge tck) ;
19161
            capture_DR <= #1 1'b0 ;
19162
            shift_DR   <= #1 1'b1 ;
19163
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19164
            begin
19165
                @(negedge tck) ;
19166
                bist_result_vector[count] = SO ;
19167
            end
19168
 
19169
            shift_DR <= #1 1'b0 ;
19170
        end
19171
        #1 disable deadlock ;
19172
        @(negedge tck) ;
19173
        extest <= #1 1'b0 ;
19174
        #1 ;
19175
        disable tck_gen ;
19176
        test_ok ;
19177
    end
19178
    begin:deadlock
19179
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19180
        begin
19181
            @(posedge pci_clock) ;
19182
            @(posedge wb_clock) ;
19183
        end
19184
 
19185
        test_fail("BIST Test didn't finish as expected") ;
19186
        extest <= #1 1'b0 ;
19187
        disable scan ;
19188
        @(negedge tck) ;
19189
        #1 ;
19190
        disable tck_gen ;
19191
    end
19192
    begin:tck_gen
19193
        forever
19194
            #50 tck = !tck ;
19195
    end
19196
    join
19197
end
19198
endtask // run_bist_test
19199
`endif
19200
 
19201 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
19202
task target_special_corner_case_test ;
19203
    reg   [11:0]    pci_ctrl_offset ;
19204
    reg   [11:0]    ctrl_offset ;
19205
    reg   [11:0]    ba_offset ;
19206
    reg   [11:0]    am_offset ;
19207
    reg             ok_wb ;
19208
    reg             ok_pci ;
19209
    reg             test_mem ;
19210
    reg             master_check_data_previous ;
19211
begin:main
19212
    master_check_data_previous  = master1_check_received_data ;
19213
    master1_check_received_data = 1'b1 ;
19214
    pci_ctrl_offset = 12'h4 ;
19215
    // use image 1 for this test
19216
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19217
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19218
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19219
 
19220
    // set behavioral slave cycle response
19221
    `ifdef REGISTER_WBM_OUTPUTS
19222
    wishbone_slave.cycle_response
19223
    (
19224
        3'b100,         // {ACK, ERR, RTY}
19225
        0,              // wait cycles
19226
        8'h0            // num of retries before termination
19227
    );
19228
    `else
19229
    wishbone_slave.cycle_response
19230
    (
19231
        3'b100,         // {ACK, ERR, RTY}
19232
        1,              // wait cycles
19233
        8'h0            // num of retries before termination
19234
    );
19235
    `endif
19236
 
19237
    `ifdef HOST
19238
        test_mem = 1 ;
19239
    `else
19240
        test_mem = `PCI_BA1_MEM_IO ;
19241
        test_mem = !test_mem ;
19242
    `endif
19243
 
19244
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19245
 
19246
    // Set Base Address of IMAGE
19247
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19248
    if ( ok_wb !== 1 )
19249
    begin
19250
        $display("Image testing failed! Failed to write P_BA1 register! Time %t ", $time);
19251
        test_fail("PCI Base Address register 1 could not be written") ;
19252
        #1 ;
19253
        disable main ;
19254
    end
19255
 
19256
    // Set Address Mask of IMAGE
19257
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19258
    if ( ok_wb !== 1 )
19259
    begin
19260
        $display("Image testing failed! Failed to write P_AM1 register! Time %t ", $time);
19261
        test_fail("PCI Address Mask register 1 could not be written") ;
19262
        #1 ;
19263
        disable main ;
19264
    end
19265
 
19266
    // Disable all the features of the PCI Image 1
19267
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19268
    if ( ok_wb !== 1 )
19269
    begin
19270
        $display("Image testing failed! Failed to write P_CTRL1 register! Time %t ", $time);
19271
        test_fail("PCI Image Control register 1 could not be written") ;
19272
        #1 ;
19273
        disable main ;
19274
    end
19275
 
19276
    // set waits to max, which means 0 on PCI
19277
    tb_init_waits   = 4 ;
19278
    tb_subseq_waits = 4 ;
19279
 
19280
    // do one dummy write, to receive a GNT park
19281
    if (test_mem)
19282
    begin
19283
        PCIU_MEM_WRITE
19284
        (
19285
            "MEM_WRITE ",                       // just the name
19286
            `Test_Master_1,                     // Behavioral Master to use for reference
19287
            Target_Base_Addr_R[1],              // Address of this transaction
19288
            32'hAAAA_AAAA,                      // Data For the transaction
19289
            4'h0,                               // Byte enables
19290
            1,                                  // length of transfer
19291
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19292
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19293
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19294
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19295
        );
19296
    end
19297
    else
19298
    begin
19299
        PCIU_IO_WRITE
19300
        (
19301
            `Test_Master_1,                     // Behavioral Master to use for reference
19302
            Target_Base_Addr_R[1],              // Address of this transaction
19303
            32'hAAAA_AAAA,                      // Data For the transaction
19304
            4'h0,                               // Byte enables
19305
            1,                                  // Size of transfer
19306
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19307
        ) ;
19308
    end
19309
 
19310
    do_pause( 1 ) ;
19311
    wb_transaction_progress_monitor
19312
    (
19313
        Target_Base_Addr_R[1],          // expected address
19314
        1'b1,                           // expected operation R/W
19315
        1,                              // 1
19316
        1'b1,                           // turn checking of transfers ON/OFF
19317
        ok_wb                           // succeeded/failed
19318
    ) ;
19319
 
19320
    if (ok_wb !== 1'b1)
19321
    begin
19322
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19323
        #1 ;
19324
        disable main ;
19325
    end
19326
 
19327
    fork
19328
    begin
19329
        if (test_mem)
19330
        begin
19331
            PCIU_MEM_WRITE
19332
            (
19333
                "MEM_WRITE ",                       // just the name
19334
                `Test_Master_1,                     // Behavioral Master to use for reference
19335
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19336
                32'hF0F0_F0F0,                      // Data For the transaction
19337
                4'h0,                               // Byte enables       
19338
                1,                                  // length of transfer
19339
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19340
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19341
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19342
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19343
            );
19344
        end
19345
        else
19346
        begin
19347
            PCIU_IO_WRITE
19348
            (
19349
                `Test_Master_1,                     // Behavioral Master to use for reference
19350
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19351
                32'hF0F0_F0F0,                      // Data For the transaction
19352
                4'h0,                               // Byte enables
19353
                1,                                  // Size of transfer
19354
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19355
            ) ;
19356
        end
19357
 
19358
        do_pause( 1 ) ;
19359
 
19360
        if (test_mem)
19361
        begin
19362
            PCIU_MEM_WRITE
19363
            (
19364
                "MEM_WRITE ",                       // just the name
19365
                `Test_Master_1,                     // Behavioral Master to use for reference
19366
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19367
                32'h0F0F_0F0F,                      // Data For the transaction
19368
                4'h0,                               // Byte enables
19369
                1,                                  // length of transfer
19370
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19371
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19372
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19373
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19374
            );
19375
        end
19376
        else
19377
        begin
19378
            PCIU_IO_WRITE
19379
            (
19380
                `Test_Master_1,                     // Behavioral Master to use for reference
19381
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19382
                32'h0F0F_0F0F,                      // Data For the transaction
19383
                4'h0,                               // Byte enables
19384
                1,                                  // Size of transfer
19385
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19386
            ) ;
19387
        end
19388
 
19389
        do_pause( 1 ) ;
19390
    end
19391
    begin
19392
        wb_transaction_progress_monitor
19393
        (
19394
            Target_Base_Addr_R[1] + 64,     // expected address
19395
            1'b1,                           // expected operation R/W
19396
            1,                              // expected number of transfers
19397
            1'b1,                           // turn checking of transfers ON/OFF
19398
            ok_wb                           // succeeded/failed
19399
        ) ;
19400
 
19401
        if ( ok_wb === 1 )
19402
        begin
19403
 
19404
            wb_transaction_progress_monitor
19405
            (
19406
                Target_Base_Addr_R[1] + 128,    // expected address
19407
                1'b1,                           // expected operation R/W
19408
                1,                              // expected number of transfers
19409
                1'b1,                           // turn checking of transfers ON/OFF
19410
                ok_wb                           // succeeded/failed
19411
            ) ;
19412
        end
19413
 
19414
        @(posedge pci_clock) ;
19415
        #1 ;
19416
        disable pci_error_mon1 ;
19417
    end
19418
    begin:pci_error_mon1
19419
        ok_pci = 1 ;
19420
        @(error_event_int) ;
19421
        ok_pci = 0 ;
19422
    end
19423
    join
19424
 
19425
    if ( ok_wb !== 1'b1 )
19426
    begin
19427
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19428
    end
19429
 
19430
    if ( ok_pci !== 1'b1)
19431
    begin
19432
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19433
    end
19434
 
19435
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19436
    begin
19437
        #1 ;
19438
        disable main ;
19439
    end
19440
 
19441
    if ( test_mem )
19442
    begin
19443
        PCIU_MEM_READ
19444
        (
19445
            "MEM_READ  ",                   // description
19446
            `Test_Master_1,                 // behavioral master selection
19447
            Target_Base_Addr_R[1] + 64,     // address of access
19448
            32'hF0F0_F0F0,                  // expected read data
19449
            1,                              // number of transfers
19450
            8'h7_0,                         // don't care (wait cycles)
19451
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19452
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19453
            `Test_Target_Retry_On           // expected Target termination
19454
        );
19455
    end
19456
    else
19457
    begin
19458
        PCIU_IO_READ
19459
        (
19460
            `Test_Master_1,                 // behavioral master selection
19461
            Target_Base_Addr_R[1] + 64,     // address of access
19462
            32'hF0F0_F0F0,                  // expected read data
19463
            4'h0,                           // byte enables
19464
            1,                              // number of transfers
19465
            `Test_Target_Retry_On           // expected target termination
19466
        ) ;
19467
    end
19468
 
19469 64 mihad
    do_pause(1) ;
19470
 
19471 63 mihad
    wb_transaction_progress_monitor
19472
    (
19473
            Target_Base_Addr_R[1] + 64,     // expected address
19474
            1'b0,                           // expected operation R/W
19475
            1,                              // expected number transfers
19476
            1'b1,                           // turn checking of transfers ON/OFF
19477
            ok_wb                           // succeeded/failed
19478
    ) ;
19479
 
19480
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19481
    repeat(3)
19482
        @(posedge pci_clock) ;
19483
 
19484
    // now read data
19485
    fork
19486
    begin
19487
        if ( test_mem )
19488
        begin
19489
            PCIU_MEM_READ
19490
            (
19491
                "MEM_READ  ",                   // description
19492
                `Test_Master_1,                 // behavioral master selection
19493
                Target_Base_Addr_R[1] + 64,     // address of access
19494
                32'hF0F0_F0F0,                  // expected read data
19495
                1,                              // number of transfers
19496
                8'h7_0,                         // don't care (wait cycles)
19497
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19498
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19499
                `Test_Target_Normal_Completion  // expected Target termination
19500
            );
19501
        end
19502
        else
19503
        begin
19504
            PCIU_IO_READ
19505
            (
19506
                `Test_Master_1,                 // behavioral master selection
19507
                Target_Base_Addr_R[1] + 64,     // address of access
19508
                32'hF0F0_F0F0,                  // expected read data
19509
                4'h0,                           // byte enables
19510
                1,                              // number of transfers
19511
                `Test_Target_Normal_Completion  // expected target termination
19512
            ) ;
19513
        end
19514
 
19515 64 mihad
        do_pause(1) ;
19516 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19517
            @(posedge pci_clock) ;
19518
 
19519
        @(posedge pci_clock) ;
19520
        #1 ;
19521
        disable pci_error_mon2 ;
19522
    end
19523
    begin:pci_error_mon2
19524
        ok_pci = 1 ;
19525
        @(error_event_int) ;
19526
        ok_pci = 0 ;
19527
    end
19528
    join
19529
 
19530
    if ( ok_wb !== 1'b1 )
19531
    begin
19532
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19533
    end
19534
 
19535
    if ( ok_pci !== 1'b1)
19536
    begin
19537
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19538
    end
19539
 
19540
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19541
    begin
19542
        #1 ;
19543
        disable main ;
19544
    end
19545
 
19546
    if ( test_mem )
19547
    begin
19548
        PCIU_MEM_READ
19549
        (
19550
            "MEM_READ  ",                   // description
19551
            `Test_Master_1,                 // behavioral master selection
19552
            Target_Base_Addr_R[1] + 128,    // address of access
19553
            32'h0F0F_0F0F,                  // expected read data
19554
            1,                              // number of transfers
19555
            8'h7_0,                         // don't care (wait cycles)
19556
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19557
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19558
            `Test_Target_Retry_On           // expected Target termination
19559
        );
19560
    end
19561
    else
19562
    begin
19563
        PCIU_IO_READ
19564
        (
19565
            `Test_Master_1,                 // behavioral master selection
19566
            Target_Base_Addr_R[1] + 128,    // address of access
19567
            32'h0F0F_0F0F,                  // expected read data
19568
            4'h0,                           // byte enables
19569
            1,                              // number of transfers
19570
            `Test_Target_Retry_On           // expected target termination
19571
        ) ;
19572
    end
19573
 
19574 64 mihad
    do_pause(1) ;
19575 63 mihad
    wb_transaction_progress_monitor
19576
    (
19577
            Target_Base_Addr_R[1] + 128,    // expected address
19578
            1'b0,                           // expected operation R/W
19579
            1,                              // expected number transfers
19580
            1'b1,                           // turn checking of transfers ON/OFF
19581
            ok_wb                           // succeeded/failed
19582
    ) ;
19583
 
19584
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19585
    repeat(3)
19586
        @(posedge pci_clock) ;
19587
 
19588
    // now read data
19589
    fork
19590
    begin
19591
        if ( test_mem )
19592
        begin
19593
            PCIU_MEM_READ
19594
            (
19595
                "MEM_READ  ",                   // description
19596
                `Test_Master_1,                 // behavioral master selection
19597
                Target_Base_Addr_R[1] + 128,    // address of access
19598
                32'h0F0F_0F0F,                  // expected read data
19599
                1,                              // number of transfers
19600
                8'h7_0,                         // don't care (wait cycles)
19601
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19602
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19603
                `Test_Target_Normal_Completion  // expected Target termination
19604
            );
19605
        end
19606
        else
19607
        begin
19608
            PCIU_IO_READ
19609
            (
19610
                `Test_Master_1,                 // behavioral master selection
19611
                Target_Base_Addr_R[1] + 128,    // address of access
19612
                32'h0F0F_0F0F,                  // expected read data
19613
                4'h0,                           // byte enables
19614
                1,                              // number of transfers
19615
                `Test_Target_Normal_Completion  // expected target termination
19616
            ) ;
19617
        end
19618
 
19619 64 mihad
        do_pause(1) ;
19620 63 mihad
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19621
            @(posedge pci_clock) ;
19622
 
19623
        @(posedge pci_clock) ;
19624
        #1 ;
19625
        disable pci_error_mon3 ;
19626
    end
19627
    begin:pci_error_mon3
19628
        ok_pci = 1 ;
19629
        @(error_event_int) ;
19630
        ok_pci = 0 ;
19631
    end
19632
    join
19633
 
19634
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19635
        test_ok ;
19636
 
19637
    if ( ok_wb !== 1'b1 )
19638
    begin
19639
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19640
    end
19641
 
19642
    if ( ok_pci !== 1'b1)
19643
    begin
19644
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19645
    end
19646
 
19647
    master1_check_received_data = master_check_data_previous ;
19648
end
19649
endtask // target_special_corner_case_test
19650
`endif
19651
 
19652 15 mihad
task test_fail ;
19653
    input [7999:0] failure_reason ;
19654
    reg   [8007:0] display_failure ;
19655
    reg   [799:0] display_test ;
19656
begin
19657
    tests_failed = tests_failed + 1 ;
19658
 
19659
    display_failure = {failure_reason, "!"} ;
19660
    while ( display_failure[7999:7992] == 0 )
19661
        display_failure = display_failure << 8 ;
19662
 
19663
    display_test = test_name ;
19664
    while ( display_test[799:792] == 0 )
19665
       display_test = display_test << 8 ;
19666
 
19667 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19668 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
19669
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
19670
    $fdisplay( tb_log_file, " *FAILED* because") ;
19671
    $fdisplay( tb_log_file, " %s", display_failure ) ;
19672 63 mihad
    current_test_parameters ;
19673
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19674 15 mihad
    $fdisplay( tb_log_file, " " ) ;
19675
 
19676
    `ifdef STOP_ON_FAILURE
19677
    #20 $stop ;
19678
    `endif
19679
end
19680
endtask // test_fail
19681
 
19682
task test_ok ;
19683
    reg [799:0] display_test ;
19684
begin
19685
   tests_successfull = tests_successfull + 1 ;
19686
 
19687
   display_test = test_name ;
19688
   while ( display_test[799:792] == 0 )
19689
       display_test = display_test << 8 ;
19690
 
19691 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19692 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
19693
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
19694
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
19695 63 mihad
   current_test_parameters ;
19696
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19697 15 mihad
   $fdisplay( tb_log_file, " " ) ;
19698
end
19699
endtask // test_ok
19700
 
19701
task test_summary;
19702
begin
19703 63 mihad
    $fdisplay(tb_log_file, "\n \n");
19704 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19705
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
19706
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
19707
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
19708
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19709
    $fclose(tb_log_file) ;
19710
end
19711
endtask
19712
 
19713 63 mihad
task current_test_parameters ;
19714
    reg [87:0] decode_speed_text ;
19715
begin
19716
    case (tb_target_decode_speed)
19717
        3'b000: decode_speed_text = "FAST       " ;
19718
        3'b001: decode_speed_text = "MEDIUM     " ;
19719
        3'b010: decode_speed_text = "SLOW       " ;
19720
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
19721
    endcase
19722
 
19723
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
19724
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (3'd4 - tb_init_waits)) ;
19725
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (3'd4 - tb_subseq_waits)) ;
19726
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
19727
 
19728
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", tb_init_waits) ;
19729
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", tb_subseq_waits) ;
19730
end
19731
endtask
19732
 
19733 15 mihad
endmodule

powered by: WebSVN 2.1.0

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